Skip to content

3D Layers

@maptoolkit/maplibre-3d-layers has two MapLibre GL JS custom layers that draw 3D geometry with three.js:

LayerWhat it draws
Fill3DLayerThe buildings of the community buildings tileset as 3D bodies with roof shapes.
GltfLayerglTF models at the features of a source: one per point, spaced along lines, or spread over polygons.

To show the 3D buildings and trees of the Street or Summer style, you do not need this package. The Scene3D Control brings it along and sets up the layers. Use the layers directly for your own colors, your own models, or a style without a 3D scene.

Install

npm install @maptoolkit/maplibre-3d-layers three maplibre-gl
import { Fill3DLayer, GltfLayer } from "@maptoolkit/maplibre-3d-layers";

Without a bundler, load dist/maplibre-3d-layers.standalone.mjs from a CDN, for example https://cdn.jsdelivr.net/npm/@maptoolkit/maplibre-3d-layers@0.5.6/dist/maplibre-3d-layers.standalone.mjs. It includes three.js, so the import map needs only the maplibre-gl entry.

The community buildings tileset

Fill3DLayer reads the buildings tileset. On the community services its TileJSON is https://tiles.maptoolkit.org/buildings.json and needs no API key:

map.addSource("buildings", {
  type: "vector",
  url: "https://tiles.maptoolkit.org/buildings.json",
});

The tileset has two source layers. buildings2d holds the footprints with their height, for a fill-extrusion layer. buildings3d holds the buildings with roof shapes and the city models from zoom 15, for Fill3DLayer. Draw both to show all buildings. 3D Buildings lists the fields.

Reference

The 3D Layers reference on docs.maptoolkit.com shows the full setup of both layers with all options. Its examples use the tiles.maptoolkit.net tileset with an API key; replace that URL with the one above.

License

The 3D Layers are open source under the MIT License.