Skip to content

Commit

Permalink
fix: render fix for titiler-pgstac v1 upgrade (#408)
Browse files Browse the repository at this point in the history
  • Loading branch information
smohiudd authored Jul 31, 2024
1 parent f449325 commit 18a4d30
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
25 changes: 17 additions & 8 deletions stac_api/runtime/src/links.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,16 @@ def inject_item(self, item: Item) -> None:
item_id = item.get("id", "")
item["links"] = item.get("links", [])
if self.tiler_href:
item["links"].append(self._get_item_map_link(item_id))
item["assets"]["rendered_preview"] = self._get_item_preview_link(item_id)
item["links"].append(self._get_item_map_link(item_id, self.collection_id))
item["assets"]["rendered_preview"] = self._get_item_preview_link(
item_id, self.collection_id
)

def _get_item_map_link(self, item_id: str) -> Dict[str, Any]:
qs = self.render_config.get_full_render_qs(self.collection_id, item_id)
href = urljoin(self.tiler_href, f"stac/map?{qs}")
def _get_item_map_link(self, item_id: str, collection_id: str) -> Dict[str, Any]:
qs = self.render_config.get_full_render_qs()
href = urljoin(
self.tiler_href, f"collections/{collection_id}/items/{item_id}/map?{qs}"
)

return {
"title": "Map of Item",
Expand All @@ -60,9 +64,14 @@ def _get_item_map_link(self, item_id: str) -> Dict[str, Any]:
"type": "text/html",
}

def _get_item_preview_link(self, item_id: str) -> Dict[str, Any]:
qs = self.render_config.get_full_render_qs(self.collection_id, item_id)
href = urljoin(self.tiler_href, f"stac/preview.png?{qs}")
def _get_item_preview_link(
self, item_id: str, collection_id: str
) -> Dict[str, Any]:
qs = self.render_config.get_full_render_qs()
href = urljoin(
self.tiler_href,
f"collections/{collection_id}/items/{item_id}/preview.png?{qs}",
)

return {
"title": "Rendered preview",
Expand Down
13 changes: 4 additions & 9 deletions stac_api/runtime/src/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,16 @@ class RenderConfig(BaseModel):
mosaic_preview_zoom: Optional[int] = None
mosaic_preview_coords: Optional[List[float]] = None

def get_full_render_qs(self, collection: str, item: Optional[str] = None) -> str:
def get_full_render_qs(self) -> str:
"""
Return the full render query string, including the
item, collection, render and assets parameters.
Return the full render query string including render and assets parameters.
"""
collection_part = f"collection={collection}" if collection else ""
item_part = f"&item={item}" if item else ""
render_part = self.get_render_params()

return "".join([collection_part, item_part, render_part])
return self.get_render_params()

def get_render_params(self) -> str:
"""Get the render parameters as a query string."""
params = self.render_params.copy()
return f"&{get_param_str(params)}"
return f"{get_param_str(params)}"

class Config:
"""Pydantic config class for RenderConfig."""
Expand Down

0 comments on commit 18a4d30

Please sign in to comment.