-1

Background

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.

enter image description here

Setup

Server

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

Client

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/

SOK
  • 515
  • 6
  • 21
  • 2
    With a non-EPSG:3857 grid you need to specify the projection in the VectorTile source options, otherwise it uses an EPSG:3857 grid (version 6.5.0 will throw an assertion if you don't). If the extent is not square you will probably also need to specify `maxResolution` (the resolution at level 0). See example here https://jsfiddle.net/3ogf4u1j/1/ – Mike May 29 '21 at 11:09

1 Answers1

0

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));

SOK
  • 515
  • 6
  • 21