2

I'm trying to use an endpoint in Mapbox vector tile format. I can access the .pbf's ok, but there's no documentation or TileJSON endpoint.

How can I find the names of layers that exist within the tiles? That is, the value that I would set to source-layer in a vector source in Mapbox-GL-JS.

Theoretically this must be doable, but I don't know any tool that lets me achieve this.

(In this particular case, it's a WMTS endpoint on GeoServer, but I'd be more interested in solutions that work generally.)

4

If you're okay to write a NodeJS script you can use

const request = require('request');
const VectorTile = require('@mapbox/vector-tile').VectorTile;
const Pbf = require('pbf');
const zlib = require('zlib');

request({
    url: 'https://example.com/1/2/3.pbf',
    encoding: null

}, (err, response, body) => {
    try {
         body = zlib.gunzipSync(body);
    } catch (e) {

    }
    const tile = new VectorTile(new Pbf(body));
    console.log('Vector source layers found: ', Object.keys(tile.layers).join(', '))
})

https://github.com/mapbox/vector-tile-js#api-reference

Try this on Runkit: https://runkit.com/stevebennett/get-layer-names-and-keys-from-vector-tile

  • Awesome, that worked with a couple of tweaks. It seems unzipping of the body is supported automatically by Request, so removed that. – Steve Bennett Jun 27 '18 at 5:32
  • Ok, too hasty. Updated version works with both gzipped and non-gzipped sources. Maybe the gzip is at lower level. Who knows. – Steve Bennett Jun 27 '18 at 5:45
  • Maybe it depends if the HTTP response includes the right headers or not. – AndrewHarvey Jun 27 '18 at 9:36
  • 1
    I've made a runkit version of this here: runkit.com/stevebennett/… – Steve Bennett Jul 19 '18 at 1:54
1

Using Andrew's code above, I've now made a website to solve this problem:

http://stevage.github.io/vector-inspector

Just paste the URL of any tile, and it lists the names of the layers and their attributes.

  • Perfect, only thing is if you can wrote something, easy reusable. input parameter is http://.....pbf, output is json as { layer1:xxx, layer2:yyy etc.....} – hoogw Jun 10 at 17:47
  • can you make a rest service? stevage.github.io/vector-inspector?pbf=http://xxx....pbf, then response as {[layer1, layer2, layer3...etc.]} – hoogw Jun 10 at 18:03

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.