SDKs · React & Next.js
Step 7 — 3D buildings & trees
Extruded or detailed 3D buildings, trees, colors and on/off switches.
Buildings and trees are separate layers. Choose how they are drawn with buildings and trees, then restyle or hide them live:
"use client";
import { useState } from "react";
import { UbHubMap } from "@ubhub/maps/react";
export function CityMap() {
const [showBuildings, setShowBuildings] = useState(true);
const [showTrees, setShowTrees] = useState(true);
return (
<UbHubMap
style={{ height: 600 }}
buildings="detailed" // none | flat (default) | extruded | detailed | 3d
trees="extruded" // none (default) | points | extruded | 3d
pitch={55} // 0 keeps the map flat
buildingStyle={{ color: "#1d4ed8", heightScale: 1.5 }}
treeStyle={{ color: "#22c55e" }}
showBuildings={showBuildings} // toggles live, no new map load
showTrees={showTrees}
/>
);
}| Prop | Changing it |
|---|---|
buildings, trees | Loads a new style (one map load) |
buildingStyle, treeStyle | Restyles the layer in place |
showBuildings, showTrees | Hides or shows the layer in place |
pitch | Tilts the camera (0 keeps the map flat) |
Detailed 3D models
For the detailed building meshes and tree models, the same 3D view as our map, install the 3D renderer's peers and pass ubhub3d as scene3d:
npm install @deck.gl/core @deck.gl/layers @deck.gl/geo-layers @deck.gl/mesh-layers @deck.gl/mapbox \
@loaders.gl/core @loaders.gl/3d-tiles @loaders.gl/gltf @loaders.gl/draco @loaders.gl/mvtimport { UbHubMap } from "@ubhub/maps/react";
import { ubhub3d } from "@ubhub/maps/3d";
<UbHubMap
style={{ height: 600 }}
buildings="3d"
trees="3d"
scene3d={ubhub3d} // the detailed meshes and tree models
pitch={55}
initialZoom={16}
/>;- The renderer lives in
@ubhub/maps/3d. Apps that do not import it need none of these packages, and their bundle does not grow. - Without
scene3d,"3d"falls back to extruded buildings and tree points. buildingStyle.coloralso colors the meshes (#rgbor#rrggbb); tree models keep their own colors."none"leaves a layer and its tiles out entirely; a hidden layer loads no new tiles. Each style and 3D tileset load counts as one map load.
Upgrade to 0.3.0
Versions 0.2.x cannot load the current standard basemap. Run
npm install @ubhub/maps@latest.Deploy note
Your proxy route serves the Draco decoder for the meshes at
/api/ubhub/draco/. With a CSP, allow worker-src 'self' blob: and script-src 'wasm-unsafe-eval'. With output: "standalone", trace node_modules/@loaders.gl/draco/dist/**.