|
@@ -725,18 +725,46 @@
|
|
|
_that.connectLayer = window.L.featureGroup().addTo(this.map);
|
|
|
_that.connectLayer.addLayer(polyline);
|
|
|
},
|
|
|
- setGraphicsList: function (graphicsList, color) {//地图图形
|
|
|
+ // setGraphicsList: function (graphicsList, color) {//地图图形
|
|
|
+ // const _that = this;
|
|
|
+ // let points = [];
|
|
|
+ // for (let i = 0; i < graphicsList.length; i++) {
|
|
|
+ // points.push([graphicsList[i].lat, graphicsList[i].lng]);//创建点
|
|
|
+ // }
|
|
|
+ // let polygon = window.L.polygon(points, {color: color});
|
|
|
+ // polygon.addTo(this.map);
|
|
|
+ // _that.graphicsLayer = window.L.featureGroup().addTo(this.map);
|
|
|
+ // _that.graphicsLayer.addLayer(polygon);
|
|
|
+ // },
|
|
|
+ setGraphicsList: function (graphicsList, color,name) {//地图图形
|
|
|
const _that = this;
|
|
|
let points = [];
|
|
|
+ let polygons = new Map(); // 使用 Map 记录 Polygon 和对应的 Popup
|
|
|
for (let i = 0; i < graphicsList.length; i++) {
|
|
|
points.push([graphicsList[i].lat, graphicsList[i].lng]);//创建点
|
|
|
}
|
|
|
- let polygon = window.L.polygon(points, {color: color});
|
|
|
- polygon.addTo(this.map);
|
|
|
- _that.graphicsLayer = window.L.featureGroup().addTo(this.map);
|
|
|
- _that.graphicsLayer.addLayer(polygon);
|
|
|
- },
|
|
|
+ if (name){
|
|
|
+ let polygon = window.L.polygon(points, {color: color}); // 创建 Polygon
|
|
|
+ let center = polygon.getBounds().getCenter();
|
|
|
+ let namePopup = window.L.popup().setLatLng([center.lat, center.lng])
|
|
|
+ .setContent(name); // 创建对应的 Popup
|
|
|
+ namePopup.addTo(this.map);
|
|
|
+ polygon.bindPopup(namePopup); // 将 Popup 绑定到 Polygon
|
|
|
+ polygon.addTo(this.map);
|
|
|
+ _that.graphicsLayer = window.L.featureGroup().addTo(this.map);
|
|
|
+ _that.graphicsLayer.addLayer(polygon);
|
|
|
+
|
|
|
+ polygons.set(polygon, namePopup); // 将 Polygon 和 Popup 记录在 Map 中
|
|
|
+ // 在需要移除时,可以通过 polygons.get(polygon).remove() 移除对应的 Popup
|
|
|
+ }else {
|
|
|
+ let polygon = window.L.polygon(points, {color: color});
|
|
|
+ polygon.addTo(this.map);
|
|
|
+ _that.graphicsLayer = window.L.featureGroup().addTo(this.map);
|
|
|
+ _that.graphicsLayer.addLayer(polygon);
|
|
|
+ }
|
|
|
|
|
|
+
|
|
|
+ },
|
|
|
dropLocation: function (lat, lng) {//落点定位
|
|
|
this.controlLevel(10)
|
|
|
setTimeout(() => {
|