Illustrates the use of the AxisGrid entity.

1,000 m
2,000 m
3,000 m
4,000 m
5,000 m
6,000 m
1,000 m
2,000 m
3,000 m
4,000 m
5,000 m
6,000 m
1,000 m
2,000 m
3,000 m
4,000 m
5,000 m
6,000 m
1,000 m
2,000 m
3,000 m
4,000 m
5,000 m
6,000 m
1,200 m
1,400 m
1,600 m
1,800 m
2,000 m
2,200 m
2,400 m
1,200 m
1,400 m
1,600 m
1,800 m
2,000 m
2,200 m
2,400 m
Giro3D version
THREE.js version
OpenLayers version
CRS
Memory usage (CPU)
Memory usage (GPU)
Frames
Clear color
Clear alpha
Status
Local clipping enabled
Capabilities
WebGL 2
Max texture units
Max texture size
Precision
Max fragment shader uniforms
Logarithmic depth buffer
Max shader attributes
Check shader errors
EXT_clip_control
EXT_color_buffer_float
EXT_color_buffer_half_float
EXT_conservative_depth
EXT_depth_clamp
EXT_float_blend
EXT_polygon_offset_clamp
EXT_texture_compression_bptc
EXT_texture_compression_rgtc
EXT_texture_filter_anisotropic
EXT_texture_mirror_clamp_to_edge
EXT_texture_norm16
NV_shader_noperspective_interpolation
OES_draw_buffers_indexed
OES_sample_variables
OES_shader_multisample_interpolation
OES_texture_float_linear
OVR_multiview2
WEBGL_clip_cull_distance
WEBGL_compressed_texture_astc
WEBGL_compressed_texture_etc
WEBGL_compressed_texture_etc1
WEBGL_compressed_texture_s3tc
WEBGL_compressed_texture_s3tc_srgb
WEBGL_debug_renderer_info
WEBGL_debug_shaders
WEBGL_lose_context
WEBGL_multi_draw
WEBGL_polygon_mode
WEBGL_stencil_texturing
MSAA
EDL
EDL Radius
EDL Strength
Inpainting
Inpainting steps
Inpainting depth contrib.
Point cloud occlusion
Type
FOV
Automatic plane computation
Far plane
Near plane
Max far plane
Min near plane
Width (pixels)
Height (pixels)
x
y
z
x
y
z
color
Enable cache
Default TTL (seconds)
Capacity (MB)
Capacity (entries)
Entries
Memory usage (approx)
Pending requests
Memory tracker
Identifier
Memory usage (CPU)
Memory usage (GPU)
Status
Render order
Enable
Plane normal X
Plane normal Y
Plane normal Z
Distance
Helper size
Negate plane
Visible
Freeze updates
Opacity
Show volumes
Volume color
Discard no-data values
Sidedness
DoubleSide
Depth test
Visible tiles
Reachable tiles
Loaded tiles
Cast shadow
Receive shadow
Tile width (pixels)
Tile height (pixels)
Show grid
Background
Background opacity
Show tiles outlines
Tile outline color
Show tile info
Show extent
Extent color
Subdivision threshold
Deformation
Wireframe
Tile subdivisions
Show collider meshes
CPU terrain
Stitching
Geometry pool
Enabled
Mode
Hillshade
Hillshade intensity
Z factor
Hillshade zenith
Hillshade azimuth
Elevation layers only
Enable
Color
Opacity
X step
Y step
X Offset
Y Offset
Thickness
Enable
Color
Thickness
Opacity
Primary interval (m)
Secondary interval (m)
Brightness
Contrast
Saturation
Layer count
Render state
Normal
Layers
Identifier
Memory usage (CPU)
Memory usage (GPU)
Name
Source CRS
Status
Resolution factor
Visible
Frozen
Interpretation
Loaded images
Minimum elevation
Maximum elevation
Show extent
Extent color
Enabled
Mode
Elevation
Lower bound
Upper bound
Type
Color space
Data type
Flip Y
Synchronous
CRS
Memory usage (CPU)
Memory usage (GPU)
Loaded/Requested
CRS
Zoom levels
Main URL
Inner source
Identifier
Memory usage (CPU)
Memory usage (GPU)
Status
Render order
Enable
Plane normal X
Plane normal Y
Plane normal Z
Distance
Helper size
Negate plane
Visible
Freeze updates
Opacity
color
Font size
Show helpers
Show labels
Adaptive labels
Absolute ticks
Show floor grid
Show ceiling grid
Show side grids
Floor elevation
Ceiling elevation
X ticks
Y ticks
Z ticks
Show helpers
Show hidden objects
Name filter
Hierarchy
Properties
isObject3D
uuid
name
type
matrixAutoUpdate
matrixWorldAutoUpdate
matrixWorldNeedsUpdate
visible
castShadow
receiveShadow
frustumCulled
renderOrder
x
y
z
x
y
z
Parameters

Adaptive labels are displayed at the intersection of grid lines and the viewport's edges.

Use the label-created event to customize the DOM element of labels.

If enabled, the ticks start at the lower-left (south-west) corner of the grid. If disabled, the ticks start at the origin point of the coordinate system.

50% © U.S. Geological Survey

The AxisGrid is useful to get a grasp of a dataset's volume in 3D space, including is height. The relative origin mode is useful to get a grasp of the dataset's size, with the absolute origin mode displays coordinates in the local CRS.

index.js
import colormap from "colormap";

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

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

import Extent from "@giro3d/giro3d/core/geographic/Extent.js";
import Instance from "@giro3d/giro3d/core/Instance.js";
import ElevationLayer from "@giro3d/giro3d/core/layer/ElevationLayer.js";
import TiledImageSource from "@giro3d/giro3d/sources/TiledImageSource.js";
import Map from "@giro3d/giro3d/entities/Map.js";
import AxisGrid, { TickOrigin } from "@giro3d/giro3d/entities/AxisGrid.js";
import Inspector from "@giro3d/giro3d/gui/Inspector.js";
import Interpretation from "@giro3d/giro3d/core/layer/Interpretation.js";
import GeoTIFFFormat from "@giro3d/giro3d/formats/GeoTIFFFormat.js";
import ColorMap, { ColorMapMode } from "@giro3d/giro3d/core/ColorMap.js";

function bindSlider(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() {
    onChange(element.valueAsNumber);
  };

  const setValue = (v, min, max, step) => {
    if (min != null && max != null) {
      element.min = min.toString();
      element.max = max.toString();

      if (step != null) {
        element.step = step;
      }
    }
    element.valueAsNumber = v;
    onChange(element.valueAsNumber);
  };

  const initialValue = element.valueAsNumber;

  return [setValue, initialValue, element];
}

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];
}

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];
}

const x = -13602000;
const y = 5812000;
const halfWidth = 2500;

const extent = new Extent(
  "EPSG:3857",
  x - halfWidth,
  x + halfWidth,
  y - halfWidth,
  y + halfWidth,
);

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

const map = new Map({
  extent,
  lighting: true,
  discardNoData: true,
  side: DoubleSide,
  backgroundColor: "white",
});

const params = {
  useCustomCss: false,
};

instance.add(map);

const source = new TiledImageSource({
  source: new XYZ({
    minZoom: 10,
    maxZoom: 16,
    url: "https://3d.oslandia.com/dem/MtStHelens-tiles/{z}/{x}/{y}.tif",
  }),
  format: new GeoTIFFFormat(),
});

const floor = 1100;
const ceiling = 2500;

const values = colormap({ colormap: "viridis", nshades: 256 });
const colors = values.map((v) => new Color(v));

const dem = new ElevationLayer({
  name: "dem",
  extent,
  interpretation: Interpretation.Raw,
  source,
  colorMap: new ColorMap({
    colors,
    min: floor,
    max: ceiling,
    mode: ColorMapMode.Elevation,
  }),
});

map.addLayer(dem);

// Create an axis grid that encompasses the Map.
const axisGrid = new AxisGrid({
  volume: {
    extent: extent.withRelativeMargin(0.1),
    floor,
    ceiling,
  },
  ticks: {
    x: 1000,
    y: 1000,
    z: 200,
  },
});

const onLabelCreated = ({ label }) => {
  if (params.useCustomCss) {
    label.classList.add("badge");
    label.classList.add("rounded-pill");
    label.classList.add("text-bg-light");
  }
};

// Let's customize the labels with bootstrap classes
// In you own application, you can use your own CSS classes of courses
axisGrid.addEventListener("label-created", onLabelCreated);

instance.add(axisGrid);

instance.view.camera.position.set(-13594700, 5819700, 7300);

const controls = new MapControls(instance.view.camera, instance.domElement);
controls.target.set(-13603000, 5811000, 0);
instance.view.setControls(controls);

function bindAxisStep(axis) {
  bindSlider(`${axis}-axis-step`, (v) => {
    axisGrid.ticks[axis] = v;
    axisGrid.refresh();
    instance.notifyChange(axisGrid);
  });
}

bindAxisStep("x");
bindAxisStep("y");
bindAxisStep("z");

bindColorPicker("color", (color) => {
  axisGrid.color = color;
  instance.notifyChange(axisGrid);
});

bindToggle("entity", (v) => {
  axisGrid.visible = v;
  instance.notifyChange(axisGrid);
});
bindToggle("origin", (v) => {
  axisGrid.origin = v ? TickOrigin.Relative : TickOrigin.Absolute;
  axisGrid.refresh();
  instance.notifyChange(axisGrid);
});
bindToggle("ceiling", (v) => {
  axisGrid.showCeilingGrid = v;
  instance.notifyChange(axisGrid);
});
bindToggle("floor", (v) => {
  axisGrid.showFloorGrid = v;
  instance.notifyChange(axisGrid);
});
bindToggle("sides", (v) => {
  axisGrid.showSideGrids = v;
  instance.notifyChange(axisGrid);
});
bindToggle("adaptive-labels", (v) => {
  axisGrid.adaptiveLabels = v;
  instance.notifyChange(axisGrid);
});
bindToggle("custom-css", (v) => {
  params.useCustomCss = v;
  axisGrid.refresh();
  instance.notifyChange(axisGrid);
});

document.getElementById("randomize-position").onclick = () => {
  const current = axisGrid.volume.extent;
  const dims = current.dimensions();
  const center = current.centerAsVector3();
  const range = 5000;
  center.set(
    center.x + (Math.random() - 0.5) * range,
    center.y + (Math.random() - 0.5) * range,
    0,
  );
  const newExtent = new Extent(
    current.crs,
    center.x - dims.x / 2,
    center.x + dims.x / 2,
    center.y - dims.y / 2,
    center.y + dims.y / 2,
  );

  axisGrid.volume.extent = newExtent;
  axisGrid.refresh();
  instance.notifyChange(axisGrid);
};

Inspector.attach("inspector", instance);
index.html
<!doctype html>
<html lang="en">
  <head>
    <title>AxisGrid</title>
    <meta charset="UTF-8" />
    <meta name="name" content="axisgrid" />
    <meta
      name="description"
      content="Illustrates the use of the AxisGrid entity."
    />
    <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">
            <div class="row">
              <div class="col-auto">Color</div>
              <div class="col">
                <input
                  type="color"
                  class="form-control form-control-color float-end h-100 w-100"
                  id="color"
                  value="#ffffff"
                  title="color"
                  autocomplete="off"
                />
              </div>
            </div>
          </label>

          <!-- Show/Hide AxisGrid -->
          <div class="form-check form-switch">
            <input
              class="form-check-input"
              type="checkbox"
              checked="true"
              role="switch"
              id="entity"
              autocomplete="off"
            />
            <label class="form-check-label" for="entity">Show axis grid</label>
          </div>

          <!-- Toggle adaptive labels -->
          <div class="form-check form-switch">
            <input
              class="form-check-input"
              type="checkbox"
              role="switch"
              id="adaptive-labels"
              autocomplete="off"
            />
            <label class="form-check-label" for="adaptive-labels"
              >Adaptive labels
              <span
                class="text-secondary"
                data-bs-toggle="popover"
                data-bs-content="help"
                ><i class="bi bi-question-circle"></i></span
            ></label>

            <p class="card-text d-none" id="help">
              <b>Adaptive labels</b> are displayed at the intersection of grid
              lines and the viewport's edges.
            </p>
          </div>

          <!-- Toggle custom CSS labels -->
          <div class="form-check form-switch">
            <input
              class="form-check-input"
              type="checkbox"
              role="switch"
              id="custom-css"
              autocomplete="off"
            />
            <label class="form-check-label" for="custom-css"
              >Use custom CSS
              <span
                class="text-secondary"
                data-bs-toggle="popover"
                data-bs-content="help-custom-css"
                ><i class="bi bi-question-circle"></i></span
            ></label>

            <p class="card-text d-none" id="help-custom-css">
              Use the <code>label-created</code> event to customize the DOM
              element of labels.
            </p>
          </div>

          <!-- Absolute/Relative -->
          <div class="form-check form-switch">
            <input
              class="form-check-input"
              type="checkbox"
              checked="true"
              role="switch"
              id="origin"
              autocomplete="off"
            />
            <label class="form-check-label" for="origin"
              >Relative origin
              <span
                class="text-secondary"
                data-bs-toggle="popover"
                data-bs-content="help-origin"
                ><i class="bi bi-question-circle"></i></span
            ></label>

            <p class="card-text d-none" id="help-origin">
              If enabled, the ticks start at the lower-left (south-west) corner
              of the grid. If disabled, the ticks start at the origin point of
              the coordinate system.
            </p>
          </div>

          <!-- Show/Hide ceiling -->
          <div class="form-check form-switch">
            <input
              class="form-check-input"
              type="checkbox"
              checked="true"
              role="switch"
              id="ceiling"
              autocomplete="off"
            />
            <label class="form-check-label" for="ceiling">Show ceiling</label>
          </div>

          <!-- Show/Hide floor -->
          <div class="form-check form-switch">
            <input
              class="form-check-input"
              type="checkbox"
              checked="true"
              role="switch"
              id="floor"
              autocomplete="off"
            />
            <label class="form-check-label" for="floor">Show floor</label>
          </div>

          <!-- Show/Hide sides -->
          <div class="form-check form-switch">
            <input
              class="form-check-input"
              type="checkbox"
              checked="true"
              role="switch"
              id="sides"
              autocomplete="off"
            />
            <label class="form-check-label" for="sides">Show sides</label>
          </div>

          <div class="my-2"></div>

          <!-- X step -->
          <label for="x-axis-step" class="form-label">X axis step</label>
          <div class="input-group">
            <input
              type="number"
              min="100"
              max="3000"
              class="form-control"
              value="1000"
              step="100"
              id="x-axis-step"
              autocomplete="off"
            />
          </div>

          <div class="my-2"></div>

          <!-- Y step -->
          <label for="y-axis-step" class="form-label">Y axis step</label>
          <div class="input-group">
            <input
              type="number"
              min="100"
              max="3000"
              value="1000"
              step="100"
              class="form-control"
              id="y-axis-step"
              autocomplete="off"
            />
          </div>

          <div class="my-2"></div>

          <!-- Z step -->
          <label for="z-axis-step" class="form-label">Z axis step</label>
          <div class="input-group">
            <input
              type="number"
              min="100"
              max="3000"
              value="200"
              step="100"
              class="form-control"
              id="z-axis-step"
              autocomplete="off"
            />
          </div>

          <div class="my-4"></div>

          <!-- Randomize grid position -->
          <button
            type="button"
            class="btn btn-primary w-100"
            id="randomize-position"
          >
            <i class="bi bi-shuffle"></i>
            Randomize position
          </button>
        </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": "axisgrid",
    "dependencies": {
        "colormap": "^2.3.2",
        "@giro3d/giro3d": "0.42.4"
    },
    "devDependencies": {
        "vite": "^3.2.3"
    },
    "scripts": {
        "start": "vite",
        "build": "vite build"
    }
}