Display the inspector with a custom panel.

100% Map style by Stamen Design, © OpenStreetMap contributors

The inspector is an extensible tool used to debug and diagnose issues in the 3D scene.

index.js
import GUI from "lil-gui";

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

import { MapControls } from "three/examples/jsm/controls/MapControls.js";

import Inspector from "@giro3d/giro3d/gui/Inspector.js";
import Extent from "@giro3d/giro3d/core/geographic/Extent.js";
import Instance from "@giro3d/giro3d/core/Instance.js";
import ColorLayer from "@giro3d/giro3d/core/layer/ColorLayer.js";
import Map from "@giro3d/giro3d/entities/Map.js";
import Panel from "@giro3d/giro3d/gui/Panel.js";
import TiledImageSource from "@giro3d/giro3d/sources/TiledImageSource.js";

class MyCustomPanel extends Panel {
  constructor(parentGui, map, instance) {
    super(parentGui, instance, "Custom panel");

    this.map = map;

    this.myCheckBox = true;

    this.addController(this, "sayHello").name("Press this button!");
    this.addController(this, "myCheckBox")
      .name("Check this box !")
      .onChange((value) => {
        this.map.object3d.visible = value;
        this.instance.notifyChange(this.map);
      });
  }

  sayHello() {
    window.alert("Hello from my custom panel!");
  }
}

const extent = new Extent(
  "EPSG:3857",
  -20037508.342789244,
  20037508.342789244,
  -20037508.342789244,
  20037508.342789244,
);

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

const map = new Map({ extent });

instance.add(map);

map.addLayer(
  new ColorLayer({
    source: new TiledImageSource({
      source: new StadiaMaps({ layer: "stamen_watercolor", wrapX: false }),
    }),
  }),
);

// Create camera and controls
instance.view.camera.position.set(0, 0, 25000000);
const controls = new MapControls(instance.view.camera, instance.domElement);
instance.view.setControls(controls);

// Attach the inspector to the DOM
const inspectorDiv = document.getElementById("inspector");
inspectorDiv.classList.remove("d-none");
const inspector = Inspector.attach(inspectorDiv, instance, {
  title: "Custom title",
});

// Hide the fullscreen button that is at the same place as the Inspector
const btnFullscreen = document.getElementById("btnFullscreen");
btnFullscreen.classList.add("d-none");

const myCustomPanel = new MyCustomPanel(inspector.gui, map, instance);

// Add our custom panel to the inspector.
inspector.addPanel(myCustomPanel);

// Trigger the first render
instance.notifyChange(map);
index.html
<!doctype html>
<html lang="en">
  <head>
    <title>Inspector</title>
    <meta charset="UTF-8" />
    <meta name="name" content="inspector" />
    <meta
      name="description"
      content="Display the inspector with a custom panel."
    />
    <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/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>

    <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": "inspector",
    "dependencies": {
        "@giro3d/giro3d": "0.39.0"
    },
    "devDependencies": {
        "vite": "^3.2.3"
    },
    "scripts": {
        "start": "vite",
        "build": "vite build"
    }
}