Skip to content

Vector tiles in MapLibre and deck.gl

Two single-file pages used to check Loka vector tiles with third-party web engines. They load the engine from unpkg, so the browser needs internet access.

Page Engine What it does
maplibre.html MapLibre GL JS 4.7.1 Adds the layer’s TileJSON as a vector source and draws one source layer
deckgl.html deck.gl 9.0.38 MVTLayer with the TileJSON address as data

Both read their settings from the address:

maplibre.html?tj=<TileJSON address>&sl=<source layer>&lon=107.6&lat=-6.99&z=10[&type=line|fill|circle]
deckgl.html?tj=<TileJSON address>&lon=107.6&lat=-6.99&z=10

The TileJSON address and the source layer (the layer’s WMS name) are on the layer’s Publishing tab in the console.

The pages run on another origin than Loka Server and send no credentials. For a quick local check, serve this folder (python -m http.server 8099 --bind 127.0.0.1), add http://127.0.0.1:8099 under Security → Allowed origins, and either switch on “Map services without token” or give the engine an Authorization: Bearer <API token> header (MapLibre: transformRequest; deck.gl: loadOptions.fetch.headers). Switch both settings off again afterwards.

Each page writes what it loaded to window.result and to the box in the corner.

No extra format is needed: a polygon layer whose attributes say how high each polygon is becomes 3D in the client. The server sends the attributes in the vector tile with their types (numbers stay numbers).

maplibre.html?tj=<TileJSON>&sl=<source layer>&lon=107.6106&lat=-6.9152&z=16.3&type=fill-extrusion&pitch=60&bearing=-20
deckgl.html?tj=<TileJSON>&lon=107.6106&lat=-6.9152&z=16.3&extrude=1&pitch=55&bearing=-20

Attribute names the pages (and loka.gl’s building profile, V3D-06 in the loka.gl repository) read:

Attribute Meaning Used by
height Top of the polygon above ground, metres MapLibre, deck.gl, loka.gl
min_height Bottom of a raised part above ground, metres MapLibre, loka.gl. deck.gl’s MVTLayer has no base height: raised parts start at the ground
building:levels, roof:shape, … OpenStreetMap “Simple 3D Buildings” keys loka.gl (when height is missing; roof shapes)

Name the columns like this in the data before importing it (GeoPackage keeps names with a colon; Shapefile shortens names to 10 characters and cannot hold a colon). The test file tests/fixtures/golden-buildings.gpkg has six such polygons.

Limits: heights are above ground, not above sea level, and the blocks do not follow the terrain unless the client drapes them itself; a tile is drawn per request and is not cached yet.