99import numpy
1010import rasterio
1111import uvicorn
12- from fastapi import APIRouter , FastAPI , Query
12+ from fastapi import APIRouter , FastAPI , Path , Query
1313from fastapi .staticfiles import StaticFiles
1414from rasterio import windows
1515from rasterio ._path import _parse_path as parse_path
2020from starlette .requests import Request
2121from starlette .responses import HTMLResponse , Response
2222from starlette .templating import Jinja2Templates
23+ from typing_extensions import Annotated
2324
2425from tilebench import Timer
2526from tilebench import profile as profiler
@@ -149,10 +150,31 @@ def register_routes(self):
149150 """Register routes to the FastAPI app."""
150151
151152 @self .router .get (r"/tiles/{z}/{x}/{y}.png" , response_class = PNGResponse )
152- def image (response : Response , z : int , x : int , y : int ):
153+ def image (
154+ response : Response ,
155+ z : Annotated [
156+ int ,
157+ Path (
158+ description = "Identifier (Z) selecting one of the scales defined in the TileMatrixSet and representing the scaleDenominator the tile." ,
159+ ),
160+ ],
161+ x : Annotated [
162+ int ,
163+ Path (
164+ description = "Column (X) index of the tile on the selected TileMatrix. It cannot exceed the MatrixHeight-1 for the selected TileMatrix." ,
165+ ),
166+ ],
167+ y : Annotated [
168+ int ,
169+ Path (
170+ description = "Row (Y) index of the tile on the selected TileMatrix. It cannot exceed the MatrixWidth-1 for the selected TileMatrix." ,
171+ ),
172+ ],
173+ ):
153174 """Handle /image requests."""
154175 with self .reader (self .src_path ) as src_dst :
155176 img = src_dst .tile (x , y , z )
177+
156178 return PNGResponse (
157179 render (
158180 numpy .zeros ((1 , 256 , 256 ), dtype = "uint8" ),
@@ -163,7 +185,27 @@ def image(response: Response, z: int, x: int, y: int):
163185 )
164186
165187 @self .router .get (r"/tiles/{z}/{x}/{y}" )
166- def tile (response : Response , z : int , x : int , y : int ):
188+ def tile (
189+ response : Response ,
190+ z : Annotated [
191+ int ,
192+ Path (
193+ description = "Identifier (Z) selecting one of the scales defined in the TileMatrixSet and representing the scaleDenominator the tile." ,
194+ ),
195+ ],
196+ x : Annotated [
197+ int ,
198+ Path (
199+ description = "Column (X) index of the tile on the selected TileMatrix. It cannot exceed the MatrixHeight-1 for the selected TileMatrix." ,
200+ ),
201+ ],
202+ y : Annotated [
203+ int ,
204+ Path (
205+ description = "Row (Y) index of the tile on the selected TileMatrix. It cannot exceed the MatrixWidth-1 for the selected TileMatrix." ,
206+ ),
207+ ],
208+ ):
167209 """Handle /tiles requests."""
168210
169211 @profiler (
@@ -272,7 +314,7 @@ def info():
272314 response_model_exclude_none = True ,
273315 response_class = GeoJSONResponse ,
274316 )
275- def grid (ovr_level : int = Query (...) ):
317+ def grid (ovr_level : Annotated [ int , Query (description = "Overview Level" )] ):
276318 """return geojson."""
277319 options = {"OVERVIEW_LEVEL" : ovr_level - 1 } if ovr_level else {}
278320 with rasterio .open (self .src_path , ** options ) as src_dst :
0 commit comments