girder / django-large-image

🩻 🗺️ Django endpoints for working with large images for tile serving
Apache License 2.0
61 stars 3 forks source link

Full mapping of URL parameters to style dictionary #10

Closed banesullivan closed 2 years ago

banesullivan commented 2 years ago

https://girder.github.io/large_image/tilesource_options.html#style

banesullivan commented 2 years ago

Fallback to style dictionary json blob in request body

banesullivan commented 2 years ago

I've decided to handle this by supporting a base64 encoding style query option. Here is an example:

import base64
import json
import requests

from ipyleaflet import Map, TileLayer

style = {
        'bands': [
            {'band': 1, 'palette': ['#000', '#0f0']},
        ]
    }

style_base64 = base64.urlsafe_b64encode(json.dumps(style).encode()).decode()

layer = TileLayer(
    url=f'http://localhost:8000/api/image-file/2/tiles/{{z}}/{{x}}/{{y}}.png?projection=EPSG:3857&style={style_base64}',

)
m = Map(zoom=4)
m.add_layer(layer)
m

style_base64 (what's passed as the style query argument) would have a value of eyJiYW5kcyI6IFt7ImJhbmQiOiAxLCAicGFsZXR0ZSI6IFsiIzAwMCIsICIjMGYwIl19XX0=

banesullivan commented 2 years ago

Fallback to style dictionary json blob in request body

I have decided to remove that in favor of a base64 encoded string as having a body is not RESTful for GET requests

banesullivan commented 2 years ago

For a JS front-end, this would simply be:

var style = {
  bands: [
    {band: 1, palette: ['#000', '#0f0']}
  ]
};
var styleBase64 = btoa(JSON.stringify(style))
thumbnailUrl = `${host}/${baseEndpoint}/${imageId}/thumbnail.png?style=${styleBase64}`;