GithubHelp home page GithubHelp logo

Comments (10)

giswqs avatar giswqs commented on July 28, 2024 1

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.

deeplook avatar deeplook commented on July 28, 2024

In my case it's only plain jpg/png.

from localtileserver.

giswqs avatar giswqs commented on July 28, 2024

Leafmap supports image_overlay with a local file. Have you tried it?

https://leafmap.org/leafmap/#leafmap.leafmap.Map.image_overlay
image

from localtileserver.

banesullivan avatar banesullivan commented on July 28, 2024

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.

deeplook avatar deeplook commented on July 28, 2024

Loading images from the localtileserver's root would be totally fine.

from localtileserver.

deeplook avatar deeplook commented on July 28, 2024

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.

giswqs avatar giswqs commented on July 28, 2024

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.

deeplook avatar deeplook commented on July 28, 2024

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.

giswqs avatar giswqs commented on July 28, 2024

@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.

banesullivan avatar banesullivan commented on July 28, 2024

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

Screen Shot 2021-12-05 at 5 56 16 PM

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.