欢迎来到天天文库
浏览记录
ID:37459621
大小:19.24 KB
页数:7页
时间:2019-05-24
《Openlayers在Google地图下测距测面积》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、在地图的panel内添加控件:vlayer=newOpenLayers.Layer.Vector("控件层");map.addLayer(vlayer);//定义面板varpanel=newOpenLayers.Control.Panel();panel.addControls([newOpenLayers.Control.DrawFeature(vlayer,OpenLayers.Handler.Path,{title:'测距',featureAdded:LengthFeatureAdd}),newOpenLayers.Contr
2、ol.DrawFeature(vlayer,OpenLayers.Handler.Polygon,{title:'测面积',featureAdded:AreaFeatureAdd})]);//添加控制面板map.addControl(panel);添加js代码文件:Ranging.js,记得添加引用。//关闭Pupup的弹出对话框functiononPopupClose(evt){vlayer.removeFeatures(vlayer.features);map.removePopup(selectedFeature.popup)
3、;selectedFeature.popup.destroy();selectedFeature.popup=null;}//测距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,"所测距离为:"+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(var8、i=0;i
6、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,"所测距离为:"+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(var8、i=0;i
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
此文档下载收益归作者所有