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

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).

Your Answer

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

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