1

So, I have a LayerGroup with polylines, points, etc. in some Layers. A certain Polyline has the handler:

Polyline.on('click', lineHelper);

Can I find out in this handler which LayerGroup the Polyline belongs to?

1 Answer 1

1

Can I find out in this handler which LayerGroup the Polyline belongs to?

No, since a Polyline (or any other Layer) can belong to zero, one, or several LayerGroups at once; a Layer doesn't keep a list of LayerGroups it's part of (it can belong to LayerGroups not on the map the layer is in).

You might want to iterate all known LayerGroups and run hasLayer() on each, or (if you use the same event handler for several layers) use FeatureGroups instead of LayerGroups, and attach the event handler to the FeatureGroup just once (instead of attaching an event handler to each individual Layer).

2
  • No way to get LayerGroups... Jan 15, 2020 at 15:20
  • And oneLayer.hasLayer(otnerLayer) return FALSE if otnerLayer is not a direct child of oneLayer. Jan 15, 2020 at 15:54

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.