Skip to content

Commit

Permalink
Fix generated tiler links in items (#41) (#42)
Browse files Browse the repository at this point in the history
* wip

* Fix render params for titiler upgrade

* Lint

* Update changelog

Co-authored-by: Matthew McFarland <[email protected]>
  • Loading branch information
lossyrob and mmcfarland committed Jan 25, 2022
1 parent e4e0c84 commit b22391d
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 26 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

## [2022.1.2]

### Fixed

- Fixed renderconfigs for item tile links [#41](https://github.com/microsoft/planetary-computer-apis/pull/41)
- Fixes hostname setting for URLs used in item links

## [2022.1.1]

### Fixed
Expand Down Expand Up @@ -44,4 +51,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Updated search limit constraints to avoid 500s [#15](https://github.com/microsoft/planetary-computer-apis/pull/15)
- Fixed STAC `describedby` and `preview` links [#33](https://github.com/microsoft/planetary-computer-apis/pull/33)
- Default search limit restored to 250 [#36](https://github.com/microsoft/planetary-computer-apis/pull/36)
- Work around issue with LandPage stac_extensions [#37](https://github.com/microsoft/planetary-computer-apis/pull/37)
- Work around issue with LandPage stac_extensions [#37](https://github.com/microsoft/planetary-computer-apis/pull/37)
22 changes: 13 additions & 9 deletions pccommon/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ class DefaultRenderConfig:
normal human vision, parameters will likely encode this rendering.
"""

assets: List[str]
render_params: Dict[str, Any]
minzoom: int
assets: Optional[List[str]] = None
maxzoom: Optional[int] = 18
create_links: bool = True
has_mosaic: bool = False
Expand All @@ -29,8 +29,14 @@ class DefaultRenderConfig:
requires_token: bool = False
hidden: bool = False # Hide from API

def get_assets_param(self) -> str:
return ",".join(self.assets)
def get_assets_params(self) -> str:
if self.assets is None:
return ""

if len(self.assets) == 1:
return f"&assets={self.assets[0]}"

return "&assets=".join(self.assets)

def get_render_params(self) -> str:
return get_param_str(self.render_params)
Expand Down Expand Up @@ -72,7 +78,7 @@ def should_add_item_links(self) -> bool:
),
"aster-l1t": DefaultRenderConfig(
assets=["VNIR"],
render_params={"bidx": [2, 3, 1], "nodata": 0},
render_params={"asset_bidx": "VNIR|2,3,1", "nodata": 0},
mosaic_preview_zoom=9,
mosaic_preview_coords=[37.2141, -104.2947],
minzoom=9,
Expand Down Expand Up @@ -111,9 +117,8 @@ def should_add_item_links(self) -> bool:
minzoom=5,
),
"gnatsgo-rasters": DefaultRenderConfig(
create_links=False,
assets=["aws0_100"],
render_params={"colormap_name": "cividis"},
render_params={"colormap_name": "cividis", "rescale": [0, 600]},
mosaic_preview_zoom=6,
mosaic_preview_coords=[44.1454, -112.6404],
requires_token=True,
Expand All @@ -130,7 +135,6 @@ def should_add_item_links(self) -> bool:
),
"goes-cmi": DefaultRenderConfig(
create_links=True,
assets=["data"],
render_params={
"expression": (
"C02_2km_wm,"
Expand Down Expand Up @@ -212,7 +216,7 @@ def should_add_item_links(self) -> bool:
),
"naip": DefaultRenderConfig(
assets=["image"],
render_params={"bidx": [1, 2, 3]},
render_params={"asset_bidx": "image|1,2,3"},
mosaic_preview_zoom=13,
mosaic_preview_coords=[36.0891, -111.8577],
minzoom=11,
Expand All @@ -235,7 +239,7 @@ def should_add_item_links(self) -> bool:
),
"sentinel-2-l2a": DefaultRenderConfig(
assets=["visual"],
render_params={"bidx": [1, 2, 3], "nodata": 0},
render_params={"asset_bidx": "visual|1,2,3", "nodata": 0},
mosaic_preview_zoom=9,
mosaic_preview_coords=[-16.4940, 124.0274],
requires_token=True,
Expand Down
10 changes: 5 additions & 5 deletions pcstac/pcstac/tiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def _get_collection_tilejson_asset(self) -> Dict[str, Any]:
(
"collection/tilejson.json?"
f"collection={self.collection_id}"
f"&assets={self.render_config.get_assets_param()}"
f"{self.render_config.get_assets_params()}"
f"{render_params_part}"
),
)
Expand Down Expand Up @@ -91,8 +91,8 @@ def _get_item_preview_asset(self, item_id: str) -> Dict[str, Any]:
(
f"item/preview.png?"
f"collection={self.collection_id}"
f"&items={item_id}"
f"&assets={self.render_config.get_assets_param()}"
f"&item={item_id}"
f"{self.render_config.get_assets_params()}"
f"{render_params_part}"
),
)
Expand All @@ -113,8 +113,8 @@ def _get_item_tilejson_asset(self, item_id: str) -> Dict[str, Any]:
(
"item/tilejson.json?"
f"collection={self.collection_id}"
f"&items={item_id}"
f"&assets={self.render_config.get_assets_param()}"
f"&item={item_id}"
f"{self.render_config.get_assets_params()}"
f"{render_params_part}"
),
)
Expand Down
16 changes: 9 additions & 7 deletions pctiler/pctiler/endpoints/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,15 @@ def map(
content=f"No item map available for collection {collection}",
)

tilejson_params = get_param_str(
{
"collection": collection,
"item": item,
"assets": ",".join(render_config.assets),
}
tilejson_params = (
get_param_str(
{
"collection": collection,
"item": item,
}
)
+ render_config.get_assets_params()
+ f"&{render_config.get_render_params()}"
)

tilejson_url = pc_tile_factory.url_for(request, "tilejson")
Expand All @@ -75,6 +78,5 @@ def map(
"collectionId": collection,
"itemId": item,
"itemUrl": item_url,
"renderParams": get_param_str(render_config.render_params),
},
)
4 changes: 0 additions & 4 deletions pctiler/templates/item_preview.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@
).addTo(map);

var tiles = tileJson.tiles[0];
var renderParams = "{{ renderParams }}";
if (renderParams) {
tiles += "&" + renderParams;
}

var tileLayer = L.tileLayer(tiles, {
minZoom: tileJson.minzoon,
Expand Down

0 comments on commit b22391d

Please sign in to comment.