Open banesullivan opened 5 days ago
unfortunately, until I get around to entirely changing to something like anywidget where I can better control how tiles are requested and the parameters that go with that request (like #219), the URL lenght issue likely isn't something I'm going to be able to resolve.
What could work is registering the colormap with matplotlib as a named colormap prior to runtime so that when localtileserver's background python thread looks for it by name it can be found
In case anyone out there knows of a better way to serialize and pass along the colormap, I am currently serializing it to JSON and injecting it as a URL query parameter here:
TiTiler supports JSON encoded custom Colormap. Not sure if its implementation be useful to localtileserver.
https://developmentseed.org/titiler/endpoints/cog/#description
import leafmap
url = "https://github.com/opengeos/datasets/releases/download/raster/nlcd_2021_land_cover_30m.tif"
colormap = {
"11": "#466b9f",
"12": "#d1def8",
"21": "#dec5c5",
"22": "#d99282",
"23": "#eb0000",
"24": "#ab0000",
"31": "#b3ac9f",
"41": "#68ab5f",
"42": "#1c5f2c",
"43": "#b5c58f",
"51": "#af963c",
"52": "#ccb879",
"71": "#dfdfc2",
"72": "#d1d182",
"73": "#a3cc51",
"74": "#82ba9e",
"81": "#dcd939",
"82": "#ab6c28",
"90": "#b8d9eb",
"95": "#6c9fb8",
}
m = leafmap.Map(center=[40, -100], zoom=4, height="650px")
m.add_basemap("Satellite")
m.add_cog_layer(url, colormap=colormap, name="NLCD Land Cover", nodata=0)
m.add_legend(title="NLCD Land Cover Type", builtin_legend="NLCD")
m.add_layer_manager()
m
It looks like some colormaps can easily become too large when serialized to pass through as a URL parameter. Take the following example originally reported in https://github.com/opengeos/leafmap/discussions/966
Create the sample data
Attempt plotting
Create the colormap
Attempt to use with localtileserver (not that the above/below colors are unused:
and if I try to use on a map:
then I see browser network errors:
414 Request-URI Too Large
Summary
LinearSegmentedColormap
are not usedLinearSegmentedColormap
is too large for the URL parameters and silently fails