Geoserver – Finding Layer Names Within Vector Tiles Without TileJSON

geoservermapboxvector-tileswmts

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

Best Answer

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