1

I have a large polygon dataset in PostGIS I would like to display in Leaflet map. I understand st_asmvt() query will return mapbox vector tiles. I can successfully query the data in postgis but I dont know how to display the results as vector tile layer in leaflet.

Research has lead me to think I should use the leafletvectorgrid plugin. Which allows me to display pbf data. How do I construct this url to render the results of my query?

\\my best guess for a local pbf tile url
var pbfTileUrl = "https://localhost/tiles/{z}/{x}/{y}.vector.pbf?";
var pbfTileLayer = L.vectorGrid.protobuf(pbfTileUrl);

The query below returns bytea result.

SELECT ST_AsMVT(q, 'small_areas', 4096, 'geom')
FROM (
  SELECT ogc_fid, edname, small_area,
    ST_AsMvtGeom(
      wkb_geometry,
      --xmin, ymin, xmax, ymax, srid
      --_northEast: o.LatLng {lat: 51.900647154116314, lng: -8.291244506835938}
      --_southWest: o.LatLng {lat: 51.89217277879109, lng: -8.625640869140625}`
      ST_MakeEnvelope(-8.625640,51.892172,-8.291244,51.900647, 4326 )
    ) AS geom
  FROM small_areas
  WHERE wkb_geometry && ST_MakeEnvelope(-8.625640,51.892172,-8.291244,51.900647, 4326 )
  AND ST_Intersects(wkb_geometry, ST_MakeEnvelope(-8.625640,51.892172,-8.291244,51.900647, 4326 ))
) AS q;

How do I pass these results to leaflet?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.