Stress test a map with many color layers.

Parameters
100%
index.js
import { Color, MathUtils } from "three";
import { MapControls } from "three/examples/jsm/controls/MapControls.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 Inspector from "@giro3d/giro3d/gui/Inspector.js";
import DebugSource from "@giro3d/giro3d/sources/DebugSource.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];
}

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

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

instance.view.camera.position.set(0, 0, 25000000);

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

instance.view.setControls(controls);

Inspector.attach("inspector", instance);

function createColorLayer() {
  const source = new DebugSource({
    color: new Color().setHSL(Math.random(), 0.5, 0.5),
    extent,
    subdivisions: MathUtils.randInt(1, 4),
  });

  return new ColorLayer({ extent, source, showTileBorders: true });
}

let layerCount = 8;
let forceTextureAtlases = false;

let map = null;

function buildMapAndLayers() {
  if (map) {
    for (const layer of map.getLayers()) {
      map.removeLayer(layer, { disposeLayer: true });
    }
    instance.remove(map);
  }

  map = new Map({ extent, forceTextureAtlases });

  instance.add(map);

  for (let i = 0; i < layerCount; i++) {
    map.addLayer(createColorLayer());
  }
}

bindSlider("layerCount", (count) => {
  layerCount = count;
});

bindToggle("forceAtlases", (force) => {
  forceTextureAtlases = force;
});

document.getElementById("build").onclick = () => buildMapAndLayers();
index.html
<!doctype html>
<html lang="en">
  <head>
    <title>Color layer stress test</title>
    <meta charset="UTF-8" />
    <meta name="name" content="layer_stress_test" />
    <meta
      name="description"
      content="Stress test a map with many color layers."
    />
    <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">
          <div class="mb-3">
            <label for="layerCount" class="form-label">Color layer count</label>
            <div class="input-group">
              <input
                type="number"
                min="0"
                max="100"
                autocomplete="off"
                value="8"
                class="form-control"
                id="layerCount"
              />
            </div>
          </div>

          <div class="form-check form-switch mb-3">
            <input
              class="form-check-input"
              type="checkbox"
              autocomplete="off"
              role="switch"
              id="forceAtlases"
            />
            <label class="form-check-label" for="forceAtlases"
              >Force texture atlases</label
            >
          </div>

          <button type="button" class="btn btn-primary" id="build">
            Generate
          </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": "layer_stress_test",
    "dependencies": {
        "@giro3d/giro3d": "0.40.0"
    },
    "devDependencies": {
        "vite": "^3.2.3"
    },
    "scripts": {
        "start": "vite",
        "build": "vite build"
    }
}