A VectorGrid
for vector tiles fetched from the internet.
Tiles are supposed to be protobufs (AKA "protobuffer" or "Protocol Buffers"),
containing data which complies with the
MapBox Vector Tile Specification.
This is the format used by:
You must initialize a VectorGrid.Protobuf
with a URL template, just like in
L.TileLayer
s. The difference is that the template must point to vector tiles
(usually .pbf
or .mvt
) instead of raster (.png
or .jpg
) tiles, and that
you should define the styling for all the features.
For OpenMapTiles, with a key from https://openmaptiles.org/docs/host/use-cdn/,
initialization looks like this:
L.vectorGrid.protobuf("https://free-{s}.tilehosting.com/data/v3/{z}/{x}/{y}.pbf.pict?key={key}", {
vectorTileLayerStyles: { ... },
subdomains: "0123",
key: 'abcdefghi01234567890',
maxNativeZoom: 14
}).addTo(map);
And for Mapbox vector tiles, it looks like this:
L.vectorGrid.protobuf("https://{s}.tiles.mapbox.com/v4/mapbox.mapbox-streets-v6/{z}/{x}/{y}.vector.pbf?access_token={token}", {
vectorTileLayerStyles: { ... },
subdomains: "abcd",
token: "pk.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRTS.TUVWXTZ0123456789abcde"
}).addTo(map);
Factory | Description |
---|---|
L.vectorGrid.protobuf( |
Instantiates a new protobuf VectorGrid with the given URL template and options |
Option | Type | Default | Description |
---|---|---|---|
subdomains |
String
| 'abc' |
Akin to the subdomains option for L.TileLayer . |
fetchOptions |
Object
| {} |
options passed to fetch , e.g. {credentials: 'same-origin'} to send cookie for the current domain |
Method | Returns | Description |
---|---|---|
setUrl( |
this |
Updates the layer's URL template and redraws it (unless |
A VectorGrid
for slicing up big GeoJSON or TopoJSON documents in vector
tiles, leveraging geojson-vt
.
var geoJsonDocument = {
type: 'FeatureCollection',
features: [ ... ]
};
L.vectorGrid.slicer(geoJsonDocument, {
vectorTileLayerStyles: {
sliced: { ... }
}
}).addTo(map);
VectorGrid.Slicer
can also handle TopoJSON transparently:
var layer = L.vectorGrid.slicer(topojson, options);
The TopoJSON format implicitly groups features into "objects".
These will be transformed into vector tile layer names when styling (the
vectorTileLayerName
option is ignored when using TopoJSON).
VectorGrid.Slicer
can take in any
of the geojson-vt
options.Option | Type | Default | Description |
---|---|---|---|
vectorTileLayerName |
String
| 'sliced' |
Vector tiles contain a set of data layers, and those data layers contain features. Thus, the slicer creates one data layer, with the name given in this option. This is important for symbolizing the data. |
A VectorGrid
is a generic, abstract class for displaying tiled vector data.
it provides facilities for symbolizing and rendering the data in the vector
tiles, but lacks the functionality to fetch the vector tiles from wherever
they are.
Extends Leaflet's L.GridLayer
.
Option | Type | Default | Description |
---|---|---|---|
rendererFactory |
| L.svg.tile |
A factory method which will be used to instantiate the per-tile renderers. |
vectorTileLayerStyles |
Object
| {} |
A data structure holding initial symbolizer definitions for the vector features. |
interactive |
Boolean
| false |
Whether this VectorGrid fires Interactive Layer events. |
getFeatureId |
Function
| undefined |
A function that, given a vector feature, returns an unique identifier for it, e.g.
function(feat) { return feat.properties.uniqueIdField; } .
Must be defined for setFeatureStyle to work. |
Method | Returns | Description |
---|---|---|
setFeatureStyle( |
this |
Given the unique ID for a vector features (as per the |
getDataLayerNames() |
Array |
Returns an array of strings, with all the known names of data layers in the vector tiles displayed. Useful for introspection. |
VectorGrid
must define the _getVectorTilePromise
private method.Method | Returns | Description |
---|---|---|
getVectorTilePromise( |
Promise |
Given a |
A symbolizer for filled areas. Applies only to polygon features.
A symbolizer for lines. Can be applied to line and polygon features.
A symbolizer for points.
The abstract Symbolizer class is mostly equivalent in concept to a L.Path
- it's an interface for
polylines, polygons and circles. But instead of representing leaflet Layers,
it represents things that have to be drawn inside a vector tile.
Method | Returns | Description |
---|---|---|
initialize( |
|
Initializes a new Line Symbolizer given a GeoJSON feature and the pixel-to-coordinate-units ratio. Internal use only. |
render(renderer, style) |
|
Renders this symbolizer in the given tiled renderer, with the given
|
L.TileLayer
, the URL template might contain a reference to any option (see the example above and note the{key}
ortoken
in the URL template, and the corresponding option).