I have a problem with my geojson layers. When I lunch my site they are all switched on, but I don't want to. Is there any solution to have lunched only one layer when my site starts, not the all one? Here is the simple example what I want https://jsfiddle.net/expedio/dtLyvffg/
And this is the code with my layers:
var controlLayers = L.control.layers().addTo(map);
$.getJSON("data/Zabudowa.geoJSON", function(geojson) {
var geojsonLayer = L.geoJson(geojson, {
style: function(feature) {
return {
'weight': 0,
'fillColor': 'brown',
'fillOpacity': 1
}
},
onEachFeature: function(feature, layer) {
var popupText = "Numer obiektu: " + feature.properties.OBJECTID + "<br>Sposob uzytkowania: " + feature.properties.type + "<br><a href='" + feature.properties.url + "'>More info</a>";
layer.bindPopup(popupText);
}
}).addTo(map);
controlLayers.addOverlay(geojsonLayer, 'Zabudowa');
});
controlLayers.addOverlay(geojsonLayer, 'Drogi');
});
var myIcon = L.Icon.extend({
iconUrl: 'icons/cemetery-24.png'
});
$.getJSON("data/miejsca_pamieci.geoJSON", function(geojson) {
var geojsonLayer = L.geoJson(geojson, {
pointToLayer: function(feature, latLng) {
return new L.Marker(latLng, {
icon: new myIcon({
iconUrl: 'icons/cemetery-24.png',
iconSize: [24, 24],
iconAnchor: [12, 24],
popupAnchor: [0, -24]
})
})
},
onEachFeature: function(feature, layer) {
layer.bindPopup("Opis: " + feature.properties.Opis)
}
}).addTo(map);
controlLayers.addOverlay(geojsonLayer, 'Miejsca_pamieci');
});
var myIcon = L.Icon.extend({
iconUrl: 'icons/accessdenied.png'
});
$.getJSON("data/Fotografie.geoJSON", function(geojson) {
var geojsonLayer = L.geoJson(geojson, {
pointToLayer: function(feature, latLng) {
return new L.Marker(latLng, {
icon: new myIcon({
iconUrl: 'icons/accessdenied.png',
iconSize: [32, 37],
iconAnchor: [16, 37],
popupAnchor: [0, -37]
})
})
},
onEachFeature: function(feature, layer) {
layer.bindPopup(feature.properties.Name, {
maxWidth: "auto"
})
}
}).addTo(map);
controlLayers.addOverlay(geojsonLayer, 'Fotografie');
});