-
Notifications
You must be signed in to change notification settings - Fork 175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add Custom Colormap querystring option #262
Changes from all commits
ed2b750
15c3f91
5530888
b7db54d
0a40990
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
"""Common dependency.""" | ||
|
||
import json | ||
import re | ||
from dataclasses import dataclass, field | ||
from enum import Enum | ||
|
@@ -9,7 +10,7 @@ | |
from morecantile import tms | ||
from morecantile.models import TileMatrixSet | ||
from rasterio.enums import Resampling | ||
from rio_tiler.colormap import cmap | ||
from rio_tiler.colormap import cmap, parse_color | ||
from rio_tiler.errors import MissingAssets, MissingBands | ||
|
||
from .custom import cmap as custom_colormap | ||
|
@@ -69,11 +70,19 @@ def TMSParams( | |
|
||
|
||
def ColorMapParams( | ||
color_map: ColorMapName = Query(None, description="Colormap name",) | ||
colormap_name: ColorMapName = Query(None, description="Colormap name"), | ||
colormap: str = Query(None, description="JSON encoded custom Colormap"), | ||
) -> Optional[Dict]: | ||
"""Colormap Dependency.""" | ||
if color_map: | ||
return cmap.get(color_map.value) | ||
if colormap_name: | ||
return cmap.get(colormap_name.value) | ||
|
||
if colormap: | ||
return json.loads( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we also accept base64 encoded string? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. neither are great, but I think base64 is less weird than JSON for get requests There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. another way maybe would be to pass a list of value like
|
||
colormap, | ||
object_hook=lambda x: {int(k): parse_color(v) for k, v in x.items()}, | ||
) | ||
|
||
return None | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
breaking change