opengeos / leafmap

A Python package for interactive mapping and geospatial analysis with minimal coding in a Jupyter environment
https://leafmap.org
MIT License
3.22k stars 386 forks source link

ipyleaflet backend only renders a grey rectangle #302

Closed hydroEng closed 2 years ago

hydroEng commented 2 years ago

Environment Information

Description

Describe what you were trying to get done. Tell us what happened, what went wrong, and what you expected to happen.

What I Did

I'm trying to set up a web map using leafmap using the ipyleaflet backend (i.e. the default one).

Writing this in my IDE and running:

import leafmap

m = leafmap.Map(center=(40, -100), zoom=4)
m.to_html('leafmap.html')

Provides me a html with simply a grey box rather than showing the openstreetmap basemap. I've tried adding tile layers but I don't get much luck - for example, when adding ESRI world imagery, a lot of the tiles show as not available even though they work fine when using folium.

giswqs commented 2 years ago

What IDE?

hydroEng commented 2 years ago

Pycharm

The map displays correctly when using jupyter notebook. But even there when rendering to html I get the same problem.

giswqs commented 2 years ago

I have not used PyCharm with leafmap before. I guess this is an issue specific to PyCharm. Try the following code. If it doesn't work, then it is an ipyleaflet issue rather than leafmap.

import ipyleaflet m = ipyleaflet.Map() m

hydroEng commented 2 years ago

I used

import ipyleaflet

m = ipyleaflet.Map()
m.save('my_map.html', title='My Map')

And got the same result in the html. I guess this is an ipyleaflet issue... but thanks for your help anyway.

Somewhat off topic, would the folium backend support using ImageOverlay to plot a raster (using rasterio to bring in a tiff file as an array) and applying a colormap to it (also ignoring nodata values)? I can do all these things in folium itself, but the colormap comes out buggy.

I was hoping to use the ipyleaflet backend's ability to plot a .tiff directly.

giswqs commented 2 years ago

Yes, you can use m.add_raster() to load any local raster datasets. It supports both folium and ipyleaflet. It has parameters for custom if color maps.

giswqs commented 2 years ago

See https://leafmap.org/notebooks/32_local_tile/

hydroEng commented 2 years ago

Amazing. Thank you!