How to enable the model camera collision

This example shows how to enable camera collision for a splat model. When enabled, the camera can’t pass through the model when you zoom in too far. Instead, it collides with the model’s surface. The collision also keeps map navigation interactions, such as view rotation, centered on the model, resulting in smoother animations and more effective data visualization.

In the example, you can turn off/on the model collision by clicking the button.

Zoom in on the model to see how the camera collides with the view. Rotate the view to see how the rotation is centered on the model.

NPM module setup


npm install --save @maptiler/geosplats
import { SplatModel, Map, config } from "@maptiler/geosplats";
import '@maptiler/geosplats/dist/maptiler-geosplats.css';

config.apiKey = 'YOUR_MAPTILER_API_KEY_HERE';
const map = new Map({
  apiKey: config.apiKey,
  container: "map",
  center: [-80.27822, 25.74077],
  zoom: 17.26
});

let cameraCollisions = true;

map.on("load", () => {
  const splatModel = new SplatModel({
    model: "YOUR_MAPTILER_SPLAT_MODEL_ID_HERE",
    cameraCollisions: cameraCollisions
  });
  map.addSplatModel(splatModel);
});

document.getElementById('btn-collision').addEventListener('click', function () {
  cameraCollisions = !cameraCollisions;
  this.classList.toggle("collision-disabled");
  if (cameraCollisions) {
    this.innerHTML = "Disable collision";

  } else {
    this.innerHTML = "Enable collision";

  }
  splatModel.setCameraCollisions(cameraCollisions);
});

Enable camera collision

This feature is disabled by default. You can enable it by calling SplatModel’s setCameraCollision API method or by passing it as an option to the SplatModel constructor, as shown in this example.

Learn more

Check out the MapTiler GeoSplats SDK JS reference

How to add a splat model to your map

Add splat model

Examples

Learn how to load a map using the GeoSplats SDK and add a photorealistic splat model. A splat model offer a modern alternative to 3D meshes, perfect for complex scenes.

Capture map and splats events

Capture events

Examples

Learn how to capture both global map events and specific splats events like load, update, mouseover, and click.

Change map basemap

Change basemap

Examples

Learn how to dynamically switch between different MapTiler basemaps while maintaining photorealistic 3D splats models in your scene.

Change the opacity and visibility of splats

Opacity and visibility

Examples

Learn how to dynamically control the transparency and visibility of photorealistic splats objects using the MapTiler GeoSplats SDK.

Was this helpful?