leaflet保存pm绘图geojson数据
//生成geojson数据
function CreateGeoJson() {
var layerArray = new Array();
map.eachLayer(function (layer) {
if (layer.pm != 'undefined' && layer.pm != null && layer.pm != '') {
if (layer.pm._enabled == false && layer.pm.options.draggable == true) {
layerArray.push(layer);
}
}
})
var geojson = L.layerGroup(layerArray).toGeoJSON();
for (var n = 0; n < geojson.features.length; n++) {
var nowJson = JSON.stringify(geojson.features[n]);
for (var m = n + 1; m < geojson.features.length; m++) {
var nextJson = JSON.stringify(geojson.features[m]);
if (nowJson == nextJson) {
geojson.features.splice(n, 1);
}
}
}
return geojson;
}
//重新加载geojson数据
L.geoJson(geojson).addTo(map);
转载自:https://blog.csdn.net/STRIVEYe/article/details/88306935