我有一个mapbox和tilemill层问题:
在这里查看我的代码:http://bl.ocks.org/marishaf/3cc9bfbeb412c1120e93
层按钮看起来总是处于“活动”模式,尽管它们仍然加载和卸载层。
每个层的图例加载(公用土地和分区层都有图例),但是如果加载这两个层,然后尝试移除这两个层,则第一个加载层的图例将保持不变。
这个传说在工具提示中也依然存在。例如,如果首先加载图例层(仅在按此顺序加载图层时发生),然后加载带有工具提示(例如点源污染)的图层,然后在点上鼠标,从而调用工具提示,然后尝试用图例删除图层,则图例将持续。
发布于 2014-04-09 16:52:01
片段:
link.href = '#';
// remove line that was here
link.innerHTML = name;
link.onclick = function(e) {
e.preventDefault();
e.stopPropagation();
if (map.hasLayer(layer)) {
map.removeLayer(layer);
map.removeLayer(gridlayer);
// you had "thelayer", but it should be "layer":
map.legendControl.removeLegend(layer.getTileJSON().legend);
// change two lines that were here to the following:
this.className = '';
} else {
map.addLayer(layer);
map.addLayer(gridlayer);
this.className = 'active';
map.legendControl.addLegend(layer.getTileJSON().legend);
}
thelayer = layer;
};很抱歉你的解释很混乱,但你同时问了两个问题,这是我能想到的最干净的回答方法。
https://stackoverflow.com/questions/22899336
复制相似问题