Illustrates the optional vertical skirts on maps.

Parameters
100% © Mapbox

Skirts are vertical side on the edges of map tiles that give volume to maps.

index.js
import { AmbientLight, Color, DirectionalLight } from "three";
import { MapControls } from "three/examples/jsm/controls/MapControls.js";

import XYZ from "ol/source/XYZ.js";

import Instance from "@giro3d/giro3d/core/Instance.js";
import Coordinates from "@giro3d/giro3d/core/geographic/Coordinates.js";
import Extent from "@giro3d/giro3d/core/geographic/Extent.js";
import ColorLayer from "@giro3d/giro3d/core/layer/ColorLayer.js";
import ElevationLayer from "@giro3d/giro3d/core/layer/ElevationLayer.js";
import Map from "@giro3d/giro3d/entities/Map.js";
import { MapLightingMode } from "@giro3d/giro3d/entities/MapLightingOptions.js";
import MapboxTerrainFormat from "@giro3d/giro3d/formats/MapboxTerrainFormat.js";
import Inspector from "@giro3d/giro3d/gui/Inspector.js";
import TiledImageSource from "@giro3d/giro3d/sources/TiledImageSource.js";

function bindNumberInput(id, onChange) {
  const element = document.getElementById(id);
  if (!(element instanceof HTMLInputElement)) {
    throw new Error(
      "invalid binding element: expected HTMLInputElement, got: " +
        element.constructor.name,
    );
  }

  element.onchange = () => {
    onChange(element.valueAsNumber);
  };

  const callback = (v) => {
    element.value = v.toString();
    onChange(element.valueAsNumber);
  };

  return [callback, element.valueAsNumber, element];
}

function bindColorPicker(id, onChange) {
  const element = document.getElementById(id);
  if (!(element instanceof HTMLInputElement)) {
    throw new Error(
      "invalid binding element: expected HTMLInputElement, got: " +
        element.constructor.name,
    );
  }

  element.oninput = function oninput() {
    // Let's change the classification color with the color picker value
    const hexColor = element.value;
    onChange(new Color(hexColor));
  };

  const externalFunction = (v) => {
    element.value = `#${new Color(v).getHexString()}`;
    onChange(element.value);
  };

  return [externalFunction, new Color(element.value), element];
}

// Chamonix Mont-Blanc coordinates
const poi = new Coordinates("EPSG:4326", 6.8697, 45.9231)
  .as("EPSG:3857")
  .toVector3();

const extentSize = 30_000;
const extent = Extent.fromCenterAndSize(
  "EPSG:3857",
  { x: poi.x, y: poi.y },
  extentSize,
  extentSize,
);

const instance = new Instance({
  target: "view",
  crs: extent.crs,
  backgroundColor: null,
});

let skirtDepth = 0;
let skirtColor = new Color("#faf0e6");

const center = extent.centerAsVector3();

const directionalLight = new DirectionalLight("white", 3);
const ambientLight = new AmbientLight("white", 1);

directionalLight.position.set(center.x - 5000, center.y - 2000, 10000);
directionalLight.target.position.copy(center);

instance.add(directionalLight);
instance.add(directionalLight.target);
instance.add(ambientLight);

directionalLight.updateMatrixWorld(true);
directionalLight.target.updateMatrixWorld(true);

let map;

const key =
  "pk.eyJ1IjoidG11Z3VldCIsImEiOiJjbGJ4dTNkOW0wYWx4M25ybWZ5YnpicHV6In0.KhDJ7W5N3d1z3ArrsDjX_A";

// Adds a XYZ elevation layer with MapBox terrain RGB tileset
const elevationLayer = new ElevationLayer({
  extent,
  preloadImages: true,
  resolutionFactor: 1 / 8,
  minmax: { min: 0, max: 5000 },
  source: new TiledImageSource({
    format: new MapboxTerrainFormat(),
    source: new XYZ({
      url: `https://api.mapbox.com/v4/mapbox.terrain-rgb/{z}/{x}/{y}.pngraw?access_token=${key}`,
      projection: "EPSG:3857",
      crossOrigin: "anonymous",
    }),
  }),
});

// Adds a XYZ color layer with MapBox satellite tileset
const satelliteLayer = new ColorLayer({
  extent,
  resolutionFactor: 1.5,
  preloadImages: true,
  source: new TiledImageSource({
    source: new XYZ({
      url: `https://api.mapbox.com/v4/mapbox.satellite/{z}/{x}/{y}.webp?access_token=${key}`,
      projection: "EPSG:3857",
      crossOrigin: "anonymous",
    }),
  }),
});

function load() {
  map = new Map({
    extent,
    lighting: {
      enabled: true,
      mode: MapLightingMode.LightBased,
      elevationLayersOnly: true,
    },
    subdivisionThreshold: 1,
    terrain: {
      segments: 64,
      enabled: true,
      skirts: {
        enabled: true,
        depth: skirtDepth,
      },
    },
    backgroundColor: skirtColor,
  });

  instance.add(map);

  map.addLayer(elevationLayer);
  map.addLayer(satelliteLayer);
}

load();

const controls = new MapControls(instance.view.camera, instance.domElement);

instance.view.camera.position.set(
  poi.x - extentSize - 15000,
  poi.y - extentSize - 15000,
  35_000,
);
controls.target.set(poi.x, poi.y, 2000);

instance.view.setControls(controls);

Inspector.attach("inspector", instance);

bindNumberInput("skirt-depth", (v) => {
  skirtDepth = v;
  if (map) {
    instance.remove(map);
  }
  load();
});

bindColorPicker("color", (newColor) => {
  skirtColor = new Color(newColor);
  if (map) {
    map.backgroundColor = skirtColor;
    instance.notifyChange(map);
  }
});
index.html
<!doctype html>
<html lang="en">
  <head>
    <title>Map vertical skirts</title>
    <meta charset="UTF-8" />
    <meta name="name" content="map_skirts" />
    <meta
      name="description"
      content="Illustrates the optional vertical skirts on maps."
    />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />

    <link rel="icon" href="https://giro3d.org/images/favicon.svg" />
    <link
      href="https://giro3d.org/assets/bootstrap-custom.css"
      rel="stylesheet"
    />
    <script src="https://giro3d.org/assets/bootstrap.bundle.min.js"></script>
    <link
      rel="stylesheet"
      type="text/css"
      href="https://giro3d.org/latest/examples/css/example.css"
    />

    <style>
      #view canvas {
        background: rgb(132, 170, 182);
        background: radial-gradient(
          circle,
          rgba(132, 170, 182, 1) 0%,
          rgba(37, 44, 48, 1) 100%
        );
      }
    </style>
  </head>

  <body>
    <div id="view" class="m-0 p-0 w-100 h-100"></div>
    <div
      id="inspector"
      class="position-absolute top-0 start-0 mh-100 overflow-auto"
    ></div>

    <div class="side-pane-with-status-bar">
      <div class="card">
        <div class="card-header">Parameters</div>
        <div class="card-body">
          <!-- Color -->
          <label class="form-check-label w-100 mb-2" for="color"
            >Skirt color</label
          >
          <div class="input-group">
            <input
              type="color"
              class="form-control form-control-color float-end"
              id="color"
              value="#faf0e6"
              title="color"
              autocomplete="off"
            />
          </div>

          <!-- Skirt depth -->
          <label for="skirt-depth" class="form-label mt-2"
            >Skirt depth (meters)</label
          >
          <div class="input-group">
            <input
              type="number"
              min="-10000"
              max="10000"
              value="0"
              step="500"
              class="form-control"
              id="skirt-depth"
              autocomplete="off"
            />
          </div>
        </div>
      </div>
    </div>

    <script type="module" src="index.js"></script>
    <script>
      /* activate popovers */
      const popoverTriggerList = [].slice.call(
        document.querySelectorAll('[data-bs-toggle="popover"]'),
      );
      popoverTriggerList.map(
        // bootstrap is used as script in the template, disable warning about undef
        // eslint-disable-next-line no-undef
        (popoverTriggerEl) =>
          new bootstrap.Popover(popoverTriggerEl, {
            trigger: "hover",
            placement: "left",
            content: document.getElementById(
              popoverTriggerEl.getAttribute("data-bs-content"),
            ).innerHTML,
            html: true,
          }),
      );
    </script>
  </body>
</html>
package.json
{
    "name": "map_skirts",
    "dependencies": {
        "@giro3d/giro3d": "0.43.1"
    },
    "devDependencies": {
        "vite": "^3.2.3"
    },
    "scripts": {
        "start": "vite",
        "build": "vite build"
    }
}