import L from 'leaflet';
import 'leaflet-draw'
/*** Case study
* async ceju(){
* let that = this
* const p1 = await new Promise(function(resolve,reject){
* let a = new Draw(that.baseMap,that.measureGroup,resolve,reject)
* a.rectangle()
* });
* console.log(p1);
*
* },
***/
//new Need to pass in map And layergroup
// The return value needs to be asynchronously accepted , So we used promise
class Draw{
constructor(map,measureGroup,resolve,reject){
this.map = map
this.drawDataMap = []
this.stopRectArea = null
this.locations = {}
this.resolve = resolve
this.reject = reject
this.measureGroup = measureGroup
this.geometry = []
}
rectangle(){
let that = this
console.log(' Start to box ');
that.map.off("click")
that.map.off("dblclick")
that.map.off("dblclick")
if(that.stopRectArea != null){ //stopRectArea stay data In the definition of , Clear the repeated frame pulling operation
that.map.off('mousedown', that.stopRectArea.mousedown);
}
var rectangleMeasure = {
startPoint: null,
endPoint: null,
rectangle:null,
layer: that.measureGroup,
color: "rgba(51,136,255,1)",
addRectangle:function(){
rectangleMeasure.destory();
var bounds = [];
bounds.push(rectangleMeasure.startPoint);
bounds.push(rectangleMeasure.endPoint);
rectangleMeasure.rectangle = L.rectangle(bounds, {color: rectangleMeasure.color, weight: 1});
rectangleMeasure.rectangle.addTo(rectangleMeasure.layer);
rectangleMeasure.layer.addTo(that.map);
},
mousedown: function(e){
rectangleMeasure.rectangle = null;
that.map.dragging.disable();
rectangleMeasure.startPoint = e.latlng;
that.map.on('mousemove',rectangleMeasure.mousemove)
},
mousemove:function(e){
rectangleMeasure.endPoint = e.latlng;
rectangleMeasure.addRectangle();
that.map.off('mousedown ', rectangleMeasure.mousedown).on('mouseup', rectangleMeasure.mouseup);
},
mouseup: function(){
that.map.dragging.enable();
that.map.off('mousemove',rectangleMeasure.mousemove).off('mouseup', rectangleMeasure.mouseup);
that.locations = {}; //locations stay data In the definition of
that.locations['leftX'] = rectangleMeasure.startPoint.lat;
that.locations['leftY'] = rectangleMeasure.startPoint.lng;
that.locations['rightX'] = rectangleMeasure.endPoint.lat;
that.locations['rightY'] = rectangleMeasure.endPoint.lng;
that.locations['layer_id'] = rectangleMeasure.layer._leaflet_id;
that.locations['layer'] = rectangleMeasure.layer;
that.locations['rectangle'] = rectangleMeasure.rectangle;
that.drawDataMap.push([rectangleMeasure.startPoint.lat,rectangleMeasure.startPoint.lng])
that.drawDataMap.push([rectangleMeasure.endPoint.lat,rectangleMeasure.startPoint.lng])
that.drawDataMap.push([rectangleMeasure.endPoint.lat,rectangleMeasure.endPoint.lng])
that.drawDataMap.push([rectangleMeasure.startPoint.lat,rectangleMeasure.endPoint.lng])
that.resolve(that.drawDataMap)
},
destory:function(){
if(rectangleMeasure.rectangle)
rectangleMeasure.layer.removeLayer(rectangleMeasure.rectangle);
}
};
that.stopRectArea = rectangleMeasure; // Record that the pull box button has been clicked , No box on the map
that.map.on('mousedown', rectangleMeasure.mousedown); // Pull box on map
}
polygon(){
let that = this
that.measureGroup.clearLayers()
var points,lines,tempLines,node;
that.map.off("mousemove")
that.map.off("mousedown")
that.map.off("mouseup")
function drawPolygon(){
that.map.doubleClickZoom.disable();
lines = new L.polyline([]);
tempLines = new L.polyline([],{ dashArray: 5 });
points = [];
that.geometry = [];
that.map.on('click', onClick); // Click on the map
that.map.on('dblclick', onDoubleClick);
that.map.on('mousemove', onMove)// Double click on the map
function onClick(e) {
points.push([e.latlng.lat, e.latlng.lng])
lines.addLatLng(e.latlng)
that.measureGroup.addLayer(tempLines)
that.measureGroup.addLayer(lines)
node=L.circle(e.latlng, { color: '#ff0000', fillColor: 'ff0000', fillOpacity: 1 })
that.measureGroup.addLayer(node)
that.geometry.push(node)
}
function onMove(e) {
if (points.length > 0) {
let ls = [points[points.length - 1], [e.latlng.lat, e.latlng.lng], points[0]]
tempLines.setLatLngs(ls)
// that.map.addLayer(tempLines)
}
}
function onDoubleClick() {
that.geometry.push(L.polygon(points).addTo(that.map))
that.drawDataMap = points
that.drawDataMap.splice(that.drawDataMap.length-1,1)
points = [];
node=null;
that.map.off('click', onClick); // Click on the map
that.map.off('dblclick', onDoubleClick);
that.map.off('mousemove', onMove)// Double click on the map
that.map.doubleClickZoom.enable();
that.resolve(that.drawDataMap)
}
}
that.removePolygon()
drawPolygon()
}
removePolygon(){
for(let ooo of this.geometry){
ooo.remove();
}
}
}
export default Draw当前位置:网站首页>Class class of box selection four to and polygon box selection based on leaflet encapsulation
Class class of box selection four to and polygon box selection based on leaflet encapsulation
2022-06-26 07:27:00 【Friend a】
边栏推荐
- C implementation adds a progress bar display effect to the specified column of the GridView table in devaxpress - code implementation method
- 5,10,15,20-tetraphenylporphyrin (TPP) and metal complexes fetpp/mntpp/cutpp/zntpp/nitpp/cotpp/pttpp/pdtpp/cdtpp supplied by Qiyue
- How to publish function computing (FC) through cloud effect
- Dark red crystal meso-5,10,15,20-tetra (p-aminophenyl) cobalt porphyrin (co TAPP); Meso-5,10,15,20-tetra (p-aminophenyl) cobalt porphyrin no complex (TAPP co no) supplied by Qiyue
- Es string type (text vs keyword) selection
- systemctl php配置文件
- Jemter stress test - Basic request - [teaching]
- Crosslinked porphyrin based polyimide ppbpi-2, ppbpi-1-cr and ppbpi-2-cr; Porous porphyrin based hyperbranched polyimide (ppbpi-1, ppbpi-2) supplied by Qiyue
- MySQL storage and custom functions
- Jemter stress test - visualization tool - [usage]
猜你喜欢

3D porphyrin MOF (mof-p5) / 3D porphyrin MOF (mof-p4) / 2D cobalt porphyrin MOF (ppf-1-co) / 2D porphyrin COF (POR COF) / supplied by Qiyue

Niuniu looks at the cloud (greedy, hash, push formula) - the first session of Niuke winter vacation training camp

Solution to the permission problem when NPM install -g serve reports an error

Excel中Unicode如何转换为汉字

Young man, do you know the original appearance of kotlin association process?

Jmeter压力测试-Web代理本地接口测试【教学篇】

报错问题Parameter index out of range(0 < 1) (1 > number of parameters,which is 0

一文深入底层分析Redis对象结构

缓存使用

How to publish function computing (FC) through cloud effect
随机推荐
Qt基础教程:QString
Jemter stress test - Basic request - [teaching]
Cache usage
一文分析EventBus-事件总线的使用方法和实现原理
Ppbpi-h-cr, ppbpimn Cr, ppbpi Fe Cr alkynyl crosslinked porphyrin based polyimide material Qiyue porphyrin reagent
Crosslinked porphyrin based polyimide ppbpi-2, ppbpi-1-cr and ppbpi-2-cr; Porous porphyrin based hyperbranched polyimide (ppbpi-1, ppbpi-2) supplied by Qiyue
Young man, do you know the original appearance of kotlin association process?
两水先木示身为Unity3D职场人的个人觉悟
MySQL
Sanic based services use celery to complete dynamic modification timing tasks
Redis (4) -- Talking about integer set
SQL query statement
蓝桥杯嵌入式学习总结(新版)
Jemter 压力测试 -可视化工具-【使用篇】
Jmeter压力测试-Web代理本地接口测试【教学篇】
Which of the top ten securities companies has the lowest commission fee and is the most safe and reliable?
SQL
Blue Bridge Cup embedded learning summary (new version)
【推荐一款实体类转换工具 MapStruct,性能强劲,简单易上手 】
php array_ Merge details