Description
OpenLayers OGCVectorTile expects a "type" property in the links returned by pygeoapi. It is currently getting "type_" which causes an error when attempting to load vector tiles.
Steps to Reproduce
Added a postgres tile provider (MVT-postgresql) for a vector dataset and then attempted to load the tiles within openlayers using OGCVectorTile .
Expected behavior
Layer loads on the map as expected.
Screenshots/Tracebacks
In the console, this error looks like:
Error: Could not find "item" link
getVectorTileUrlTemplate ogcTileUtil.js:242
parseTileSetMetadata ogcTileUtil.js:456
getTileSetInfo ogcTileUtil.js:503
promise callback*getTileSetInfo ogcTileUtil.js:502
OGCVectorTile OGCVectorTile.js:84
Going to the server and looking at the response for a mvt query, it includes this:
{
"rel": "item",
"type_": "application/vnd.mapbox-vector-tile", // ← should be "type"
"href": ".../tiles/WebMercatorQuad/{tileMatrix}/{tileRow}/{tileCol}?f=mvt"
}
Tracing this back,
pygeoapi/provider/mvt_postgresql.py, line 250-252:
service_url_link = LinkType(href=service_url, rel='item',
type_=service_url_link_type,
title=service_url_link_title)
and pygeoapi/models/provider/base.py line 153-159
I understand that type_ is being used as type is a reserved word. I had initially made a workaround on the front end whereas I reconstructed the url and just used the generic vector tiles type in OpenLayers however I would prefer if this worked properly so I changed the LinkType base model to use a pydantic alias:
from pydantic import BaseModel, Field
class LinkType(BaseModel):
type_: Optional[str] = Field(None, alias='type', serialization_alias='type')
Then I also changed to return by alias: pygeoapi/provider/mvt_postgresql.py and the get_default_metadata function:
return content.model_dump(exclude_none=True, by_alias=True)
This fixed it. However, all of the mvt get_default_metadata functions would need to be updated.
Environment
- OS: Windows
- Python version: 3.14.4
- pygeoapi version: master
Description
OpenLayers OGCVectorTile expects a "type" property in the links returned by pygeoapi. It is currently getting "type_" which causes an error when attempting to load vector tiles.
Steps to Reproduce
Added a postgres tile provider (MVT-postgresql) for a vector dataset and then attempted to load the tiles within openlayers using OGCVectorTile .
Expected behavior
Layer loads on the map as expected.
Screenshots/Tracebacks
In the console, this error looks like:
Going to the server and looking at the response for a mvt query, it includes this:
Tracing this back,
and pygeoapi/models/provider/base.py line 153-159
I understand that type_ is being used as type is a reserved word. I had initially made a workaround on the front end whereas I reconstructed the url and just used the generic vector tiles type in OpenLayers however I would prefer if this worked properly so I changed the LinkType base model to use a pydantic alias:
Then I also changed to return by alias: pygeoapi/provider/mvt_postgresql.py and the get_default_metadata function:
return content.model_dump(exclude_none=True, by_alias=True)This fixed it. However, all of the mvt get_default_metadata functions would need to be updated.
Environment