Closed banesullivan closed 2 years ago
Fallback to style dictionary json blob in request body
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=
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
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}`;
https://girder.github.io/large_image/tilesource_options.html#style