Comments (10)
Are you trying to overlay GeoTIFFs or simple jpg/png on the map? For GeoTIFF, you can just add it as a tile layer to the map. Leafmap just added support for this. See opengeos/leafmap#134
from localtileserver.
In my case it's only plain jpg/png.
from localtileserver.
Leafmap supports image_overlay with a local file. Have you tried it?
https://leafmap.org/leafmap/#leafmap.leafmap.Map.image_overlay
from localtileserver.
tl;dr: yes, I can add this by supporting non-geospatial images and then having you pass the existing thumbnail
endpoint's URL to ImageOverlay.
Leafmap supports image_overlay with a local file. Have you tried it?
I think there might be an issue with ipyleaflet/leaflet being able to load from local files that are not relative to the webserver launching leaflet (Jupyter) and that's what jupyter-widgets/ipyleaflet#234 is all about?
localtileserver
's focus is to serve tiles specifically for geospatial rasters and becoming an arbitrary file server is a bit out of scope for localtileserver
. Further, this would definitely present a major security vulnerability if localtileserver
is used in any production environment (or if the port you launch it on your machine is visible to the outside world) as it would effectively make your entire file system available at the hosted port (because the underlying Python process that is the webserver has access to your entire filesystem).
Perhaps what I can do is add in an some optional dependencies to support tile serving of non-geospatial images from the large_image
stack. Then, when you want to overlay an image that has no geospatial bounds, you could hit the /thumbnail
endpoint to be served that image at a URL and that URL is what you'd pass to ImageOverlay
. This is something I have implemented in other tile server apps and really wouldn't require much work here... though it would require working through some annoying edge cases to make sure the tile server will work with both geospatial and non-geospatial images with default parameters
from localtileserver.
Loading images from the localtileserver's root would be totally fine.
from localtileserver.
Leafmap supports image_overlay with a local file. Have you tried it?
@giswqs It works for the default leafmap.Map
(haven't tried anything else). I see that it passes the file wrapped in a base64 encoded URL in https://github.com/giswqs/leafmap/blob/09f9f732cdf15f3c7f52f4c544b1e9b13b84a337/leafmap/leafmap.py#L1358. Would it not be nice to have that in ipyleaflet directly? But I understand that this project has much unpredictability.
Also, I'm not sure I can refresh the image data for an existing overlay, can I?
from localtileserver.
leafmap.image_overlay()
is based on ipyleaflet. If ipyleaflet can refresh the image data for an existing overlay, then leafmap should work as well. I have not tried it personally.
from localtileserver.
My point is that the lines doing the base64 encoding might perhaps better be added to ipyleaflet directly, so it would be possible to create an ImageOverlay
instance and add it to a map in separate steps. leafmap.image_overlay()
does it in one step only, which is shorter, but you don't have a handle to the instance.
from localtileserver.
@deeplook I am not sure how to add that directly to ipyleaflet (dealing with JavaScript). Maybe it is easier to create a new ImageOverlay
(inherits ipyleaflet.ImageOverlay
) with the base64 encoding functionality?
https://github.com/jupyter-widgets/ipyleaflet/blob/stable/ipyleaflet/leaflet.py#L691
from localtileserver.
This feature is out of scope for localtileserver.
With that said, it is possible to use localtileserver
to produce a thumbnail of any local image file. Simply install large-image-source-pil
with pip
and then do the following for PNG/JPEG images:
from localtileserver import TileClient
from ipyleaflet import Map, ImageOverlay
# Some local PNG or JPEG
tc = TileClient('/Users/bane/Desktop/IMG_1385.jpeg')
overlay = ImageOverlay(url=tc.create_url('thumbnail'), bounds=((13, -130), (32, -120)))
m = Map()
m.add_layer(overlay)
m
This is not intended use and, generally, the TileClient
will not work with non-geospatial images and I do not currently plan on supporting non-geospatial images (though we could if there becomes sufficient interest from the microscopy crowd for example)
Considering this feature request is out of scope and really just asking work around something that is broken in ipyleaflet, I am going to close this here.
@deeplook, why don't you just launch a simple Python server next to the file?
From the working directory of the image
$ python -m http.server 8089
Then:
from ipyleaflet import Map, ImageOverlay
overlay = ImageOverlay(url='http://localhost:8089/IMG_1385.jpeg', bounds=((13, -130), (32, -120)))
m = Map()
m.add_layer(overlay)
m
from localtileserver.
Related Issues (20)
- Use localtileserver in a docker container HOT 1
- Error: NeededInitPrefix is not defined HOT 4
- add_raster() isn't adding the downloaded image into the map HOT 15
- add_layer doesn't work with GeoTIFF file converted from xarray Dataset HOT 11
- can't add local raster file in windows HOT 4
- Use ipyleaflet's as_leaflet_layer interface
- Cannot display raster in Google Colab HOT 5
- Generated PNG tiles are not transparent (have black background) HOT 3
- Remote COG no longer works HOT 4
- Tiff file saving to HTML using folium HOT 1
- Tileclient does not show when run dash app python on docker HOT 3
- localtileserver fails with flask==3 HOT 2
- localtileserver not working with Leafmap on Docker HOT 4
- localtileserver client cannot work after setting the http proxy HOT 4
- not working on VS code remote notebook HOT 1
- Passing rasterio.Env context to tile server HOT 5
- nodata causes padding HOT 15
- The vmin and vmax parameters have no effect HOT 2
- Support custom colormaps
- Generate thumbnails in a projection
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from localtileserver.