For AI agents: a documentation index is available at /llms.txt. Markdown versions of all pages are available by appending .md to any URL.
Display a 3D building model generated with photogrammetry software
Use the MapTiler 3D JS module to display a 3D building model generated with photogrammetry software processing thousands images on a map. Thanks to the 3D JS module we can view the 3D model and navidate inside the building.
This demonstration showcases a small control interface that allows to adjust various model parameters and instantly see their effects on the model’s behavior.
MapTiler 3D Compatibility
This example uses MapTiler SDK v4.2.1 for compatibility with the @maptiler/3d module. We are actively updating the 3D module to support MapTiler SDK v5.0.0.
NPM module setup
npm install --save @maptiler/sdk @maptiler/3d lil-gui
import { Map, MapStyle, config } from '@maptiler/sdk';
import '@maptiler/sdk/dist/maptiler-sdk.css';
import { Layer3D, AltitudeReference } from '@maptiler/3d';
import { GUI } from 'lil-gui';
config.apiKey = 'YOUR_MAPTILER_API_KEY';
const map = new Map({
container: document.getElementById('map'),
style: MapStyle.DATAVIZ,
zoom: 18,
center: [-2.9712237417697906, 56.462597919624585],
pitch: 60,
maxPitch: 85,
terrainControl: true,
terrain: true,
maptilerLogo: true,
});
(async () => {
await map.onReadyAsync();
map.setSky({
"sky-color": "#b2ddfa",
"horizon-color": "#FFFFFF",
"fog-color": "#FFFFFF",
"fog-ground-blend": 0.8,
"horizon-fog-blend": 0.1,
"sky-horizon-blend": 0.6,
"atmosphere-blend": 0.5,
})
const layer3D = new Layer3D("custom-3D-layer", {antiaslias: true});
map.addLayer(layer3D);
// Increasing the intensity of the ambient light
layer3D.setAmbientLight({intensity: 2});
// Adding a point light
layer3D.addPointLight("point-light", {intensity: 30});
const gui = new GUI({ width: 200 });
const meshId = "some-mesh";
const mesh = await layer3D.addMeshFromURL(
meshId,
"https://docs-media.maptiler.com/docs/models/scotland_dundee_the_mcmanus_5m_point_cloud.glb",
{
lngLat: [-2.9712237417697906, 56.462597919624585],
heading: 100,
scale: 1,
visible: true,
altitude: 6.5,
altitudeReference: AltitudeReference.GROUND,
}
);
const guiObj = {
opacity: 1,
pointSize: 1,
}
gui.add( guiObj, 'opacity', 0, 1)
.onChange((opacity) => {
mesh.modify({opacity});
});
gui.add( guiObj, 'pointSize', 0, 20, 0.1 )
.onChange((pointSize) => {
mesh.modify({pointSize});
});
})()
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="robots" content="noindex">
<title>Display a 3D building model generated with photogrammetry software | NPM example</title>
<link rel="stylesheet" href="./style.css">
</head>
<body>
<div id="map"></div>
<script type="module" src="./main.js"></script>
</body>
</html>
body {margin: 0; padding: 0;}
#map {position: absolute; top: 0; bottom: 0; width: 100%;}
.lil-gui.autoPlace {
right: inherit;
left: 15px;
}
Scotland: Dundee, The McManus (5M point cloud) by Daniel Muirhead is licensed under Creative Commons Attribution ↩