Setting Default TMS ID #1075
Answered
by
vincentsarago
judsoncrouch-eog
asked this question in
Q&A
-
Hello, Is there a way to hard code the WebMercatorQuad TMS ID in the latest version of TiTiler? I want to upgrade my deployment of TiTiler to the latest, but we have a lot of saved URLs that don't include the new required TMS ID. |
Beta Was this translation helpful? Give feedback.
Answered by
vincentsarago
Jan 22, 2025
Replies: 1 comment 1 reply
-
Sorry for the disagreement, we needed to remove the default TMS Id to match the OGC specification 🙁 You could create custom endpoint that redirect to the correct URL, but you'll need to write your own application. This could also be in a Middleware maybe. from attrs import define
from typing import Annotated
from fastapi import Path
from fastapi.responses import RedirectResponse
from pydantic import Field
from titiler.core.factory import img_endpoint_params, TilerFactory
from titiler.core.resources.enums import ImageType
@define(kw_only=True)
class CustomFactory(TilerFactory):
def register_routes(self):
super().register_routes()
@self.router.get(r"/tiles/{z}/{x}/{y}", **img_endpoint_params)
@self.router.get(r"/tiles/{z}/{x}/{y}.{format}", **img_endpoint_params)
@self.router.get(r"/tiles/{z}/{x}/{y}@{scale}x", **img_endpoint_params)
@self.router.get(r"/tiles/{z}/{x}/{y}@{scale}x.{format}", **img_endpoint_params)
def tile_redirect(
z: Annotated[
int,
Path(
description="Identifier (Z) selecting one of the scales defined in the TileMatrixSet and representing the scaleDenominator the tile.",
),
],
x: Annotated[
int,
Path(
description="Column (X) index of the tile on the selected TileMatrix. It cannot exceed the MatrixHeight-1 for the selected TileMatrix.",
),
],
y: Annotated[
int,
Path(
description="Row (Y) index of the tile on the selected TileMatrix. It cannot exceed the MatrixWidth-1 for the selected TileMatrix.",
),
],
scale: Annotated[
int,
Field(
gt=0, le=4, description="Tile size scale. 1=256x256, 2=512x512..."
),
] = 1,
format: Annotated[
ImageType,
"Default will be automatically defined if the output image needs a mask (png) or not (jpeg).",
] = None,
):
route_params = {
"z": "{z}",
"x": "{x}",
"y": "{y}",
"scale": tile_scale,
"tileMatrixSetId": "WebMercatorQuad",
}
if format:
route_params["format"] = format.value
tiles_url = self.url_for(request, "tile", **route_params)
qs = [
(key, value)
for (key, value) in request.query_params._list
]
if qs:
tiles_url += f"?{urlencode(qs)}"
qs = [
(key, value)
for (key, value) in request.query_params._list
if key.lower() not in qs_key_to_remove
]
return RedirectResponse(tiles_url) |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
judsoncrouch-eog
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @judsoncrouch-eog
Sorry for the disagreement, we needed to remove the default TMS Id to match the OGC specification 🙁
You could create custom endpoint that redirect to the correct URL, but you'll need to write your own application. This could also be in a Middleware maybe.