Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - guoke888

#1
Hi there,

It would be great for online map to support pbf vector tiles.


Here is an example:


  <onlinemapsource uid="1">
    <name>MapBox</name>
    <url><![CDATA[https://api.mapbox.com/v4/alltrails.osm_segments,alltrails.ahx8exyx,mapbox.mapbox-streets-v8,alltrails.86sfqzu9,alltrails.6ejp62vc,alltrails.2a54nuiz,alltrails.5xfhqyuo,alltrails.dpxqqqh6,mapbox.mapbox-terrain-v2,alltrails.park-areas-production,alltrails.park-centerpoints-production/{$z}/{$x}/{$y}.vector.pbf?sku=101jwaSDi9aEs&access_token=pk.eyJ1IjoiYWxsdHJhaWxzIiwiYSI6ImNqM293emo1YjAwZWQyd3FnaXh0eWsxeHkifQ.LeDD0X-JiWsJmDKeB0AS5w]]></url>
    <minzoom>13</minzoom>
    <maxzoom>16</maxzoom>
    <projection>MERCATORESFERICA</projection>
    <servers></servers>
    <httpparam name="User-Agent">Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36</httpparam>
    <cacheable>1</cacheable>
    <downloadable>1</downloadable>
    <maxtilesday>0</maxtilesday>
    <maxthreads>0</maxthreads>
    <xop></xop>
    <yop></yop>
    <zop></zop>
    <qop></qop>
    <sop></sop>
  </onlinemapsource>


Note the tiles served by this map source are gzip compressed protobuf files.
So you need to gunzip it first, then you can decode it with `protoc --decode` using https://github.com/mapbox/vector-tile-spec/blob/master/2.1/vector_tile.proto.

Example 1:

#### Download the file
$ curl -X GET "https://api.mapbox.com/v4/alltrails.osm_segments,alltrails.ahx8exyx,mapbox.mapbox-streets-v8,alltrails.86sfqzu9,alltrails.6ejp62vc,alltrails.2a54nuiz,alltrails.5xfhqyuo,alltrails.dpxqqqh6,mapbox.mapbox-terrain-v2,alltrails.park-areas-production,alltrails.park-centerpoints-production/14/2721/6303.vector.pbf?sku=101jwaSDi9aEs&access_token=pk.eyJ1IjoiYWxsdHJhaWxzIiwiYSI6ImNqM293emo1YjAwZWQyd3FnaXh0eWsxeHkifQ.LeDD0X-JiWsJmDKeB0AS5w" > 6303.pbf.gz
$ file 6303.pbf.gz
6303.pbf.gz: gzip compressed data, from Unix, original size modulo 2^32 21648

#### We can unzip it
$ gunzip 6303.pbf.gz
$ ls -l
total 16
-rw-rw-r-- 1 user user 21648 Jun 18 01:57 6303.pbf

#### Now download the vector_tile.proto file from https://github.com/mapbox/vector-tile-spec repo
$ git clone https://github.com/mapbox/vector-tile-spec.git
$ ls -l vector-tile-spec/2.1/vector_tile.proto
-rw-rw-r-- 1 user user 2860 Jun 18 01:54 vector-tile-spec/2.1/vector_tile.proto

#### Now we can use protoc to decode it
$ cat 6303.pbf | protoc -I vector-tile-spec/2.1/ vector_tile.proto --decode vector_tile.Tile
[libprotobuf WARNING ../../../../../src/google/protobuf/compiler/parser.cc:649] No syntax specified for the proto file: vector_tile.proto. Please use 'syntax = "proto2";' or 'syntax = "proto3";' to specify a syntax version. (Defaulted to proto2 syntax.)
.
.
.
  extent: 4096
  version: 2
}


This doc should be helpful: https://docs.mapbox.com/data/tilesets/guides/vector-tiles-standards/


Here is another example:

<onlinemapsource uid="2">
    <name>MapTiler.com</name>
    <url><![CDATA[https://api.maptiler.com/tiles/v3/{$z}/{$x}/{$y}.pbf?key=eIgS48TpQ70m77qKYrsx&mtsid=402d4247-0a2e-4a5e-9e5c-f8000a15eabf]]></url>
    <minzoom>0</minzoom>
    <maxzoom>15</maxzoom>
    <projection>MERCATORESFERICA</projection>
    <servers>1</servers>
    <httpparam name="User-Agent">Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36</httpparam>
    <httpparam name="Referer">https://www.maptiler.com/</httpparam>
    <cacheable>1</cacheable>
    <downloadable>1</downloadable>
    <maxtilesday>0</maxtilesday>
    <maxthreads>0</maxthreads>
    <xop></xop>
    <yop></yop>
    <zop></zop>
    <qop></qop>
    <sop></sop>
  </onlinemapsource>


Note map tiles served by this map source are not gzip compressed. So no need to gunzip.

Thanks!