@@ -187,10 +187,10 @@ class EndpointsFactory(metaclass=abc.ABCMeta):
187
187
188
188
def __post_init__ (self ):
189
189
"""Post Init: register route and configure specific options."""
190
- self .register_routes ()
191
190
if self .with_common :
192
- self ._conformance_route ()
193
191
self ._landing_route ()
192
+ self ._conformance_route ()
193
+ self .register_routes ()
194
194
195
195
def url_for (self , request : Request , name : str , ** path_params : Any ) -> str :
196
196
"""Return full url (with prefix) for a specific handler."""
@@ -1111,7 +1111,7 @@ def conforms_to(self) -> List[str]:
1111
1111
1112
1112
def links (self , request : Request ) -> List [model .Link ]:
1113
1113
"""OGC Tiles API links."""
1114
- return [
1114
+ links = [
1115
1115
model .Link (
1116
1116
title = "Collection Vector Tiles (Template URL)" ,
1117
1117
href = self .url_for (
@@ -1149,6 +1149,25 @@ def links(self, request: Request) -> List[model.Link]:
1149
1149
rel = "data" ,
1150
1150
templated = True ,
1151
1151
),
1152
+ ]
1153
+
1154
+ if self .with_viewer :
1155
+ links .append (
1156
+ model .Link (
1157
+ title = "Collection Map viewer (Template URL)" ,
1158
+ href = self .url_for (
1159
+ request ,
1160
+ "viewer_endpoint" ,
1161
+ collectionId = "{collectionId}" ,
1162
+ tileMatrixSetId = "{tileMatrixSetId}" ,
1163
+ ),
1164
+ type = MediaType .html ,
1165
+ rel = "data" ,
1166
+ templated = True ,
1167
+ )
1168
+ )
1169
+
1170
+ links += [
1152
1171
model .Link (
1153
1172
title = "TileMatrixSets" ,
1154
1173
href = self .url_for (
@@ -1171,6 +1190,8 @@ def links(self, request: Request) -> List[model.Link]:
1171
1190
),
1172
1191
]
1173
1192
1193
+ return links
1194
+
1174
1195
def register_routes (self ): # noqa: C901
1175
1196
"""Register OGC Tiles endpoints."""
1176
1197
self ._tilematrixsets_routes ()
@@ -1428,49 +1449,67 @@ async def collection_tileset(
1428
1449
for matrix in tms
1429
1450
]
1430
1451
1452
+ links = [
1453
+ {
1454
+ "href" : self .url_for (
1455
+ request ,
1456
+ "collection_tileset" ,
1457
+ collectionId = collection .id ,
1458
+ tileMatrixSetId = tileMatrixSetId ,
1459
+ ),
1460
+ "rel" : "self" ,
1461
+ "type" : "application/json" ,
1462
+ "title" : f"'{ collection .id } ' tileset tiled using { tileMatrixSetId } TileMatrixSet" ,
1463
+ },
1464
+ {
1465
+ "href" : self .url_for (
1466
+ request ,
1467
+ "tilematrixset" ,
1468
+ tileMatrixSetId = tileMatrixSetId ,
1469
+ ),
1470
+ "rel" : "http://www.opengis.net/def/rel/ogc/1.0/tiling-schemes" ,
1471
+ "type" : "application/json" ,
1472
+ "title" : f"Definition of '{ tileMatrixSetId } ' tileMatrixSet" ,
1473
+ },
1474
+ {
1475
+ "href" : self .url_for (
1476
+ request ,
1477
+ "collection_get_tile" ,
1478
+ tileMatrixSetId = tileMatrixSetId ,
1479
+ collectionId = collection .id ,
1480
+ z = "{z}" ,
1481
+ x = "{x}" ,
1482
+ y = "{y}" ,
1483
+ ),
1484
+ "rel" : "tile" ,
1485
+ "type" : "application/vnd.mapbox-vector-tile" ,
1486
+ "title" : "Templated link for retrieving Vector tiles" ,
1487
+ "templated" : True ,
1488
+ },
1489
+ ]
1490
+
1491
+ if self .with_viewer :
1492
+ links .append (
1493
+ {
1494
+ "href" : self .url_for (
1495
+ request ,
1496
+ "viewer_endpoint" ,
1497
+ tileMatrixSetId = tileMatrixSetId ,
1498
+ collectionId = collection .id ,
1499
+ ),
1500
+ "type" : "text/html" ,
1501
+ "rel" : "data" ,
1502
+ "title" : f"Map viewer for '{ tileMatrixSetId } ' tileMatrixSet" ,
1503
+ }
1504
+ )
1505
+
1431
1506
data = model .TileSet .model_validate (
1432
1507
{
1433
1508
"title" : f"'{ collection .id } ' tileset tiled using { tileMatrixSetId } TileMatrixSet" ,
1434
1509
"dataType" : "vector" ,
1435
1510
"crs" : tms .crs ,
1436
1511
"boundingBox" : collection_bbox ,
1437
- "links" : [
1438
- {
1439
- "href" : self .url_for (
1440
- request ,
1441
- "collection_tileset" ,
1442
- collectionId = collection .id ,
1443
- tileMatrixSetId = tileMatrixSetId ,
1444
- ),
1445
- "rel" : "self" ,
1446
- "type" : "application/json" ,
1447
- "title" : f"'{ collection .id } ' tileset tiled using { tileMatrixSetId } TileMatrixSet" ,
1448
- },
1449
- {
1450
- "href" : self .url_for (
1451
- request ,
1452
- "tilematrixset" ,
1453
- tileMatrixSetId = tileMatrixSetId ,
1454
- ),
1455
- "rel" : "http://www.opengis.net/def/rel/ogc/1.0/tiling-schemes" ,
1456
- "type" : "application/json" ,
1457
- "title" : f"Definition of '{ tileMatrixSetId } ' tileMatrixSet" ,
1458
- },
1459
- {
1460
- "href" : self .url_for (
1461
- request ,
1462
- "collection_get_tile" ,
1463
- tileMatrixSetId = tileMatrixSetId ,
1464
- collectionId = collection .id ,
1465
- z = "{z}" ,
1466
- x = "{x}" ,
1467
- y = "{y}" ,
1468
- ),
1469
- "rel" : "tile" ,
1470
- "type" : "application/vnd.mapbox-vector-tile" ,
1471
- "title" : "Templated link for retrieving Vector tiles" ,
1472
- },
1473
- ],
1512
+ "links" : links ,
1474
1513
"tileMatrixSetLimits" : tilematrix_limit ,
1475
1514
}
1476
1515
)
@@ -1499,6 +1538,7 @@ def _tile_routes(self):
1499
1538
responses = {200 : {"content" : {MediaType .mvt .value : {}}}},
1500
1539
operation_id = ".collection.vector.getTile" ,
1501
1540
tags = ["OGC Tiles API" ],
1541
+ deprecated = True ,
1502
1542
)
1503
1543
async def collection_get_tile (
1504
1544
request : Request ,
@@ -1582,6 +1622,7 @@ def _tilejson_routes(self):
1582
1622
response_class = ORJSONResponse ,
1583
1623
operation_id = ".collection.vector.getTileJSON" ,
1584
1624
tags = ["OGC Tiles API" ],
1625
+ deprecated = True ,
1585
1626
)
1586
1627
async def collection_tilejson (
1587
1628
request : Request ,
@@ -1683,6 +1724,7 @@ def _stylejson_routes(self):
1683
1724
response_class = ORJSONResponse ,
1684
1725
operation_id = ".collection.vector.getStyleJSON" ,
1685
1726
tags = ["OGC Tiles API" ],
1727
+ deprecated = True ,
1686
1728
)
1687
1729
async def collection_stylejson (
1688
1730
request : Request ,
@@ -1809,19 +1851,29 @@ async def collection_stylejson(
1809
1851
"/collections/{collectionId}/{tileMatrixSetId}/viewer" ,
1810
1852
response_class = HTMLResponse ,
1811
1853
operation_id = ".collection.vector.viewerTms" ,
1854
+ deprecated = True ,
1855
+ tags = ["Map Viewer" ],
1812
1856
)
1813
1857
@self .router .get (
1814
1858
"/collections/{collectionId}/viewer" ,
1815
1859
response_class = HTMLResponse ,
1816
1860
operation_id = ".collection.vector.viewer" ,
1861
+ deprecated = True ,
1862
+ tags = ["Map Viewer" ],
1863
+ )
1864
+ @self .router .get (
1865
+ "/collections/{collectionId}/tiles/{tileMatrixSetId}/viewer" ,
1866
+ response_class = HTMLResponse ,
1867
+ operation_id = ".collection.vector.map" ,
1868
+ tags = ["Map Viewer" ],
1817
1869
)
1818
1870
def viewer_endpoint (
1819
1871
request : Request ,
1820
1872
collection : Annotated [Collection , Depends (self .collection_dependency )],
1821
1873
tileMatrixSetId : Annotated [
1822
- Literal ["WebMercatorQuad" ],
1823
- "Identifier selecting one of the TileMatrixSetId supported (default: 'WebMercatorQuad ')" ,
1824
- ] = "WebMercatorQuad" ,
1874
+ Literal [tuple ( self . supported_tms . list ()) ],
1875
+ f "Identifier selecting one of the TileMatrixSetId supported (default: '{ tms_settings . default_tms } ')" ,
1876
+ ] = tms_settings . default_tms ,
1825
1877
minzoom : Annotated [
1826
1878
Optional [int ],
1827
1879
Query (description = "Overwrite default minzoom." ),
@@ -1839,7 +1891,7 @@ def viewer_endpoint(
1839
1891
] = None ,
1840
1892
):
1841
1893
"""Return Simple HTML Viewer for a collection."""
1842
- self .supported_tms .get (tileMatrixSetId )
1894
+ tms = self .supported_tms .get (tileMatrixSetId )
1843
1895
1844
1896
tilejson_url = self .url_for (
1845
1897
request ,
@@ -1850,13 +1902,16 @@ def viewer_endpoint(
1850
1902
if request .query_params ._list :
1851
1903
tilejson_url += f"?{ urlencode (request .query_params ._list )} "
1852
1904
1853
- return self .templates . TemplateResponse (
1905
+ return self ._create_html_response (
1854
1906
request ,
1855
- name = "map.html" ,
1856
- context = {
1907
+ {
1908
+ "title" : collection . id ,
1857
1909
"tilejson_endpoint" : tilejson_url ,
1910
+ "tms" : tms ,
1911
+ "resolutions" : [matrix .cellSize for matrix in tms ],
1858
1912
},
1859
- media_type = "text/html" ,
1913
+ template_name = "map" ,
1914
+ title = f"{ collection .id } viewer" ,
1860
1915
)
1861
1916
1862
1917
0 commit comments