2

I add some geojson layers to the map control once a layer is loaded and the control can show all the layer names. But I notice that all the checkboxes are unchecked by default. So that once I click the control to uncollapse it, all the layers disappear. And I have to check them one by one to display them again.

The code is like:

ctrl = L.control.layers([aBaseLayer]); ctrl.addOverlay(aGeoJsonLayer, 'ageojsonlayer'); 

Then I can control the aGeoJsonLayer, but unlike the aBaseLayer, the aGeoJsonLayer is not checked by default in the control panel. So every time after the layer is loaded, when I click the control, the layer will be gone until I check it in the control panel. Any way to fix this?

3
  • how about providing some functioning code (or a jsfiddle) to demonstrate the issue
    – Kelso
    Commented Dec 9, 2012 at 21:56
  • @Kelso The code is like: ctrl = L.control.layers([aBaseLayer]); ctrl.addOverlay(aGeoJsonLayer, 'ageojsonlayer'); Then I can control the aGeoJsonLayer, but unlike the aBaseLayer, the aGeoJsonLayer is not checked by default in the control panel. So every time after the layer is loaded, when I click the control, the layer will be gone until I check it in the control panel. Commented Dec 10, 2012 at 3:40
  • Please add and format the code into your question. I said functioning code or jsfiddle to make it easier to answer your question.
    – Kelso
    Commented Dec 11, 2012 at 11:40

2 Answers 2

1

Have you tried something like

L.control.layers([aBaseLayer], [aGeoJsonLayer]).addTo(map);

Although you may want to add your layer as a geojson layer: http://leafletjs.com/reference.html#geojson

1

Your code only creates a control layer and does not add your base layer or overlay to the map. So if your aBaseLayer and aGeoJsonLayer are not on the map when you create the control layer, the checkboxes will not be selected.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.