Rohit  Sthapit
Rohit Sthapit

Reputation: 474

mvt vector tiles on showing on MapboxGL

I followed https://medium.com/@mrgrantanderson/https-medium-com-serving-vector-tiles-from-django-38c705f6

to serve the mvt tiles to the mapbox from geoDjango.

With running query

   cursor.execute("SELECT ST_AsMVT(tile) FROM (SELECT osm_id, building, ST_AsMVTGeom(geom, TileBBox(%s, %s, %s, 3857)) FROM  nepal_khokanabuildings ) AS tile", [zoom, x, y])

as my model project is ESPG:3857

The Vectors don't seem to load up on the map, the api request is working fine. I also tried serving vector files from Geoserver no luck either.

Here is my JS File

var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/light-v10',
zoom: 12,

    center: [85.294688,27.634106],

});
    var mapillarySource = {
      type: 'vector',
      tiles: [
       'http://0.0.0.0:8000/nepal/api/v1/data/nepal/{z}/{x}/{y}.mvt'
        ],
      minzoom: 0,
      maxzoom: 14
  };

map.on('load', function() {

  map.addSource('mapillary', mapillarySource);
  map.addLayer({
      'id': 'mapillary',
      'type': 'fill',
      'source': 'mapillary',
      'source-layer': 'water',
      'paint': {
                "fill-color": "#00ffff"

      }
  });
});
map.addControl(new mapboxgl.NavigationControl());
</script>

Upvotes: 0

Views: 1641

Answers (2)

sumit
sumit

Reputation: 129

Use Following ,

"id": "postgis-tiles-layer",
"source-layer": "default",

Upvotes: 0

Steve Bennett
Steve Bennett

Reputation: 126105

There are lots of problems that can manifest themselves as "my layers don't show".

You can check each of these things:

  • is the layer being created before the map is ready? (wait for "load" event)
  • are the correct tile requests being generated?
  • are those requests succeeding?
  • are they returning actual .pbf files?
  • do they contain data in the right location, and in the right projection?
  • do they contain a layer with the name you expect? ('water' in this case)
  • do they contain data of the type you expect? (polygons in this case)

I am curious about the 0.0.0.0 host, but also suspect that the layer name may not be right.

If your tile requests are succeeding, you can try using https://stevage.github.io/vector-inspector/ to inspect them, although you may have issues with that page being served on HTTPS and your local tiles being on HTTP.

Upvotes: 1

Related Questions