移除除底图以外所有图层
for(var i in map._layers) {
if(map._layers[i]._path != undefined) {
try {
map.removeLayer(map._layers[i]);
}
catch(e) {
console.log("problem with " + e + map._layers[i]);
}
}
}
点
var blueIcon = L.icon({
iconUrl: "图标地址",
iconSize: [30, 30],
iconAnchor: [20, 10]
});
this.htmlmaker = [];
this.axios.get("./static/json/point.json").then(
response => {
var latlng = response.data.features;
for (let i = 0; i < latlng.length; i++) {
var newArr = this.pointType;
if (newArr.indexOf(latlng[i].properties.FolderPath) != -1) {
var lat = latlng[i].geometry.coordinates[1];
var lng = latlng[i].geometry.coordinates[0];
var tempmarker=[lat,lng];
var marker = L.marker([lat, lng], {
icon: blueIcon,
minzoom: 8,
maxZoom: 10,
riseOnHover: true
});
var html = "";
html += '<div class="l-popup">';
html += "</div>";
marker.bindPopup(html);
this.htmlmaker.push(marker);
marker.on("click", () => {
this.tempPoint = latlng[i];
});
this.markerGroup = L.layerGroup(this.htmlmaker);
this.markerGroup.addTo(map);
map.flyTo(tempmarker,12,{duration: 1});
}
}
this.markerGroup.clearLayers();
线
var polyLines = [];
var latlngs = fea[i].geometry.coordinates;
for (var j = 0; j < latlngs.length; j++) {
var lng = latlngs[j][0];
var lat = latlngs[j][1];
var latLng = [lat, lng];
polyLines.push(latLng);
}
var polyline = L.polyline (polyLines, {
color: "red",
});
polyline.on("dblclick",e=>{
console.log(1)
})
polyline.bindPopup(fea[i].properties.Name);
this.polyLines.push(polyline);
this.polygonsGroup = L.layerGroup(this.polyLines);
this.polygonsGroup.addTo(map);
map.fitBounds(polyline.getBounds());
map.removeLayer(this.polygonsGroup);
转载请注明原文地址:https://ipadbbs.8miu.com/read-51019.html