@klorad/engine-mapbox
The scene on a GL map with Mapbox GL JS or MapLibre GL JS. A reader like the three.js, OpenLayers and Cesium ones, drawing the same World on a real map.
import { createMapboxRenderer } from "@klorad/engine-mapbox";
import { MapboxView } from "@klorad/engine-mapbox/react";The package holds no map library. You pass the one you are licensed for as gl: Mapbox GL JS
3 (import mapboxgl from "mapbox-gl", with your access token and its terms) or MapLibre GL JS 4
or 5 (import maplibregl from "maplibre-gl", open source, no token). Load the library's own
stylesheet in your page. Peer dependencies: react and @klorad/react for MapboxView only.
import maplibregl from "maplibre-gl";
import "maplibre-gl/dist/maplibre-gl.css";
const map = createMapboxRenderer({ container, scene, gl: maplibregl, onPick: (id) => map.select(id) });| Export | Kind | Description |
|---|---|---|
createMapboxRenderer(options) | function | Draws the scene on a GL map in container. Returns a MapboxRenderer. |
MapboxView (/react) | component | The map as a React component; reads the scene from KloradProvider unless given one. Its ref is the camera handle every Klorad view gives (frame, frameFeature, which frames the building that holds the element since this view does not draw its elements one by one, view, setView, setDrag, metresPerPixel, footprint, toScreen), so stage tools, saved views and tours move it as they move three.js. Its map style is mapStyle. |
defaultMapboxPalette, defaultMapboxStyle, isStale | value, function | The default colours and look: correspondence by colour, a shadow or twin without a fresh reading in grey. |
MapboxPalette, MapboxLook, MapboxStyleContext, MapboxStyleFn | type | For objectStyle: the object, its readings, whether it is stale and selected; returns a colour, a height scale, for a point the name of an icon, and faint: drawn faint and met by a click only when nothing else is there, as the Operational look of ADR-0109 draws what is not connected; and hidden: not drawn at all, nor met by a click, for what a person hides while they work (ADR-0113). |
toMapCamera, fromMapCamera, metresPerPixelAt, zoomFor | function | A Klorad camera view (target in metres, heading, tilt, distance) to a GL map camera and back. |
mapShape, featuresOf, ribbon, layerDefinitions | function | How objects become GeoJSON and layers, for a map you draw yourself. |
MapBasemap | type | A basemap under the scene: { style }, a GL style as a URL or an object, or { tiles, tileSize?, attribution?, minzoom?, maxzoom? }, raster tiles as XYZ templates. |
basemapStyle, groundStyle, sameBasemap | function | The style a basemap is drawn with, the plain ground, and whether two basemaps are the same one, for a map you draw yourself. |
mapboxCapabilities | value | What this reader draws: every shape, solids raised to their height, a model as a symbol, two and three dimensions. |
GlLibrary, GlMap | type | The part of a GL library the reader uses. |
What it draws
| Geometry | On the map |
|---|---|
box, extrusion, cylinder, sphere | The footprint raised from the object's height to its top (a sphere as an upright cylinder of its size). |
polygon | The area on the ground. |
polyline | The path as wide as its width in metres at every zoom. |
marker | A dot at its position; with an icon from its style, a disc in its colour with the icon over it. |
model | Its footprint raised from its position to its height, when the geometry carries both (a building brought in from IFC does); otherwise a symbol at its position, the shape living in its file. |
splat | A symbol at its position: the shape lives in its file. |
feature | Its footprint raised to its height, when it has both; the footprint on the ground with no height; nothing when it has no footprint (a storey). |
group | Nothing of its own: its parts are drawn. |
Options
Prop
Type
MapboxRenderer
| Member | Description |
|---|---|
select(objectId | null) | Outlines an object; selection is your state, not the world's. |
frame(objectIds?, { animate? }) | Fits the view to the given objects, or to all of them. |
view(), setView(view, { animate? }) | The camera as a CameraView, and moving it. |
setDrag(mode) | What a drag with the main button or one finger does from now on: "pan" or "rotate" (the drag option, default "pan"). The other button, or the main one with Ctrl, does the other. |
metresPerPixel(), footprint(), toScreen(point) | For a scale bar, the area in view, and drawing over the map. |
setBasemap(basemap | null) | Draws the scene over another basemap, or over none: the style the map was made with, or the plain ground. The camera and the selection stay. |
setLabels(shown) | Hides or shows the place names of the style the map draws: its symbol layers, never the scene's own. Kept for every style the map takes. |
groundHeight(place) | Always 0: the map is a plan and draws no terrain. The three renderers answer it, so a page asks whichever is in front. |
enterVR() | Refused: a map has no VR. |
map | The GL map, for what this reader does not do. |
dispose() | Stops following the scene and removes the map. |
A basemap under the scene
A map opens on a plain ground, which needs no token and no one's tiles. Give it a basemap your app is licensed to use, when it is made or while it runs:
map.setBasemap({ style: "https://tiles.example.com/styles/streets/style.json" });
map.setBasemap({ tiles: ["https://tiles.example.com/aerial/{z}/{x}/{y}.jpg"], attribution: "© Example Imagery" });
map.setBasemap(null);A style is the source's own, with its layers and its words. Raster tiles are drawn over the
plain ground, so a tile that fails shows the ground, and attribution is what the map's
attribution control shows with them. A new style takes away what was added to the old one, so
the reader puts the scene's layers and icons on every style the map takes; the selection and
the camera are not touched. setLabels(false) hides a style's place names; raster tiles have
theirs painted in, so for those give the tiles of the same basemap without names. The reader names no provider: the addresses, their terms and what
they ask to be shown are your app's. See the guide
Put a basemap and terrain under a scene.
Icons
A style names an icon for a point, and the renderer draws it over a disc in the point's colour, so the colour still says the state and the icon says what it is:
const map = createMapboxRenderer({
container,
scene,
gl: maplibregl,
icons: { sign: '<svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 0 24 24" fill="none" stroke="#fff" stroke-width="2"><rect x="3" y="5" width="18" height="10" rx="1"/></svg>' },
objectStyle: ({ object, palette }) => ({ color: palette.shadow, ...(object.properties.kind === "sign" ? { icon: "sign" } : {}) }),
});The renderer never changes the scene. It follows its events, and restyles every second so a reading that goes stale turns grey without a new event.
Try it in your browserExample: Select a detector on a map and in 3DA junction on a map: the blocks raised to their height, the roads in their true width, the detectors coloured by their flow, read the same in three.js.Something wrong or unclear? Tell us.
@klorad/engine-cesium
The scene on the globe with CesiumJS. A reader like the three.js and OpenLayers ones, drawing the same World, with buildings streamed as 3D Tiles and their elements as features.
@klorad/access
The Access layer. Worlds, the Entitlement the World layer asks, projections per World and the audit log.