Skip to content

FeatureGroup breaks with non-evented children #1962

@sheppard

Description

@sheppard

A Leaflet user on IRC wanted to return a LayerGroup for a feature in their custom pointToLayer function but was getting an error. After some investigation, it looks like FeatureGroup (and GeoJSON by extension) expects all of its child layers to have L.Mixin.Events applied (i.e. to have an on method).

Thus, it is not possible to return a LayerGroup from pointToLayer - instead one must return a FeatureGroup which has the events mixin. This is probably better anyway, since presumably the user would want the same events applied to all members of the group. Should we:

  • update the docs and the GeoJSON example to clarify that pointToLayer only works with evented ILayers (basically everything except LayerGroup)
  • and/or, update FeatureGroup.addLayer to check to ensure the child layer is evented before trying to call on()

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions