資源描述:
《Openlayers在Google地圖下測(cè)距測(cè)面積》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在行業(yè)資料-天天文庫。
1、在地圖的panel內(nèi)添加控件:vlayer=newOpenLayers.Layer.Vector("控件層");map.addLayer(vlayer);//定義面板varpanel=newOpenLayers.Control.Panel();panel.addControls([newOpenLayers.Control.DrawFeature(vlayer,OpenLayers.Handler.Path,{title:'測(cè)距',featureAdded:LengthFeatureAdd}),newOpenLayers.Contr
2、ol.DrawFeature(vlayer,OpenLayers.Handler.Polygon,{title:'測(cè)面積',featureAdded:AreaFeatureAdd})]);//添加控制面板map.addControl(panel);添加js代碼文件:Ranging.js,記得添加引用。//關(guān)閉Pupup的彈出對(duì)話框functiononPopupClose(evt){vlayer.removeFeatures(vlayer.features);map.removePopup(selectedFeature.popup)
3、;selectedFeature.popup.destroy();selectedFeature.popup=null;}//測(cè)距varEARTH_RADIUS=6378137;functionrad(d){returnd*Math.PI/180.0;}functionGetDistance(lat1,lon1,lat2,lon2){varradLat1=rad(lat1);varradLat2=rad(lat2);vara=radLat1-radLat2;varb=rad(lon1)-rad(lon2);vars=2*Math.a
4、sin(Math.sqrt(Math.pow(Math.sin(a/2),2)+Math.cos(radLat1)*Math.cos(radLat2)*Math.pow(Math.sin(b/2),2)));s=s*EARTH_RADIUS;s=Math.round(s*10000)/10000;returns;}functionLengthFeatureAdd(feature){vardistance=0;varsource=newProj4js.Proj('EPSG:900913');vardest=newProj4js.Pro
5、j('WGS84');for(vari=1;i6、y.components[i].y);Proj4js.transform(source,dest,p2);distance=distance+GetDistance(p1.y,p1.x,p2.y,p2.x);}popup=newOpenLayers.Popup.FramedCloud("chicken",feature.geometry.getBounds().getCenterLonLat(),null,"所測(cè)距離為:"+distance.toFixed(1)+"米"+"7、iv>",null,true,onPopupClose);popup.autoSize=true;feature.popup=popup;selectedFeature=feature;map.addPopup(popup);}functionAreaFeatureAdd(feature){varpointX=newArray();varpointY=newArray();varsource=newProj4js.Proj('EPSG:900913');vardest=newProj4js.Proj('WGS84');for(var
8、i=0;i