A minimal Mapbox custom layer to add Three.js models to a map.
If you need more advanced features, check out ThreeBox.
const threeLayer = new ThreeJsCustomLayer();
const map = new mapboxgl.Map({
container: 'map',
center: [9.191383, 45.464211],
zoom: 11,
accessToken: 'your-access-token',
style: 'mapbox://styles/mapbox/outdoors-v11',
});
map.once('load' () => {
map.addLayer(threeLayer);
const geometry = new THREE.BoxGeometry(100, 100, 100);
const material = new THREE.MeshBasicMaterial({color: 0x00ff00});
const cube = new THREE.Mesh(geometry, material);
threeLayer.addObjectAtLocation(cube, map.getCenter());
});