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

Setting layer name shown under the layer control #12

Closed
giswqs opened this issue Jun 26, 2020 · 11 comments
Closed

Setting layer name shown under the layer control #12

giswqs opened this issue Jun 26, 2020 · 11 comments

Comments

@giswqs
Copy link

giswqs commented Jun 26, 2020

Is it possible to set the layer name shown under the layer control? Currently, it seems the default layer name is empty. I tried using l.name = 'layer name', but it has no effect. It would be great if the da.leaflet.plot() has a name argument that can be set directly. Thanks.

@davidbrochart
Copy link
Collaborator

Thanks for your suggestion @giswqs, I will try to work on it soon. Maybe we could use the DataArray name? Similarly, plotting a Dataset (#2) would use each array's name.

@giswqs
Copy link
Author

giswqs commented Jun 26, 2020

@davidbrochart Sounds good. So basically, users can set da.name, then your da.leaflet.plot() function automatically uses da.name as the layer name to show under the layer control. Am I correct?

da = xr.open_rasterio('/path/to/file')
da.name = 'layer name'
l = da.leaflet.plot(m, x_dim='x', y_dim='y')

@davidbrochart
Copy link
Collaborator

Yes, that's the plan. But it could also be possible to set it as a keyword argument of the plot function in the case of a DataArray as you suggested.

@giswqs
Copy link
Author

giswqs commented Jun 26, 2020

Sounds great! Looking forward to it. I will be adding xarray_leaflet as a dependency for geemap. I plan to add a function (e.g., Map.add_raster(file_path, layer_name)) that wraps da.leaflet.plot() so that users can use one line of code to load local raster datasets to geemap.

@davidbrochart
Copy link
Collaborator

Awesome!

@giswqs
Copy link
Author

giswqs commented Jul 2, 2020

I was able to customize the layer name. Here is the source code.

@davidbrochart
Copy link
Collaborator

So it looks like setting the layer name works fine?

@giswqs
Copy link
Author

giswqs commented Jul 2, 2020

Yes, it works with geemap. But I would still suggest you add the layer_name argument to the plot() function so that non-GEE users can still use ipyleaflet to load rasters. Otherwise, when multiple local raster layers are added, only the last one added will be listed under the layer control.

@crendl
Copy link

crendl commented Sep 28, 2020

I would still suggest you add the layer_name argument to the plot() function

I second that suggestion!
Regards

@davidbrochart
Copy link
Collaborator

Sorry, I didn't have much time to work on xarray-leaflet lately. There will be a JupyterCon sprint on ipyleaflet, where we could also work on xarray-leaflet. It would be great if you could participate!

@davidbrochart
Copy link
Collaborator

The layer name is now set to the DataArray name (see davidbrochart@66536e0).

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

No branches or pull requests

3 participants