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 support for as_leaflet_layer in Map.add #1033

Merged
merged 8 commits into from
Aug 10, 2022

Conversation

banesullivan
Copy link
Contributor

@banesullivan banesullivan commented Jul 31, 2022

I use ipyleaflet a ton with localtileserver and I was thinking it'd be convenient if ipyleaflet.Map's add() method supported passing objects with an as_leaflet_layer() interface.

There may be better/cleaner ways to do this, so suggestions are welcome! But, my end goal is to make it easier to go from raster file path to ipyleaflet.Map showing tiles like:

from localtileserver import TileClient
from ipyleaflet import Map

client = TileClient('path/to/geo.tif')  # <--- will have `as_leaflet_layer` method

m = Map(center=client.center(), zoom=client.default_zoom)
m.add_layer(client)
m

@davidbrochart davidbrochart marked this pull request as ready for review July 31, 2022 10:59
Copy link
Member

@davidbrochart davidbrochart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion @banesullivan, I think it would make sense, including for xarray-leaflet.

Copy link
Member

@martinRenou martinRenou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

ipyleaflet/leaflet.py Show resolved Hide resolved
@davidbrochart
Copy link
Member

@banesullivan I think we should document this interface.

@banesullivan
Copy link
Contributor Author

I think we should document this interface.

Agreed. If you all are happy with as_leaflet_layer being the name and it being a method, then I'll add some docs when I get a few minutes

@@ -0,0 +1,68 @@
Layer-Like Objects
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davidbrochart and @martinRenou, please review this explanation and feel free to modify. This is what I came up with on a whim to document the interface.

docs/source/layers/layer_like.rst Outdated Show resolved Hide resolved
docs/source/layers/layer_like.rst Outdated Show resolved Hide resolved
@davidbrochart
Copy link
Member

@banesullivan I just made a small change to the docs, otherwise it looks good to me.
Thanks!

@banesullivan
Copy link
Contributor Author

Thank you for the second set of eyes and improvements!

@davidbrochart davidbrochart merged commit 59f964d into jupyter-widgets:master Aug 10, 2022
@banesullivan
Copy link
Contributor Author

Hm. I just checked the docs built from master: https://ipyleaflet.readthedocs.io/en/master/layers/layer_like.html

and it looks like the data are not embedded in the jupyter output
Screen Shot 2022-08-10 at 11 02 01 AM

@davidbrochart
Copy link
Member

davidbrochart commented Aug 10, 2022

I opened #1037, the code was in LayerGroup instead of 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.

None yet

3 participants