adding layers in layer group dynamically to layer control in leaflet -


i creating bunch of vector layers via xhr calls, , want add layer group , add layer group layer control. way thinking is

1. add layer control map base layer in control 2. create layer via `xhr`      2.1. check if layer group lg exists in layer control         2.1.1. if yes, add layer lg       2.1.2. if no, add layer group lg layer control , add layer lg 3. repeat #2 above. 

well, tried above (without layer group part) , works (code below).

lc = l.control.layers({'osm': osm}).addto(map); 

and then

x.onload = function(e) {     if (x.readystate === 4) {         if (x.status === 200) {             var res = json.parse(x.responsetext);             ..             lc.addoverlay(lyr, "layer name");         }     } }; 

however, can't figure out layer group. suggestions welcome.

in ajax callback, should find

layergroup = l.layergroup()         .addlayer(vector1))         .addlayer(vector2))         .addlayer(vector3))         ....         .addto(map);  if(layercontrol === false) {  // var layercontrol set false in init phase;      layercontrol = l.control.layers().addto(map); }  layercontrol.addoverlay(layergroup , "my batch of vectors"); 

see example here: http://jsfiddle.net/franceimage/9xjt8223/


Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -