+
+ + + +

Collection {{ response.title }}

+ +
+ + - - + + map.fitBounds(L.geoJSON(geo).getBounds()); + + let layer = Object.values(data.vector_layers)[0]; + let paintRules = [ + { + dataLayer: layer.id, + symbolizer: new protomapsL.LineSymbolizer({ + color:"#000000" + }), + minzoom: layer.minzoom, + maxzoom: layer.maxzoom + } + ] + + protomapsL.leafletLayer({url:data.tiles[0], paintRules:paintRules}).addTo(map); + }) + .catch(err => { + console.warn(err) + }) + + + +{% include "footer.html" %} From e40d1f1054f21b7b50e273741c599abb92483791 Mon Sep 17 00:00:00 2001 From: vincentsarago Date: Thu, 28 Mar 2024 12:27:38 +0100 Subject: [PATCH 2/3] fix tests --- tests/test_factories.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/test_factories.py b/tests/test_factories.py index 35dd4076..c23ec737 100644 --- a/tests/test_factories.py +++ b/tests/test_factories.py @@ -116,7 +116,7 @@ def test_tiles_factory(): endpoints = OGCTilesFactory() assert endpoints.with_common assert endpoints.title == "OGC API" - assert len(endpoints.router.routes) == 14 + assert len(endpoints.router.routes) == 15 assert len(endpoints.conforms_to) == 5 app = FastAPI() @@ -127,7 +127,7 @@ def test_tiles_factory(): assert response.headers["content-type"] == "application/json" assert response.json()["title"] == "OGC API" links = response.json()["links"] - assert len(links) == 9 # 5 from tiles + 4 from common + assert len(links) == 10 # 6 from tiles + 4 from common landing_link = [link for link in links if link["title"] == "Landing Page"][0] assert landing_link["href"] == "http://testserver/" tms_link = [link for link in links if link["title"] == "TileMatrixSets"][0] @@ -150,7 +150,7 @@ def test_tiles_factory(): assert endpoints.router_prefix == "/map" assert endpoints.with_common assert endpoints.title == "OGC Tiles API" - assert len(endpoints.router.routes) == 14 + assert len(endpoints.router.routes) == 15 app = FastAPI() app.include_router(endpoints.router, prefix="/map") @@ -160,7 +160,7 @@ def test_tiles_factory(): assert response.headers["content-type"] == "application/json" assert response.json()["title"] == "OGC Tiles API" links = response.json()["links"] - assert len(links) == 9 + assert len(links) == 10 landing_link = [link for link in links if link["title"] == "Landing Page"][0] assert landing_link["href"] == "http://testserver/map/" tms_link = [link for link in links if link["title"] == "TileMatrixSets"][0] @@ -180,7 +180,7 @@ def test_tiles_factory(): endpoints = OGCTilesFactory(title="OGC Tiles API", with_common=False) assert not endpoints.with_common assert endpoints.title == "OGC Tiles API" - assert len(endpoints.router.routes) == 12 + assert len(endpoints.router.routes) == 13 assert len(endpoints.conforms_to) == 5 app = FastAPI() @@ -203,7 +203,7 @@ def test_endpoints_factory(): endpoints = Endpoints() assert endpoints.with_common assert endpoints.title == "OGC API" - assert len(endpoints.router.routes) == 19 + assert len(endpoints.router.routes) == 20 assert len(endpoints.conforms_to) == 11 # 5 from tiles + 6 from features app = FastAPI() @@ -214,7 +214,7 @@ def test_endpoints_factory(): assert response.headers["content-type"] == "application/json" assert response.json()["title"] == "OGC API" links = response.json()["links"] - assert len(links) == 14 # 5 from tiles + 5 from features + 4 from common + assert len(links) == 15 # 6 from tiles + 5 from features + 4 from common landing_link = [link for link in links if link["title"] == "Landing Page"][0] assert landing_link["href"] == "http://testserver/" queryables_link = [ @@ -237,14 +237,14 @@ def test_endpoints_factory(): assert response.status_code == 200 assert response.headers["content-type"] == "application/json" body = response.json()["conformsTo"] - assert len(body) > 10 # 4 from tiles + 6 from features + assert len(body) > 9 # 3 from tiles + 6 from features assert "http://www.opengis.net/spec/ogcapi-common-1/1.0/conf/core" in body endpoints = Endpoints(router_prefix="/ogc", title="OGC Full API", with_common=True) assert endpoints.router_prefix == "/ogc" assert endpoints.with_common assert endpoints.title == "OGC Full API" - assert len(endpoints.router.routes) == 19 + assert len(endpoints.router.routes) == 20 assert not endpoints.ogc_features.with_common assert endpoints.ogc_features.router_prefix == "/ogc" assert not endpoints.ogc_tiles.with_common @@ -258,7 +258,7 @@ def test_endpoints_factory(): assert response.headers["content-type"] == "application/json" assert response.json()["title"] == "OGC Full API" links = response.json()["links"] - assert len(links) == 14 + assert len(links) == 15 landing_link = [link for link in links if link["title"] == "Landing Page"][0] assert landing_link["href"] == "http://testserver/ogc/" queryables_link = [ @@ -288,7 +288,7 @@ def test_endpoints_factory(): endpoints = Endpoints(title="Tiles and Features API", with_common=False) assert not endpoints.with_common assert endpoints.title == "Tiles and Features API" - assert len(endpoints.router.routes) == 17 # 10 from tiles + 5 from features + assert len(endpoints.router.routes) == 18 # 11 from tiles + 5 from features assert len(endpoints.conforms_to) == 11 # 4 from tiles + 6 from features app = FastAPI() From f93d777317e2bad92856aa5354ca562c6122250b Mon Sep 17 00:00:00 2001 From: vincentsarago Date: Fri, 29 Mar 2024 17:21:57 +0100 Subject: [PATCH 3/3] simplify --- tipg/factory.py | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/tipg/factory.py b/tipg/factory.py index aa7be8f4..de7efa73 100644 --- a/tipg/factory.py +++ b/tipg/factory.py @@ -40,12 +40,11 @@ from fastapi import APIRouter, Depends, Path, Query from fastapi.responses import ORJSONResponse -from fastapi.routing import APIRoute from starlette.datastructures import QueryParams from starlette.requests import Request from starlette.responses import HTMLResponse, Response, StreamingResponse -from starlette.routing import Match, compile_path, replace_params +from starlette.routing import compile_path, replace_params from starlette.templating import Jinja2Templates, _TemplateResponse tms_settings = TMSSettings() @@ -211,17 +210,6 @@ def url_for(self, request: Request, name: str, **path_params: Any) -> str: return str(url_path.make_absolute_url(base_url=base_url)) - def find_route(self, path: str, method: str = "GET") -> Optional[APIRoute]: - """find route from scope.""" - for route in self.router.routes: - match, _ = route.matches({"type": "http", "path": path, "method": method}) - if match != Match.FULL: - continue - - return route - - return None - def _create_html_response( self, request: Request, @@ -1500,14 +1488,12 @@ async def collection_tileset( }, ] - if route := self.find_route( - f"/collections/{collection.id}/tiles/{tileMatrixSetId}/viewer" - ): + if self.with_viewer: links.append( { "href": self.url_for( request, - route.name, + "viewer_endpoint", tileMatrixSetId=tileMatrixSetId, collectionId=collection.id, ), @@ -1925,6 +1911,7 @@ def viewer_endpoint( "resolutions": [matrix.cellSize for matrix in tms], }, template_name="map", + title=f"{collection.id} viewer", )