Change the opacity and visibility of splats

This example shows how to change the opacity of splats and how to dynamically hide or show it. This is particularly useful for visualizing layers of information, highlighting specific objects, or creating smooth transitions in your 3D scenes.

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: [9.59401, 59.22317],
  zoom: 17.23
});

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

  document.getElementById("opacity").oninput = (e) => {
    splatModel.setOpacity(parseFloat(e.target.value));
  };

  let visible = true;
  document.getElementById("toggle-vis").onclick = () => {
    visible = !visible;
    if (visible) splatModel.show();
    else splatModel.hide();
  };
});

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.

Edit model in custom editor

Edit model in custom editor

Examples

Build a custom 3D editor to adjust the position, rotation, and scale of splat models and save their properties to a database.

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.

Was this helpful?