I'm serving up a data from PostGIS by converting it into a tile and then bytes and then onto a leaflet map. It all works, with one exception, the latitudes stretch ever greater towards the poles when zoomed out, but this effect disappears when zooming in. Both pink and blue lines are from the same data set.
When zoomed in the dataset come together/align suggesting there isn't a problem with the initial dataset.
When zooming out to levels of 5 and below the tiles produced seem to distort and stretch ever more towards the poles. The tiles near the equator are effected a lot less.
This is the code python that is used to produce the tiles from the server:
#def tile_ul(x, y, z):
n = 2.0 ** z
lon_deg = x / n * 360.0 - 180.0
lat_rad = arctan(sinh(pi * (1 - 2 * y / n)))
lat_deg = degrees(lat_rad)
return lon_deg,lat_deg
############################################################
def get_tile(z,x,y):
xmin, ymin = tile_ul(x, y, z)
xmax, ymax = tile_ul(x + 1, y + 1, z)
query = """SELECT ST_AsMVT(tile) FROM (
SELECT id, ST_AsMVTGeom(geom, ST_MakeEnvelope( %s, %s, %s, %s ,4326), 4096, 256, false ) geom
FROM seaarea ) as tile"""
cursor = db.connection.cursor()
cursor.execute(query,(xmin,ymin,xmax,ymax))
tile = bytes(cursor.fetchone()[0])
cursor.close()
return tile
the client code which is used before adding the tile layer to a leaflet map:
var url = "http://localhost:5000/tiles/{z}/{x}/{y}"
var mapillaryLayer = L.vectorGrid.protobuf(url, {vectorTileLayerStyles: {
fillColor: 'red'}}).addTo(mymap);
I believe the issue may lay in the PostGIS query or possibly the bounds created for the tiles when at low zoom levels. A similar issue is report here
Any suggestions on how to make the tiles not distort at low zoom levels?
Stay Safe All.