PaulLeCam / react-leaflet

React components for Leaflet maps
https://react-leaflet.js.org
Other
5.13k stars 884 forks source link

Fill FeatureGroup's layers declaratively like LayerGroup #86

Closed jgoux closed 8 years ago

jgoux commented 8 years ago

Hello, is it possible to declare FeatureGroup's layers like LayerGroup ? Example :

<FeatureGroup>
    <Marker position={foo}></Marker>
    <Marker position={bar}></Marker>
</FeatureGroup>
PaulLeCam commented 8 years ago

Hi, No, this is not supported yet, probably in a future release.

bradsimantel commented 8 years ago

How would this be different from your LayerGroup implementation? I was planning on trying to get this syntax working for FeatureGroup this weekend (and then opening a pull request).

jgoux commented 8 years ago

@bradsimantel It has the getBounds() function which will allow me to center my map based on the elements' coordinates inside the FeatureGroup Disclamer: I'm a total newbie with Leaflet, maybe there is an easier solution for my case. :)

bradsimantel commented 8 years ago

@jgoux: Sorry for the miscommunication! I understand that Leaflet's FeatureGroup has some useful methods that differentiate it from LayerGroup. I was trying to ask @PaulLeCam how he thinks a component wrapper around FeatureGroup that allows for child Marker components might be different from the current wrapper around LayerGroup.

PaulLeCam commented 8 years ago

Hi, I created a new branch to have the FeatureGroup work like LayerGroup: https://github.com/PaulLeCam/react-leaflet/tree/feature-group

The main differences from LayerGroup is that it needs to pass the popupContainer prop to its children, so that the Popups can bind to it, and support the style props, as they can be applied to its children using setStyle

It seems to work for a very simple use case (https://github.com/PaulLeCam/react-leaflet/blob/feature-group/example/other-layers.js#L34) but it needs lots of tests for different cases, on the top of my head:

Please let me know if you're playing around with this branch and have any issue and answers to these questions!

bradsimantel commented 8 years ago

This is awesome, @PaulLeCam! Thanks so much! I'll post updates as I try stuff.

PaulLeCam commented 8 years ago

Hi,

I added it to v0.9, please let me know if you have any issue with it!