For AI agents: a documentation index is available at /llms.txt. Markdown versions of all pages are available by appending .md to any URL.

Position markers at different altitudes with 3D terrain

This example demonstrates how to place markers at different altitudes floating above 3D terrain using MapTiler SDK v5:

  • Altitude positioning: Set marker altitude in meters using .setAltitude(altitude, { relativeTo: "sea" | "ground" }).
    • Sea level (relativeTo: "sea"): Position markers at absolute elevations (ASL). Markers stay at a fixed global height regardless of the terrain underneath.
    • Ground level (relativeTo: "ground"): Position markers relative to the terrain surface directly below (AGL). Markers rise and fall dynamically following the underlying slopes and ridges.
  • Vertical ground lines: Enable .setGroundLine(true) to draw a dynamic vertical connector line from each floating marker down to the surface of the 3D terrain.
  • Interactive dragging: Drag any marker across the terrain (draggable: true). Notice how sea-level markers keep their fixed elevation while their ground lines stretch or contract, while ground-relative markers glide over mountain contours at a constant clearance.

The scene centers on the dramatic mountain amphitheater of Glencoe, Scotland, featuring four nearby markers: a mountain rescue helicopter at 720 m ASL, a ridge lookout at 580 m ASL, a survey drone hovering at 150 m AGL, and a valley basecamp stationed at 40 m AGL.

NPM module setup


npm install --save @maptiler/sdk
import { Map, MapStyle, config, Popup, Marker } from "@maptiler/sdk";
import "@maptiler/sdk/dist/maptiler-sdk.css";

config.apiKey = "YOUR_MAPTILER_API_KEY";

// Initialize map with 3D terrain centered on Glencoe amphitheater
const map = new Map({
  container: "map",
  style: MapStyle.HYBRID,
  center: [-5.005, 56.661],
  zoom: 13.7,
  pitch: 60,
  bearing: -15,
  terrain: true,
  terrainControl: true,
});

map.on("load", () => {
  // 1. High Altitude Marker (720 m ASL): Rescue Helicopter
  const helicopter = new Marker({
    lngLat: [-5.001, 56.663],
    shape: "maptiler",
    size: "m",
    icon: "hospital",
    innerColor: "#E11D48",
    outerColor: "#FFFFFF",
    title: "Mountain Rescue Helicopter (720 m ASL)",
    draggable: true,
  });
  map.addMarker(helicopter);
  helicopter.setAltitude(720, { relativeTo: "sea" }).setGroundLine(true);
  helicopter.setPopup(
    new Popup({ offset: 30 }).setHTML(
      "<strong>Rescue Helicopter</strong><br>Altitude: 720 m ASL (Sea level)<br><em>Draggable marker</em>",
    ),
  );

  // 2. Mid-High Altitude Marker (580 m ASL): Mountain Ridge Lookout
  const ridge = new Marker({
    lngLat: [-5.007, 56.656],
    shape: "maptiler",
    size: "m",
    icon: "flag",
    innerColor: "#0070F3",
    outerColor: "#FFFFFF",
    title: "Ridge Lookout (580 m ASL)",
    draggable: true,
  });
  map.addMarker(ridge);
  ridge.setAltitude(580, { relativeTo: "sea" }).setGroundLine(true);
  ridge.setPopup(
    new Popup({ offset: 30 }).setHTML(
      "<strong>Ridge Lookout</strong><br>Altitude: 580 m ASL (Sea level)<br><em>Draggable marker</em>",
    ),
  );

  // 3. Ground-Relative Marker (150 m AGL): Survey Drone
  const drone = new Marker({
    lngLat: [-5.004, 56.659],
    shape: "circle",
    size: "m",
    content: "D",
    contentColor: "#FFFFFF",
    innerColor: "#8B5CF6",
    outerColor: "#FFFFFF",
    title: "Survey Drone (150 m AGL - Ground)",
    draggable: true,
  });
  map.addMarker(drone);
  drone.setAltitude(150, { relativeTo: "ground" }).setGroundLine(true);
  drone.setPopup(
    new Popup({ offset: 30 }).setHTML(
      "<strong>Survey Drone</strong><br>Altitude: 150 m AGL (Relative to ground)<br><em>Draggable marker</em>",
    ),
  );

  // 4. Ground-Relative Marker (40 m AGL): Valley Basecamp
  const basecamp = new Marker({
    lngLat: [-5.007, 56.664],
    shape: "bubble-circle",
    size: "m",
    innerColor: "#10B981",
    outerColor: "#FFFFFF",
    title: "Valley Basecamp (40 m AGL - Ground)",
    draggable: true,
  });
  map.addMarker(basecamp);
  basecamp.setAltitude(40, { relativeTo: "ground" }).setGroundLine(true);
  basecamp.setPopup(
    new Popup({ offset: 30 }).setHTML(
      "<strong>Valley Basecamp</strong><br>Altitude: 40 m AGL (Relative to ground)<br><em>Draggable marker</em>",
    ),
  );
});
Display simple marker on the map

Display marker

Tutorials

Learn how to add a default marker to your map.

Create a draggable marker

Create a draggable marker

Examples

Create a draggable marker and display its map coordinates.

Show the trace position with Elevation profile control

Show trace position Elevation profile control

Examples

Synchronize a moving map marker with elevation profile cursor.

Customize and create marker shapes interactively

Marker shapes and customization

Examples

Configure and create customizable, draggable markers in real-time with custom shapes, embedded letters, emojis, sizes, colors, and shadows.

Marker animations, transitions, and interactive UI states

Marker animations and states

Examples

Create animated markers with interactive UI states and transitions.

Was this helpful?