vector-tile-query allows you to query Mapbox Vector Tiles and return data values from these tiles. This module consists of one main function, and two utility / helper functions.
Parses a Vector Tile protobuf and queries a layer for a a number of fields based on a series of lat, lngs points
pbuf
: vector tile (pbuf
)tileInfo
: tile Z,X,Y ('tileinfo: {z:,x:,y:}')queryPoints
:array
oflat, lngs
s ([[lat,lng],[lat,lng]...]
)pointIDs
:array
of point IDs that correspond to order of querylat,lng
s ([0,1,2...]
)options
: options for query:layer
: layer within the tile source to query. Example:contour
fields
:array
of fields within the layer to return data for. Example [ele
]interpolate
(optional): whether or not to interpolate between closest two features. Examplefalse
. Defaulttrue
callback
:function(err,data) {...}
to call upon completion of query
Array (with one record per input lat,lng
) of values:
[
{
id: <id>,
latlng: { lat: <lat>, lng: <lng> },
<field1>: <field1 value>,
<field2>: <field2 value>
},
...
]
Given a set of lat,lng
points and a zoom level, finds what tiles to load, loads these tiles asynchronously (using a defined function), splits query lat, lngs
s out per tile, and assigns these a sequential ID (based on input order)
queryPoints
:array
oflat, lngs
s ([[lat,lng],[lat,lng]...]
)zoom
: zoom level of tiles to queryloadFunction
: function to load tiles / should return apbuf
callback
:function(err,data) {...}
to call upon completion
Array of "tile objects" with tile zxy, query points within that tile, ids of these points, and vector tile pbufs.
[
{
zxy: { z: <z>, x: <x>, y: <y> },
points: [ [lat,lng], [lat,lng], ... ],
pointIDs: [ 0, 1, ... ],
data: <vtile pbuf>
}
...
]
Helper function to asynchronously query (using queryTile
(given a set of "tile objects") and return sorted values (based on input order / input point ids).
dataArr
:array
of "tileObjects" as described above - one record for each tile that will be queriedoptions
:options
as described above inqueryTile
callback
:function(err,data) {...}
to call upon completion
Array (with one record per input lat,lng
) of values:
[
{
id: <id>,
latlng: { lat: <lat>, lng: <lng> },
<field1>: <field1 value>,
<field2>: <field2 value>
},
...
]
git clone https://github.com/mapbox/vector-tile-query.git
npm install