leaflet esri 添加label

var labels = {};

earthquakes.on('createfeature', function (e) {
var id = e.feature.id;
var feature = earthquakes.getFeature(id);
var center = feature.getLatLng();
var label = L.marker(center, {
icon: L.divIcon({
iconSize: null,
className: 'label',
html: '<div>' + e.feature.properties.name + '</div>'
})
}).addTo(map);
labels[id] = label;
});

earthquakes.on('addfeature', function (e) {
var label = labels[e.feature.id];
if (label) {
label.addTo(map);
}
});

earthquakes.on('removefeature', function (e) {
var label = labels[e.feature.id];
if (label) {
map.removeLayer(label);
}
});

posted @ 2020-07-13 08:37  googlegis  阅读(562)  评论(0编辑  收藏  举报

坐标合肥,非典型GIS开发人员 GitHub