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】
边栏推荐
- Zraqnhydae
- Thymeleaf中使用二维数组[[]]报错:Could not parse as expression
- How can I find the completely deleted photos in Apple mobile phone?
- Jemter stress test - visualization tool - [usage]
- [yolov4] matlab simulation of network target detection based on yolov4 deep learning
- Oracle creates stored procedures with return values and executes SQL calls
- systemctl php配置文件
- Jemter stress test - visualization tool support - [installation]
- Is it safe for individuals to buy stocks with compass software? How to buy stocks
- QPS
猜你喜欢

Median segmentation (find rules) - Niuke

执行npm install -g serve时报错权限权限问题解决方案

ZRaQnHYDAe

Important reference indicators for data center disaster recovery: RTO and RPO

【推荐一款实体类转换工具 MapStruct,性能强劲,简单易上手 】

Zraqnhydae

Teach you how to use the harmonyos local simulator

ZRaQnHYDAe
![[recommend 10 easy idea plug-ins with less tedious and repetitive code]](/img/74/69ca02e3d83404f7b0df07c308a59d.png)
[recommend 10 easy idea plug-ins with less tedious and repetitive code]

Redis(4)----浅谈整数集合
随机推荐
Alkynyl crosslinked porphyrin based polyimide materials (ppbpi-h-cr, ppbpi Mn cr.ppbpi Fe Cr); Metalloporphyrin based polyimide (ppbpi Mn, ppbpi FE) supplied by Qiyue
MySQL storage and custom functions
Stm32f1 and stm32subeide programming example - thermal sensor driver
Here comes the apple ar/vr device exclusive system! Or named realityos
Porphyrin based polyimide ppbpis (ppbpi-pa, ppbpi-pepa and ppbpi-pena); Crosslinked porphyrin based polyimide (ppbpi-pa-cr, ppbpi-pepa-cr, ppbpi-pena-cr) reagent
Service interface test guide
Zraqnhydae
The performance of iron and steel enterprises was expected to be good in January this year. Since February, the prices of products of iron and steel enterprises have increased significantly. A mighty
The difference between insert ignore and insert into
item2安装配置及环境失效问题解决
十大证券公司哪个佣金手续费最低,最安全可靠?
Thymeleaf中使用二维数组[[]]报错:Could not parse as expression
卡尔曼滤波器_Recursive Processing
[image fusion] MRI-CT image fusion based on gradient energy, local energy and PCA fusion rules with matlab code
Liquid crystal texture diagram of purple solid mm-tpp-10c methacrylic acid decanoxy tetraphenyl porphyrin and mm-tpp-12c methacrylic acid dodecanoxy tetraphenyl porphyrin - Qi Yue display
QTreeWidget And QTableWidget
Solution to the problem of multi application routing using thinkphp6.0
MySQL
ES cluster_ block_ exception read_ only_ allow_ Delete question
面试被问Redis主从复制不会答?这13张图让你彻底弄明白