javascript - Button for layers are always in active state, legend persists for 1st layer when 2 layers are added -
i have mapbox , tilemill layer problem:
check out code here: http://bl.ocks.org/marishaf/3cc9bfbeb412c1120e93
layer buttons they're in "active" mode, although still load , unload layers.
legends load each layer (legends exist public land , zoning layers), if load both , try remove both layers, legend persists first layer loaded.
the legend persists tooltips. example, if load layer legend first (only happens if layers loaded in order) , layer tooltips (for example point source pollution) , mouse on point tooltip called , try remove layer legend, legend persists.
- remove "link.classname = 'active';" before onclick function.
- change "if (map.haslayer(layer))" statement more similar "else" 1 ("layer" instead of "thelayer" , 1 "classname" change).
snippet:
link.href = '#'; // remove line here link.innerhtml = name; link.onclick = function(e) { e.preventdefault(); e.stoppropagation(); if (map.haslayer(layer)) { map.removelayer(layer); map.removelayer(gridlayer); // had "thelayer", should "layer": map.legendcontrol.removelegend(layer.gettilejson().legend); // change 2 lines here following: this.classname = ''; } else { map.addlayer(layer); map.addlayer(gridlayer); this.classname = 'active'; map.legendcontrol.addlegend(layer.gettilejson().legend); } thelayer = layer; };
sorry messy explanation, asking 2 questions @ once, , cleanest way can think answer.
Comments
Post a Comment