Openlayers doesn't seem to support the URL that Carto prefers for getting UTF Grids.
import TileLayer from 'ol/layer/Tile';
import UTFGrid from 'ol/source/UTFGrid';
const newUTFLayer = new TileLayer({
source: new UTFGrid({
url: 'https://PATH.TO.CARTO/LAYERGROUP_ID/0/{z}/{x}/{y}.grid.json';
})
});
I get the error
"errors":["Invalid coordinates: NaN/NaN/NaN"],"errors_with_context":[{"type":"unknown","message":"Invalid coordinates: NaN/NaN/NaN"}]}
Clearly Openlayers isn't replacing {z}/{x}/{y}
with coordinates.
In the official example of using a UTF grid, they seem to be requesting some kind of config from Mapbox to get a UTF grid, but Carto seems to use a different mechanism?
-
Edit: I've found some additional information from people having similar problems to me:
It seems the issue is that OpenLayers' UTFGrid source is trying to request a TileJSON file (which I believe is a metadata file?) rather than the individual UTF grid tiles themselves.
Frustrating that there needs to be a server-side component to solve it using the aforementioned work-around.
Edit 2: The OpenLayers UTFGrid spec seems to allow you to set a tileJson
object, can I use this to get around having to request a TileJson file?