剛剛發現 Leafletjs 并喜歡它。當我的 json 為空或無效時,我一直試圖洗掉我所有的制造商,但我無法正確處理。每次我的 json 更新時,我都嘗試了閃爍/閃爍的所有不同方法,這是我設法獲得的最接近的方法。
任何幫助都會很棒。我對制造商移動和更新而不眨眼的例子太少了……我真的不想使用谷歌地圖!
我試圖重置制造商 = {}; 但這沒有任何作用。謝謝
data.BMS.forEach(function (obj) {
if (obj.lat !== undefined && obj.lng !== undefined) {
if (!markers.hasOwnProperty(obj.id)) {
markers[obj.id] = new L.Marker([obj.lat, obj.lng], {icon: panicNormal}).addTo(map) .bindTooltip(obj.name,
{
permanent: true,
direction: 'top',
offset: [0, 0]
});
markers[obj.id].previousLatLngs = [];
areaBounds.push([obj.lat, obj.lng]);
} else {
areaBounds.push([obj.lat, obj.lng]);
markers[obj.id].previousLatLngs.push(markers[obj.id].getLatLng());
if(obj.status == "TRUE"){
markers[obj.id].setIcon(panicAlarm);
}else{
if(obj.type == "MO"){
markers[obj.id].setIcon(panicNormal);
}else{
markers[obj.id].setIcon(lora);
}
}
markers[obj.id].setLatLng([obj.lat, obj.lng]);
}
}else{
//How do I remove the markers
}
});
uj5u.com熱心網友回復:
您可以使用L.FeatureGroup()將所有標記添加到它,然后洗掉所有標記.clearLayers()
var fg = L.featureGroup().addTo(map);
...
markers[obj.id] = new L.Marker([obj.lat, obj.lng], {icon: panicNormal}).addTo(fg) .bindTooltip
...
}else{
//How do I remove the markers
fg.clearLayers();
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/347683.html
標籤:javascript 传单 地图
