I have been playing around with vector tiles (for the first time) and I have been stuck on an issue regarding the projection of the data. The Vector Tiles doesn't align perfectly with the background map (Projection issue?). The vector tile data seems to be in the correct size when comparing it to the background map but is located slightly off.
I have created my own simple MVT endpoint via PostGIS where instead of returning the data in EPSG:3857
I'm using EPSG:25832
with my own bounding box (Because the data I am showing on the client is already in EPSG:25832
.
WITH
bounds(geometry) AS (SELECT ST_TileEnvelope(@Z, @X, @Y, ST_MakeEnvelope(120000, 5900000, 1000000, 6500000, 25832))),
geometry AS (...),
mvtgeom AS (SELECT ST_AsMVTGeom(ST_Transform(geom, 25832), bounds.geometry, 4096, 256, true) FROM geometry, bounds)
SELECT ST_AsMVT(mvtgeom.*) FROM mvtgeom
I created a simple client to demonstrate the issue (Please note that the vector tiles layer points to localhost).
Openlayer Client via VueLayer - https://jsfiddle.net/z4a65d9L/
Solution
The problem has that the bound was not a perfect square which created the offset.
I used PostGIS to create a new bound and used that instead which solved my problem
SELECT ST_ASTEXT(ST_Expand(ST_SetSRID( ST_Point(560000, 6200000), 25832), 370000));