Display a simple globe with a single color layer.

Parameters
100% © OpenStreetMap contributors
index.js
import { OSM } from "ol/source.js";

import GlobeControls from "@giro3d/giro3d/controls/GlobeControls.js";
import Instance from "@giro3d/giro3d/core/Instance.js";
import ColorLayer from "@giro3d/giro3d/core/layer/ColorLayer.js";
import Globe from "@giro3d/giro3d/entities/Globe.js";
import Inspector from "@giro3d/giro3d/gui/Inspector.js";
import TiledImageSource from "@giro3d/giro3d/sources/TiledImageSource.js";

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

  element.oninput = function oninput() {
    onChange(element.checked);
  };

  const callback = (v) => {
    element.checked = v;
    onChange(element.checked);
  };

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

const instance = new Instance({
  target: "view",
  crs: "EPSG:4978",
  backgroundColor: "grey",
});

const globe = new Globe({
  backgroundColor: "#aad3df",
});

globe.helperColor = "black";

instance.add(globe);

const layer = new ColorLayer({
  source: new TiledImageSource({ source: new OSM() }),
});

globe.addLayer(layer);

instance.view.goTo(globe);

const controls = new GlobeControls({
  scene: globe.object3d,
  ellipsoid: globe.ellipsoid,
  camera: instance.view.camera,
  domElement: instance.domElement,
});

const updateControls = () => {
  controls.update();
  instance.notifyChange(globe);

  requestAnimationFrame(updateControls);
};

updateControls();

Inspector.attach("inspector", instance);

bindToggle("show-layer", (v) => {
  layer.visible = v;
  instance.notifyChange(layer);
});
bindToggle("show-bounding-boxes", (v) => {
  globe.showBoundingBoxes = v;
  instance.notifyChange(globe);
});
bindToggle("show-lod-spheres", (v) => {
  globe.showBoundingSpheres = v;
  instance.notifyChange(globe);
});
bindToggle("show-outlines", (v) => {
  globe.showTileOutlines = v;
  instance.notifyChange(globe);
});
index.html
<!doctype html>
<html lang="en">
  <head>
    <title>Simple Globe</title>
    <meta charset="UTF-8" />
    <meta name="name" content="simple_globe" />
    <meta
      name="description"
      content="Display a simple globe with a single color layer."
    />
    <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"
    />
  </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">
          <!-- Toggle tile outlines -->
          <div class="form-check form-switch">
            <input
              class="form-check-input"
              type="checkbox"
              role="switch"
              id="show-outlines"
              autocomplete="off"
            />
            <label class="form-check-label" for="show-outlines"
              >Show tiles</label
            >
          </div>

          <!-- Toggle bounding boxes -->
          <div class="form-check form-switch">
            <input
              class="form-check-input"
              type="checkbox"
              role="switch"
              id="show-bounding-boxes"
              autocomplete="off"
            />
            <label class="form-check-label" for="show-bounding-boxes"
              >Show bounding boxes</label
            >
          </div>

          <!-- Toggle LOD spheres -->
          <div class="form-check form-switch">
            <input
              class="form-check-input"
              type="checkbox"
              role="switch"
              id="show-lod-spheres"
              autocomplete="off"
            />
            <label class="form-check-label" for="show-lod-spheres"
              >Show LOD spheres</label
            >
          </div>

          <!-- Toggle color layer -->
          <div class="form-check form-switch">
            <input
              class="form-check-input"
              type="checkbox"
              role="switch"
              id="show-layer"
              checked
              autocomplete="off"
            />
            <label class="form-check-label" for="show-layer"
              >Show color layer</label
            >
          </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": "simple_globe",
    "dependencies": {
        "@giro3d/giro3d": "0.43.1"
    },
    "devDependencies": {
        "vite": "^3.2.3"
    },
    "scripts": {
        "start": "vite",
        "build": "vite build"
    }
}