当前位置: 首页 > Web前端 > vue.js

基于单张包测距,面测类

时间:2023-03-31 17:11:17 vue.js

importLfrom'leaflet';import'leaflet-draw'classDrawPlug{constructor(map,measureGroup){//距离测量端this.DRAWING=false;//是否在绘制this.DRAWLAYERS=[];this.BarDRAWLAYERS=[];this.ISMEASURE=true;//是否是测量距离this.MEASURETOOLTIP;//测距提示this.MEASUREAREATOOLTIP;//测量面提示this.MEASURERESULT=0;//测量结果this.DRAWPOLYLINE;//绘制多段线this.DRAWMOVEPOLYLINE;//绘制过程中的折线this.DRAWPOLYLINEPOINTS=[];//绘制折线的节点集this.DRAWPOLYGON;//绘制的表面this.DRAWMOVEPOLYGON;//表面绘制过程中this.DRAWMOVEPOLYGONDRAWPOLYGONPOINTS=[];//绘制人脸的节点集this.map=map;this.measureGroup=measureGroup;}startDrawLine(){letthat=thisthat.MEASURERESULT=0;//测量结果that.map.getContainer().style.cursor='crosshair';varshapeOptions={颜色:'#3388ff',权重:3,不透明度:0.8,填充:false,clickable:true}that.DRAWPOLYLINE=newL.Polyline([],shapeOptions);//绘制的折线that.measureGroup.addLayer(that.DRAWPOLYLINE);if(that.ISMEASURE){//是否是测量距离that.MEASURETOOLTIP=newL.Tooltip(that.map);//测量提示}that.map.on('mousedown',onClick);that.map.on('dblclick',onDoubleClick);函数onClick(e){console.log('onClick');那.绘图=真;//是否是.DRAWPOLYLINEPOINTS.push(e.latlng);//绘制折线的节点集if(that.DRAWPOLYLINEPOINTS.length>1&&that.ISMEASURE){//是否是测量距离that.MEASURERESULT+=e.latlng.distanceTo(that.DRAWPOLYLINEPOINTS[that.DRAWPOLYLINEPOINTS.长度-2]);}that.DRAWPOLYLINE.addLatLng(e.latlng);//绘制折线that.map.on('mousemove',onMove);}functiononMove(e){if(that.DRAWING){//正在绘制if(that.DRAWMOVEPOLYLINE!=undefined&&that.DRAWMOVEPOLYLINE!=null){//绘制过程中的折线that.measureGroup.removeLayer(that.DRAWMOVEPOLYLINE);}varprevPoint=that.DRAWPOLYLINEPOINTS[that.DRAWPOLYLINEPOINTS.length-1];that.DRAWMOVEPOLYLINE=newL.Polyline([prevPoint,e.latlng],shapeOptions);that.measureGroup.addLayer(that.DRAWMOVEPOLYLINE);如果(that.ISMEASURE){vardistance=that.MEASURERESULT+e.latlng.distanceTo(that.DRAWPOLYLINEPOINTS[that.DRAWPOLYLINEPOINTS.length-1]);控制台日志(距离);}}}functiononDoubleClick(e){that.map.getContainer().style.cursor='';/*显示两点距离*/vardistance=that.MEASURERESULT+e.latlng.distanceTo(that.DRAWPOLYLINEPOINTS[that.DRAWPOLYLINEPOINTS.length-1]);varmyIcon=L.divIcon({//html:(distance/1000).toFixed(2)+"公里",className:'my-div-icon',html:"

"+"

"+(distance/1000).toFixed(2)+"KM

"+"
",iconSize:26});for(leti=0;i"+"

"+(distance_cust/1000).toFixed(2)+"KM

"+"
",iconSize:26});让site_c=L.polyline([that.DRAWPOLYLINEPOINTS[i],that.DRAWPOLYLINEPOINTS[i+1]],{color:'rgba(0,0,0,0)',}).addTo(that.measureGroup);letas=site_c.getCenter()letc=newL.Marker(as,{draggable:false,icon:myIcon_cust});that.measureGroup.addLayer(c)}letmarker=newL.Marker(e.latlng,{draggable:false,icon:myIcon});that.measureGroup.addLayer(marker)if(that.DRAWING){if(that.DRAWMOVEPOLYLINE!=undefined&&that.DRAWMOVEPOLYLINE!=null){that.map.removeLayer(that.DRAWMOVEPOLYLINE);那.DRAWMOVEPOLYLINE=null;}that.BarDRAWLAYERS.push(that.DRAWPOLYLINE);那.DRAWPOLYLINEPOINTS=[];那.DRAWING=false;那.ISMEASURE=假;that.map.off('mousedown');that.map.off('mousemove');that.map.off('dblclick');}}}清除图层(){letthat=thisthat.measureGroup.clearLayers()}startDrawPolygon(){letthat=thisthat.MEASURERESULT=0;that.map.getContainer().style.cursor='crosshair';that.map.on('mousedown',function(e){that.DRAWING=true;that.DRAWPOLYGONPOINTS.push(e.latlng);that.DRAWPOLYGON.addLatLng(e.latlng);});that.map.on('mousemove',function(e){if(that.DRAWING){if(that.DRAWMOVEPOLYGON!=undefined&&that.DRAWMOVEPOLYGON!=null){that.map.removeLayer(that.DRAWMOVEPOLYGON);}varprevPoint=that.DRAWPOLYGONPOINTS[that.DRAWPOLYGONPOINTS.length-1];varfirstPoint=that.DRAWPOLYGONPOINTS[0];that.DRAWMOVEPOLYGON=newL.Polygon([firstPoint,prevPoint,e.latlng],shapeOptions);那.measureGroup.addLayer(那.DRAWMOVEPOLYG在);}});that.map.on('dblclick',function(e){that.map.getContainer().style.cursor='';vartempPoints=[];for(vari=0;i"+"

"+(distance_cust/1000).toFixed(2)+"公里

"+"
",iconSize:26});letsite_c=L.polyline([as[i],as[i+1]],{color:'rgba(0,0,0,0)',}).addTo(that.measureGroup);letas_ccc=site_c.getCenter()letc=newL.Marker(as_ccc,{draggable:false,icon:myIcon_cust});that.measureGroup.addLayer(c)}console.log(as);tempPoints.push(e.latlng);让CC=that.DRAWPOLYGON.getCenter()vardistance=CalArea(tempPoints);varmyIcon=L.divIcon({html:"
"+"

"+(距离/1000000).toFixed(3)+"KM2

"+"
",类名:'我的分区图标',iconSize:26});让marker=newL.Marker(CC,{draggable:false,icon:myIcon});that.measureGroup.addLayer(标记);//marker.bindPopup("总面积:"+(distance/1000000).toFixed(3)+'平面公共').openPopup();如果(that.DRAWING){如果(that.DRAWMOVEPOLYGON!=undefined&&that.DRAWMOVEPOLYGON!=null){that.map.removeLayer(that.DRAWMOVEPOLYGON);那.DRAWMOVEPOLYGON=null;}that.BarDRAWLAYERS.push(that.DRAWPOLYGON);那.DRAWPOLYGONPOINTS=[];那.DRAWING=false;那.ISMEASURE=假;that.map.off('mousedown');that.map.off('mousemove');that.map.off('dblclick');}});varshapeOptions={color:'#3388ff',weight:3,opacity:0.8,fill:true,fillColor:null,fillOpacity:0.2,clickable:true}that.DRAWPOLYGON=newL.Polygon([],shapeOptions);that.measureGroup.addLayer(that.DRAWPOLYGON);如果(that.ISMEASURE){that.MEASUREAREATOOLTIP=newL.Tooltip(that.map);}functionCalArea(latLngs){varpointsCount=latLngs.length,area=0.0,d2r=Math.PI/180,p1,p2;if(pointsCount>2){for(vari=0;i
最新推荐
猜你喜欢