mapbox / vector-tile-spec

Mapbox Vector Tile specification
https://www.mapbox.com/vector-tiles/specification/
Other
890 stars 209 forks source link

How should I interpret the keys/values of a vector tile? #156

Closed lorenzoMezza closed 3 months ago

lorenzoMezza commented 3 months ago

I am working on a map renderer in JavaScript, and I need to render vector tiles. For this task, I need to know, for example, which kind of transportation layer (road) I am rendering. Is it a highway, a pedestrian path, or a rail? This is necessary to correctly distinguish which ones to render and which not to render and how to render.

I am serving the map with OpenMapTiles, using nothing more than ./quickstart.sh and make start-postserve.

With JavaScript, I receive the PBF data and convert it into an appropriate format that gives me a layer containing several pieces of information about it. However, I cannot understand how to correctly interpret the keys/values information about the layer, particularly for the transportation layer.

Here is what I've done:

if (layer.name === "transportation") {
    let index = layer.keys.indexOf("class");
    if (layer.values[index].stringValue === 'transit') {
        geometry = this.parseGeometry(feature.geometry);
        this.renderLine(geometry, scale);
    }
}

These are the details about the layer that I receive:


keys: Array(18)
  0 : "class"
  1 : "subclass"
  2 : "network"
  3 : "oneway"
  4 : "ramp"
  5 : "brunnel"
  6 : "service"
  7 : "access"
  8 : "toll"
  9 : "expressway"
  10 : "layer"
  11 : "level"
  12 : "indoor"
  13 : "bicycle"
  14 : "foot"
  15 : "horse"
  16 : "mtb_scale"
  17 : "surface"

values: Array(7)
  0 : Value {stringValue: 'rail'}
  1 : Value {stringValue: 'tunnel'}
  2 : Value {sintValue: -2}
  3 : Value {stringValue: 'minor'}
  4 : Value {stringValue: 'no'}
  5 : Value {uintValue: 1}
  6 : Value {stringValue: 'tertiary'}

They seem nonsensical and somewhat redundant to me, and I am unable to use those data. I was assuming that the keys array references each index in the values array, but that appears to be false. For example, if I want to know if the transportation class is rail, I should check the index 0 of the values, but that doesn't seem to be related. I would appreciate any hints on this matter.

e-n-f commented 3 months ago

@lorenzoMezza Which keys and values from the layer are relevant to each feature are spelled out in the tags field of the feature, which alternates key references and value references.