Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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?

share|improve this question
    
how about providing some functioning code (or a jsfiddle) to demonstrate the issue –  Kelso Dec 9 '12 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. –  user1056824 Dec 10 '12 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 Dec 11 '12 at 11:40
add comment

1 Answer

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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