Interactive interface for browsing global, full-resolution satellite imagery
WV-3066 - Openlayers v10 Support (#6031)
christof-wittreichecdf8641c46f
diff --git a/package-lock.json b/package-lock.jsonindex 34a16bb55..aba05d06a 100644--- a/package-lock.json+++ b/package-lock.json@@ -41,7 +41,7 @@"moment": "^2.30.1","moment-locales-webpack-plugin": "^1.2.0","node-dir": "^0.1.17",- "ol": "^8.2.0",+ "ol": "^10.6.1","ol-mapbox-style": "^12.6.1","p-queue": "^8.1.0","proj4": "^2.19.10",@@ -4446,6 +4446,12 @@"dev": true,"license": "MIT"},+ "node_modules/@types/rbush": {+ "version": "4.0.0",+ "resolved": "https://registry.npmjs.org/@types/rbush/-/rbush-4.0.0.tgz",+ "integrity": "sha512-+N+2H39P8X+Hy1I5mC6awlTX54k3FhiUmvt7HWzGJZvF+syUAAxP/stwppS8JE84YHqFgRMv6fCy31202CMFxQ==",+ "license": "MIT"+ },"node_modules/@types/react": {"version": "19.1.7","license": "MIT",@@ -6164,32 +6170,6 @@"version": "1.1.4","license": "MIT"},- "node_modules/color-parse": {- "version": "2.0.2",- "license": "MIT",- "dependencies": {- "color-name": "^2.0.0"- }- },- "node_modules/color-parse/node_modules/color-name": {- "version": "2.0.0",- "license": "MIT",- "engines": {- "node": ">=12.20"- }- },- "node_modules/color-rgba": {- "version": "3.0.0",- "license": "MIT",- "dependencies": {- "color-parse": "^2.0.0",- "color-space": "^2.0.0"- }- },- "node_modules/color-space": {- "version": "2.3.2",- "license": "Unlicense"- },"node_modules/colord": {"version": "2.9.3","dev": true,@@ -7249,7 +7229,9 @@"license": "MIT"},"node_modules/earcut": {- "version": "2.2.4",+ "version": "3.0.2",+ "resolved": "https://registry.npmjs.org/earcut/-/earcut-3.0.2.tgz",+ "integrity": "sha512-X7hshQbLyMJ/3RPhyObLARM2sNxxmRALLKx1+NVFFnQ9gKzmCrxm9+uLIAdBcvc8FNLpctqlQ2V6AE92Ol9UDQ==","license": "ISC"},"node_modules/eastasianwidth": {@@ -9609,24 +9591,6 @@"postcss": "^8.1.0"}},- "node_modules/ieee754": {- "version": "1.2.1",- "funding": [- {- "type": "github",- "url": "https://github.com/sponsors/feross"- },- {- "type": "patreon",- "url": "https://www.patreon.com/feross"- },- {- "type": "consulting",- "url": "https://feross.org/support"- }- ],- "license": "BSD-3-Clause"- },"node_modules/ignore": {"version": "5.3.2","license": "MIT",@@ -13873,15 +13837,16 @@"license": "MIT"},"node_modules/ol": {- "version": "8.2.0",+ "version": "10.6.1",+ "resolved": "https://registry.npmjs.org/ol/-/ol-10.6.1.tgz",+ "integrity": "sha512-xp174YOwPeLj7c7/8TCIEHQ4d41tgTDDhdv6SqNdySsql5/MaFJEJkjlsYcvOPt7xA6vrum/QG4UdJ0iCGT1cg==","license": "BSD-2-Clause","dependencies": {- "color-rgba": "^3.0.0",- "color-space": "^2.0.1",- "earcut": "^2.2.3",- "geotiff": "^2.0.7",- "pbf": "3.2.1",- "rbush": "^3.0.1"+ "@types/rbush": "4.0.0",+ "earcut": "^3.0.0",+ "geotiff": "^2.1.3",+ "pbf": "4.0.1",+ "rbush": "^4.0.0"},"funding": {"type": "opencollective",@@ -14310,10 +14275,11 @@}},"node_modules/pbf": {- "version": "3.2.1",+ "version": "4.0.1",+ "resolved": "https://registry.npmjs.org/pbf/-/pbf-4.0.1.tgz",+ "integrity": "sha512-SuLdBvS42z33m8ejRbInMapQe8n0D3vN/Xd5fmWM3tufNgRQFBpaW2YVJxQZV4iPNqb0vEFvssMEo5w9c6BTIA==","license": "BSD-3-Clause","dependencies": {- "ieee754": "^1.1.12","resolve-protobuf-schema": "^2.1.0"},"bin": {@@ -15334,16 +15300,14 @@}},"node_modules/rbush": {- "version": "3.0.1",+ "version": "4.0.1",+ "resolved": "https://registry.npmjs.org/rbush/-/rbush-4.0.1.tgz",+ "integrity": "sha512-IP0UpfeWQujYC8Jg162rMNc01Rf0gWMMAb2Uxus/Q0qOFw4lCcq6ZnQEZwUoJqWyUGJ9th7JjwI4yIWo+uvoAQ==","license": "MIT","dependencies": {- "quickselect": "^2.0.0"+ "quickselect": "^3.0.0"}},- "node_modules/rbush/node_modules/quickselect": {- "version": "2.0.0",- "license": "ISC"- },"node_modules/rc-pagination": {"version": "4.3.0","license": "MIT",diff --git a/package.json b/package.jsonindex 2a92a4631..187f5a5ed 100644--- a/package.json+++ b/package.json@@ -177,7 +177,7 @@"moment": "^2.30.1","moment-locales-webpack-plugin": "^1.2.0","node-dir": "^0.1.17",- "ol": "^8.2.0",+ "ol": "^10.6.1","ol-mapbox-style": "^12.6.1","p-queue": "^8.1.0","proj4": "^2.19.10",diff --git a/web/js/components/animation-widget/play-queue.js b/web/js/components/animation-widget/play-queue.jsindex 58eb50144..e80fbf20e 100644--- a/web/js/components/animation-widget/play-queue.js+++ b/web/js/components/animation-widget/play-queue.js@@ -186,37 +186,6 @@ class PlayQueue extends React.Component {getAverageFetchTime = () => this.fetchTimes.reduce((a, b) => a + b) / this.fetchTimes.length;- calcBufferSize() {- const { numberOfFrames, speed } = this.props;- let bufferSize = 0;- const msPerSec = 1000;- const avgFetchTime = this.getAverageFetchTime();- const remainingFrames = numberOfFrames - this.initialBufferSize;- const remainingLoadTime = avgFetchTime * remainingFrames;- const remainingPlayTime = (remainingFrames / speed) * msPerSec;- const totalPlayTime = (numberOfFrames / speed) * msPerSec;- const timeToBufferEnd = totalPlayTime - remainingPlayTime;- const framesLoadedDuringInitialBufferPlayback = timeToBufferEnd / avgFetchTime;- const canKeepUp = framesLoadedDuringInitialBufferPlayback >= this.initialBufferSize;-- if (!canKeepUp && remainingLoadTime >= remainingPlayTime) {- const preloadTime = remainingLoadTime - remainingPlayTime;- bufferSize = Math.ceil(preloadTime / msPerSec);- }-- // const totalLoadTime = ((avgFetchTime * numberOfFrames) / msPerSec / CONCURRENT_REQUESTS).toFixed(2);- // console.debug('Total frames: ', numberOfFrames);- // console.debug('Avg fetch time: ', (avgFetchTime / msPerSec).toFixed(2));- // console.debug('Play time (t/r): ', (totalPlayTime / msPerSec).toFixed(2), (remainingPlayTime / msPerSec).toFixed(2));- // console.debug('Load time (t/r): ', totalLoadTime, (remainingLoadTime / msPerSec).toFixed(2));-- const totalBuffer = bufferSize + this.initialBufferSize;- if (totalBuffer >= numberOfFrames) {- return numberOfFrames;- }- return totalBuffer;- }-isPreloadSufficient() {const { numberOfFrames } = this.props;const currentBufferSize = util.objectLength(this.bufferObject);@@ -230,11 +199,7 @@ class PlayQueue extends React.Component {this.checkQueue();return false;}- if (!this.minBufferLength) {- this.minBufferLength = this.calcBufferSize();- }- // console.debug(`Buffer: ${currentBufferSize} / ${this.minBufferLength}`);- return currentBufferSize >= this.minBufferLength;+ return false;}checkShouldPlay = function(loopStart) {@@ -348,18 +313,19 @@ class PlayQueue extends React.Component {const fetchTime = elapsedTime >= MIN_REQUEST_TIME_MS ? elapsedTime : MIN_REQUEST_TIME_MS;this.fetchTimes.push(fetchTime);this.setState({ loadedItems: loadedItems += 1 });- return strDate;- });- if (!this.mounted) return;- this.bufferObject[strDate] = strDate;- delete this.inQueueObject[strDate];- const currentBufferSize = util.objectLength(this.bufferObject);+ if (!this.mounted) return;+ this.bufferObject[strDate] = strDate;+ delete this.inQueueObject[strDate];+ const currentBufferSize = util.objectLength(this.bufferObject);- if (!initialLoad || this.canPreloadAll || currentBufferSize >= this.initialBufferSize) {- this.checkQueue();- this.checkShouldPlay();- }+ if (!initialLoad || this.canPreloadAll || currentBufferSize >= this.initialBufferSize) {+ this.checkQueue();+ this.checkShouldPlay();+ }++ return strDate;+ });}play() {diff --git a/web/js/modules/map/util.js b/web/js/modules/map/util.jsindex 3a9117738..65b00aa2d 100644--- a/web/js/modules/map/util.js+++ b/web/js/modules/map/util.js@@ -1,5 +1,6 @@import * as olExtent from 'ol/extent';import ImageLayer from 'ol/layer/Image';+import OlMap from 'ol/Map';import {each as lodashEach,isUndefined as lodashIsUndefined,@@ -7,7 +8,6 @@ import {get as lodashGet,isEqual as lodashIsEqual,} from 'lodash';-import OlRendererCanvasTileLayer from 'ol/renderer/canvas/TileLayer';import Promise from 'bluebird';import { encode } from '../link/util';import { getActiveVisibleLayersAtDate } from '../layers/selectors';@@ -146,110 +146,53 @@ export function getMapParameterSetup(};}-/**- * Calculate the current extent from the map's extent (boundaries) &- * the viewport extent (boundaries).- *- * @method calculateExtent- * @param {array} layerExtent The layer extent- * @param {array} map The current map- * @return {array} An extent array. Used to calculate- * the extent for prev, next & current day- */-function calculateExtent(layerExtent, map) {- const viewportExtent = map.getView().calculateExtent();- const visibleExtent = olExtent.getIntersection(viewportExtent, layerExtent);-- if (map.proj === 'geographic') {- if (layerExtent[1] < -180) {- // Previous day- visibleExtent[1] += 360;- visibleExtent[3] += 360;- } else if (layerExtent[1] > 180) {- // Next day- visibleExtent[1] -= 360;- visibleExtent[3] -= 360;- }- }-- // eslint-disable-next-line no-restricted-globals- if (!isFinite(visibleExtent[0])) {- return null;- }- return visibleExtent;-}+let preloadMap;/**- * Returns a promise of the layer tilegrid.+ * Adds the passed layer to a preloadMap, which is an invisible copy of our main OlMap+ * The layer is then removed once it is fully loaded on the preloadMap+ * This is done so because new version of OpenLayers (>= v10.2.x) no longer work properly with+ * displaying layers instantly on-screen during an animation with just pre-loading the tiles, and now+ * the layers themselves must have been rendered on an OlMap before animation to achieve the same results.** @method promiseTileLayer* @param {object} layer _ol_layer_Tile_- * @param {array} extent An array of map boundaries [180, -90, 250, 90]- * @param {object} viewState Contains center, projection, resolution, rotation and zoom parameters- * @param {number} pixelRatio The window.devicePixelRatio, used to detect retina displays+ * @param {object} map _ol_Map_* @return {object} promise*/-function promiseTileLayer(layer, extent, map) {- let tileSource;- let currentZ;- let i;- let tileGrid;+function promiseTileLayer(layer, map) {+ let i = 0;+ return new Promise((resolve) => {+ if (!preloadMap) {+ const mapContainerEl = document.getElementById('wv-map');+ const mapEl = document.createElement('div');+ const id = 'wv-map-preload';- return new Promise((resolve, reject) => {- if (!extent) {- resolve('resolve tile layer');- return;- }- // OL object describing the current map frame- const { pixelRatio, viewState } = map.frameState_;- const { projection, resolution } = viewState;- const { zDirection } = new OlRendererCanvasTileLayer(layer);- tileSource = layer.getSource();- tileGrid = tileSource.getTileGridForProjection(projection);- currentZ = tileGrid.getZForResolution(resolution, zDirection);- i = 0;+ mapEl.setAttribute('id', id);+ mapEl.style.display = 'none';+ mapContainerEl.insertAdjacentElement('afterbegin', mapEl);+ preloadMap = new OlMap({+ view: map.getView(),+ target: id,+ });+ }const onLoad = function onLoad (e) {- if (e.type === 'tileloadend') {- i -= 1;- if (i === 0) {- // eslint-disable-next-line no-use-before-define- complete();- }- } else {- // eslint-disable-next-line no-console- console.error(`No response for tile request ${layer.wv.key}`);- // some gibs data is not accurate and rejecting here- // will break the animation if tile doesn't exist- // eslint-disable-next-line no-use-before-define- complete();+ i -= 1;+ preloadMap.removeLayer(layer);+ if (i === 0) {+ preloadMap.un('loadend', onLoad);+ resolve();}};- const complete = function () {- tileSource.un('tileloadend', onLoad);- tileSource.un('tileloaderror', onLoad);- resolve();- };-- const loadTile = function ([one, two, three]) {- const tile = tileSource.getTile(one, two, three, pixelRatio, projection);- try {- tile.load();- } catch (e) {- // eslint-disable-next-line no-console- console.error(`Could not load tile with coords: [${one}, ${two}, ${three}] for extent [${extent}]`);- // eslint-disable-next-line no-console- console.error(e);- }- if (tile.state === 2) resolve();+ if (!preloadMap.getLayers().getArray().includes(layer)) {i += 1;- tileSource.on('tileloadend', onLoad);- tileSource.on('tileloaderror', onLoad);- };-- tileGrid.forEachTileCoord(extent, currentZ, loadTile);+ preloadMap.addLayer(layer);+ layer.setVisible(true);+ preloadMap.on('loadend', onLoad);+ }});}@@ -272,9 +215,7 @@ function promiseLayerGroup(layerGroup, map) {const layerPromiseArray = layers.map((layer) => {// TODO #3688 figure out why vector layers cause preloadinig issuesif (layer.isVector || layer instanceof ImageLayer) return Promise.resolve();- const layerExtent = layer.getExtent();- const extent = calculateExtent(layerExtent, map);- return promiseTileLayer(layer, extent, map);+ return promiseTileLayer(layer, map);});Promise.all(layerPromiseArray).then(resolve);@@ -300,8 +241,11 @@ export async function promiseImageryForTime(state, date, activeString) {}const options = { date, group: activeString };const key = layerKey(layer, options, state);- const layerGroup = cache.getItem(key) || await createLayer(layer, options);- return promiseLayerGroup(layerGroup, selected);+ const cachedItem = cache.getItem(key);+ const layerGroup = cachedItem || await createLayer(layer, options);+ if (!cachedItem) {+ return promiseLayerGroup(layerGroup, selected);+ }}));selected.getView().changed();return date;diff --git a/web/scss/features/map.scss b/web/scss/features/map.scssindex c6e2647c7..3a56ef0ea 100644--- a/web/scss/features/map.scss+++ b/web/scss/features/map.scss@@ -1,6 +1,6 @@@use "variables";-.wv-map {+.wv-map, #wv-map-preload {position: absolute;margin: 0;padding: 0;@@ -8,6 +8,11 @@z-index: 0;}+#wv-map-preload {+ display: block !important;+ visibility: hidden;+}+.wv-map-zoom {position: absolute;right: 0;