UNPKG

mobility-toolbox-js

Version:

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

51 lines (50 loc) 2.09 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 */ export default class MaplibreLayerRenderer extends MapLibreLayerRenderer { constructor(layer, translateZoom) { super(layer, translateZoom); this.ignoreNextRender = false; this.tranaslateZoom2 = translateZoom; this.setIsReady = this.setIsReady.bind(this); this.ignoreNextRender = false; } prepareFrame() { return true; } 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 void (mapLibreMap === null || mapLibreMap === void 0 ? void 0 : mapLibreMap.once('idle', this.setIsReady.bind(this))); return container; } setIsReady() { if (!this.ready) { this.ready = true; this.ignoreNextRender = true; this.getLayer().changed(); } } updateReadyState() { var _a, _b, _c, _d; void ((_b = (_a = this.getLayer()) === null || _a === void 0 ? void 0 : _a.mapLibreMap) === null || _b === void 0 ? void 0 : _b.off('idle', this.setIsReady.bind(this))); void ((_d = (_c = this.getLayer()) === null || _c === void 0 ? void 0 : _c.mapLibreMap) === null || _d === void 0 ? void 0 : _d.once('idle', this.setIsReady.bind(this))); } }