<分区>
重置/刷新切换的最佳方式是什么?我正在使用 CSS 样式的选择器控制一些 map 图层。 Toggle All Off 按钮取消选择所有 map 图层,但切换仍显示为“事件”。 Here is the example (jfiddle 不喜欢 mapbox map )。
//Create toggles to turn map layers on and off
var item = document.createElement('li');
var link = document.createElement('a');
link.href = '#';
link.className == 'active';
link.innerHTML = name;
link.onclick = function (e) {
e.preventDefault();
e.stopPropagation();
//turn off map layers when Toggle All Off button is clicked
if ($(this).text() == 'Toggle All Off') {
map.eachLayer(function (layer) {
map.removeLayer(layer);
});
map.addLayer(baseLayer);
} else if (map.hasLayer(layer))