jupyter-widgets / ipyleaflet

A Jupyter - Leaflet.js bridge
https://ipyleaflet.readthedocs.io
MIT License
1.49k stars 365 forks source link

Custom projections #1117

Open banesullivan opened 1 year ago

banesullivan commented 1 year ago

I'm hoping for some help using a custom projection with ipyleaflet.

My ultimate goal is to have a slippy map viewer for non-geospatial images (think microscopy).

I'm struggling to get the Map crs correct so that the tile layer aligns with the coordinates I expect.

Can someone help me refine this example?

from ipyleaflet import Map, basemaps, projections, Rectangle, TileLayer

size_x, size_y = 500, 500

crs = dict(
    name='PixelSpace',
    custom=True,
    resolutions=[256 * 2 ** (-l) for l in range(20)],
    proj4def='+proj=longlat +axis=esu',
    bounds=[[0, 0], [size_y, size_x]],
    origin=[0, 0],
)

# a debug tile layer that returns a PNG with "x/y/z" in a box
debug = TileLayer(url='https://tileserver.banesullivan.com/api/tiles/debug/{z}/{x}/{y}.png')
rectangle = Rectangle(bounds=[[0,0], [size_y, size_x]])

m = Map(basemap=debug, zoom=0, crs=crs, center=[size_y/2, size_x/2])
m.add_layer(rectangle)
m

Screenshot 2023-05-31 at 1 33 34 PM Screenshot 2023-05-31 at 1 33 46 PM

I expect the tile layer to only load within the bounds of the rectangle.