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';



// Defines geographic extent: CRS, min/max X, min/max Y
const extent = new Extent(
    'EPSG:3857',
    -20037508.342789244,
    20037508.342789244,
    -20037508.342789244,
    20037508.342789244,
);

// `viewerDiv` will contain Giro3D' rendering area (the canvas element)
const viewerDiv = document.getElementById('viewerDiv');

// Creates a Giro3D instance
const instance = new Instance(viewerDiv, {
    crs: extent.crs(),
    renderer: {
        clearColor: 0x0a3b59,
    },
});

// Instanciates camera
instance.camera.camera3D.position.set(0, 0, 25000000);

// Instanciates controls
const controls = new MapControls(instance.camera.camera3D, instance.domElement);

instance.useTHREEControls(controls);

Inspector.attach(document.getElementById('panelDiv'), instance);


function bindSlider(name, callback) {
    const slider = document.getElementById(name);
    slider.oninput = function oninput() {
        callback(slider.value);
    };
}

function bindToggle(name, callback) {
    const toggle = document.getElementById(name);
    toggle.oninput = () => {
        const state = toggle.checked;
        callback(state);
    };
}

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;
/** @type {Map} */
let map = null;

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

    // Creates a map that will contain the layer
    map = new Map('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>
  <meta charset="UTF-8">
  <title>Giro3D - Color layer stress test</title>
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
  <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL" crossorigin="anonymous"></script>
  <style>
    body {
      padding: 0;
      margin: 0;
      width: 100vw;
      height: 100vh;
    }

    #viewerDiv {
      width: 100%;
      height: 100%;
    }

    #panelDiv {
      position: absolute;
      top: 0;
      left: 0;
    }
    
  </style>
</head>

<body>
  <div id="viewerDiv"></div>
  <div id="panelDiv"></div>
  <div class="m-2 position-absolute top-0 end-0">
    <div class="card m-1">
        <div class="card-header">Parameters</div>

        <div class="card-body">
            <fieldset class="container m-1">
                <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>
            </fieldset>
        </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.36.0",
    "colormap": "^2.3.2",
    "@turf/turf": "^6.5.0"
  },
  "devDependencies": {
    "vite": "^3.2.3"
  },
  "scripts": {
    "start": "vite",
    "build": "vite build"
  }
}