Add a 3D model to globe using MapTiler 3D JS

This example shows how to add a 3D model to globe using MapTiler 3D JS module. The 3D JS module enables you to integrate multiple 3D objects onto the globe surface. You can adjust model sizes, create duplicates, position models at specific elevations above sea level, and more. This offers complete flexibility in manipulating your 3D models.

NPM module setup


npm install --save @maptiler/sdk @maptiler/3d
import { Map, MapStyle, config } from '@maptiler/sdk';
import '@maptiler/sdk/dist/maptiler-sdk.css';
import { Layer3D, AltitudeReference } from '@maptiler/3d';

config.apiKey = 'YOUR_MAPTILER_API_KEY_HERE';
const map = new Map({
  container: 'map', // container's id or the HTML element to render the map
  style:  MapStyle.SATELLITE,
  center: [-15.45, -21.27], // starting position [lng, lat]
  zoom: 0.75, // starting zoom
  projection: 'globe' //enable globe projection
});

(async () => {
  await map.onReadyAsync();

  const layer3D = new Layer3D("custom-3D-layer");
  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 originalPlaneID = "plane";
  await layer3D.addMeshFromURL(
    originalPlaneID,
    "https://docs-media.maptiler.com/docs/models/plane_a340.glb",
    {
      scale: 1000,
      altitude: 1000000,
      heading: 55,
      altitudeReference: AltitudeReference.MEAN_SEA_LEVEL,
      lngLat: [-2.548828,42.617791]
    }
  );

  const originalDuckID = "duck";
  await layer3D.addMeshFromURL(
    originalDuckID,
    "https://docs-media.maptiler.com/docs/models/duck.glb",
    {
      scale: 1000000,
      heading: 155,
      lngLat: [-43.857422,24.447150]
    }
  );

  layer3D.cloneMesh(originalDuckID, `${originalDuckID}_1`, {lngLat: [-26.298828,28.226970], scale: 400000});

})();

 ↩

Projection control how to toggle the map between mercator and globe projection

Projection control (globe)

Tutorials

Toggle between Mercator and globe projections using map controls.

Create a globe map with ocean bathymetry terrain elevation

Globe with ocean bathymetry

Examples

Display ocean bathymetry and terrain elevation on 3D globe.

Add multiple 3D models to the map

Add multiple 3D models

Examples

Incorporate multiple 3D models with adjustable parameters on maps.

Animate a 3D plane flight in a globe using MapTiler 3D JS

Animate a 3D plane flight in a globe

Examples

Animate airplane flight paths using 3D models on globe.

Was this helpful?