Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add other controls in v1 TODO #100

Merged
merged 4 commits into from
Nov 24, 2015
Merged

Add other controls in v1 TODO #100

merged 4 commits into from
Nov 24, 2015

Conversation

jonboiser
Copy link
Contributor

Filling out some of the missing controls in #87.

I've done some basic testing on Attribution and Scale. The Layers control gets placed on the map, but I'm not sure how to correctly pass a base layer reference from a, say, TileLayer component into the Layers control.

@jonboiser
Copy link
Contributor Author

Here is one solution I've been working on for the LayersControl. In your Map, you can include multiple layers as children.

<Map bounds={this.state.bounds}>
  <TileLayer
    attribution='&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
    layerName='OpenStreetMap'
    url='http://{s}.tile.osm.org/{z}/{x}/{y}.png'
  />
  <TileLayer
    attribution='&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
    layerName='OpenStreetMap2'
    url='http://otile4.mqcdn.com/tiles/1.0.0/osm/{z}/{x}/{y}.png'
  />
  <LayersControl baseLayers={['OpenStreetMap', 'OpenStreetMap2']}/>
</Map>

The difference is that you pass layerName props into the layers, and pass an array matching those names as a prop into LayersControl.

I'm not sure we can look at all the layers synchronously, so in the LayersControl componentWillMount stage, we listen for these layers being added to the map asynchronously. When the layer is added, we also add it to the control. When we are sure the last layer is added, we remove the event listener.

@PaulLeCam
Copy link
Owner

Hey, thanks for the PR!

I'll try to have a look at Leaflet's doc this week for these controls, see if there any specific cases to consider.
Other than that I think it will mostly be about handling dynamic properties and adding some doc, but your current code looks good.

PaulLeCam added a commit that referenced this pull request Nov 24, 2015
Add other controls in v1 TODO
@PaulLeCam PaulLeCam merged commit d9b0578 into PaulLeCam:master Nov 24, 2015
@PaulLeCam
Copy link
Owner

Thanks!

@chriswiggins
Copy link

Sorry to dig this up - I'm having issues with understanding how to use the layers control? It seems to "work" when I pass actual leaflet objects in as you would normally to L.control.layers, but how do you set a default?

Much appreciated - happy to submit a PR with updated Readme instructions and even an example once I get it working :-)

@PaulLeCam
Copy link
Owner

What do you mean by default? The default options are Leaflet's ones, this library simply passes the props to the relevant Leaflet constructor.

@chriswiggins
Copy link

chriswiggins commented Feb 15, 2016 via email

@TobyEalden
Copy link

Hi - I'm having a similar issue - I have a <GeoJson> overlay as a child of <Map> - how do I configure the <LayersControl> overlays property to reference the <GeoJson> element? Do I need to write some code in componentDidMount to discover the Leaflet element corresponding to the GeoJson layer and manually set the overlays property?

@jonboiser
Copy link
Contributor Author

@chriswiggins Could you give a code example of this?

I was wondering if it was possible to pass in a <TileLayer> through to LayersControl

I think I had a similar idea when I first wrote these wrappers (see my earlier comment), but I think it would involve writing some more logic into the guts of LayersControl to pull it off.

@chriswiggins
Copy link

@jonboiser I was thinking of something like this:

<LayersControl ...layersOpts>
    <TileLayer type='base' title='Street View' selected='true' ...otherOpts/>
    <TileLayer type='base' title='Satellite View' ...otherOpts />
    <ImageOverlay type='Overlay' title='Overlay' ...otherOpts />
</LayersControl>

Come to think of it, that could actually be fairly straightforward if the LayersControl element "rendered" its children and then added to the layers control. I'll have a play today and get back to you all on whether or not this works!

@chriswiggins
Copy link

So I've given this a go and no immediate luck - mainly because the TileLayers are expecting a map prop to be passed to them however in this implementation thats not what we want to do. I might have to end up modifying lots of components to get this to work.

Any other ideas around how we could do this?

@jonboiser
Copy link
Contributor Author

So you would wrap the LayersControl-composed-with-TileLayers in a Map like this? I think this would be a nice way to work with Leaflet.

<Map>
<LayersControl ...layersOpts>
    <TileLayer type='base' title='Street View' selected='true' ...otherOpts/>
    <TileLayer type='base' title='Satellite View' ...otherOpts />
    <ImageOverlay type='Overlay' title='Overlay' ...otherOpts />
</LayersControl>
</Map>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants