UNPKG

mobility-toolbox-js

Version:

Toolbox for JavaScript applications in the domains of mobility and logistics.

48 lines (47 loc) 1.98 kB
import { MapLibreLayerRenderer } from '@geoblocks/ol-maplibre-layer/lib'; // /** // * This class is usea renderer for Maplibre Layer to be able to use the native ol // * functionnalities like map.getFeaturesAtPixel or map.hasFeatureAtPixel. // * @private // */ // // @ts-expect-error export default class MaplibreLayerRenderer extends MapLibreLayerRenderer { constructor(layer, translateZoom) { super(layer, translateZoom); this.ignoreNextRender = false; this.setIsReady = this.setIsReady.bind(this); this.ignoreNextRender = false; } renderFrame(frameState) { const layer = this.getLayer(); const { mapLibreMap } = layer; const map = layer.getMapInternal(); if (!layer || !map || !mapLibreMap) { // @ts-expect-error - can return null return null; } if (this.ready && this.ignoreNextRender) { this.ignoreNextRender = false; return mapLibreMap === null || mapLibreMap === void 0 ? void 0 : mapLibreMap.getContainer(); } this.ready = false; this.ignoreNextRender = false; this.updateReadyState(); const container = super.renderFrame(frameState); // Mark the renderer as ready when the map is idle mapLibreMap === null || mapLibreMap === void 0 ? void 0 : mapLibreMap.once('idle', this.setIsReady); return container; } setIsReady() { if (!this.ready) { this.ready = true; this.ignoreNextRender = true; this.getLayer().changed(); } } updateReadyState() { var _a, _b, _c, _d; (_b = (_a = this.getLayer()) === null || _a === void 0 ? void 0 : _a.mapLibreMap) === null || _b === void 0 ? void 0 : _b.off('idle', this.setIsReady); (_d = (_c = this.getLayer()) === null || _c === void 0 ? void 0 : _c.mapLibreMap) === null || _d === void 0 ? void 0 : _d.once('idle', this.setIsReady); } }