0

I am making my own layer control in a way. I want to check if a named L.geoJSON has any features. If not I will fetch GeoJSON from an API and add it to the layer.

But I cannot work out how to check if it has any feature? Have tried to find someway around it, have been trying to look for properties on the object, but cannot get it to work.

const mygeojsonLayer= L.geoJSON(null)

if(mygeojsonLayer._layers.length === 0){
        mygeojsonLayer.addTo(map)
} else {fetchData()}
  • 3
    GeoJSON layer is a group layer, so you could use getLayers() method to check if it contains any layers/features. – TomazicM Sep 17 at 12:43
  • Thats right! Tha should work. Thaks! – geogrow Sep 17 at 12:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.