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);
}
});