【发布时间】:2014-05-16 23:38:06
【问题描述】:
我是 Leaflet/JavaScript 的新手,一直在努力为图例获取地图,以便仅在从图层控件中选择特定图层时显示。我有三层,其中一层我想没有图例,另外两层有相应的图例。我遇到了一个示例,但无法使其工作:
// Add and remove legend from layers
map.on('overlayadd', function (eventLayer) {
// Switch to the Permafrost legend...
if (eventLayer.name === 'Permafrost') {
this.removeControl(legend1);
legend2.addTo(this);
} else { // Or switch to the treeline legend...
this.removeControl(legend2);
legend1.addTo(this);
}});
我用具体的例子创建了一个jsfiddle:
http://jsfiddle.net/gerlis/T8DHb/3/
任何指导将不胜感激。
【问题讨论】: