我想addLayer
(標誌,圓形和彈出)地圖。傳單地圖:如何刪除圖層並向地圖添加彈出窗口?
我能夠添加標記,圈成功,但我不能添加彈出式窗口,我也不能removeLayer這導致標記和圓圈...
乘以它基本上不會刪除以前的標記, ,加入新的人之前圈子
這是一個工作FIDDLE:
https://jsfiddle.net/31ws6z37/3/
這是我的全部代碼:
function initializeMapAndLocator(){
var map = L.map('map_2385853');
googleStreets = L.tileLayer('http://{s}.google.com/vt/lyrs=m&x={x}&y={y}&z={z}',{
maxZoom: 20,
subdomains:['mt0','mt1','mt2','mt3']
}).addTo(map);
map.locate({setView: true,
maxZoom: 16,
watch:true,
timeout: 60000
});
function onLocationFound(e) {
var radius = e.accuracy/2;
var marker = new L.Marker(e.latlng, {draggable:true});
var circles = new L.circle(e.latlng, radius).bindPopup("You are within " + radius + " meters from this point").openPopup();;
map.removeLayer(marker);
map.removeLayer(circles);
map.addLayer(marker);
map.addLayer(circles);
}
map.on('locationfound', onLocationFound);
}
initializeMapAndLocator();
可能有人請讓我知道如何removeLayer以及如何彈出添加到我的地圖?
任何幫助,將不勝感激。
編輯:
似乎沒有什麼是工作,我拔頭髮。我轉過身去的每一個角落,每一次搜索都表明我需要使用removeLayer去除標記,但這並不適合我,我也不明白!
這是我的代碼另一個版本,仍然移除舊之前添加標記....
var map = L.map('map_2385853');
googleStreets = L.tileLayer('http://{s}.google.com/vt/lyrs=m&x={x}&y={y}&z={z}',{
maxZoom: 20,
subdomains:['mt0','mt1','mt2','mt3']
}).addTo(map);
map.locate({setView: true,
maxZoom: 16,
watch:true,
timeout: 60000
});
function onLocationFound(e) {
var radius = e.accuracy/2;
var marker;
var circles;
marker = new L.Marker(e.latlng, {draggable:true});
circles = new L.circle(e.latlng, radius);
//var pop = new bindPopup("You are within " + radius + " meters from this point").openPopup();
map.eachLayer(function (layer) {
map.removeLayer(marker);
map.removeLayer(circles);
});
map.addLayer(marker);
map.addLayer(circles);
}
map.on('locationfound', onLocationFound);
我敢肯定,我做錯了什麼,但我只是不知道在哪裏以及怎麼樣!
任何幫助將是偉大的。
奧凱我會看看怎麼回事錯誤 – Manuel
這是你想要的嗎? – Manuel
@Manuel,你是我的英雄伴侶。相信與否,我正在閱讀文檔並接近您的解決方案,但我沒有使用haslayer。再次感謝。 – Jackson