Leaflet - tell whether an object a layer or a group

المشرف العام

Administrator
طاقم الإدارة
I need to close popups on an object, but I don't know whether it is a layer or a geoJSON (and hence a feature group). If the former, I can do layer.closePopup(), but if the latter, I have to do layer.eachLayer().closePopup() (I think).

How do I test whether an object in Leaflet is a layer or a group? I'm getting some joy with if (layer.childNodes), but it doesn't always seem to work, and I'd rather have a Leaflet solution than a DOM one, as I think it would be more reliable.



أكثر...
 
أعلى