Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

WV-2333: Upgrade to latest ol and ol-mapbox-style (#3936)

Jason Kentcd1ac50ff8d4
diff --git a/package-lock.json b/package-lock.json
index f3b62ecb2..2e2e8d11a 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -36,8 +36,8 @@
"moment": "^2.29.4",
"moment-locales-webpack-plugin": "^1.1.2",
"node-dir": "^0.1.17",
- "ol": "6.4.x",
- "ol-mapbox-style": "6.1.x",
+ "ol": "7.0.0",
+ "ol-mapbox-style": "9.1.0",
"p-queue": "^7.1.0",
"proj4": "2.6.1",
"promise-queue": "2.2.5",
@@ -2705,30 +2705,6 @@
"node": ">=6.0.0"
}
},
- "node_modules/@jridgewell/source-map": {
- "version": "0.3.2",
- "resolved": "https://registry.npmjs.org/@jridgewell/source-map/-/source-map-0.3.2.tgz",
- "integrity": "sha512-m7O9o2uR8k2ObDysZYzdfhb08VuEml5oWGiosa1VdaPZ/A6QyPkAJuwN0Q1lhULOf6B7MtQmHENS743hWtCrgw==",
- "dev": true,
- "dependencies": {
- "@jridgewell/gen-mapping": "^0.3.0",
- "@jridgewell/trace-mapping": "^0.3.9"
- }
- },
- "node_modules/@jridgewell/source-map/node_modules/@jridgewell/gen-mapping": {
- "version": "0.3.2",
- "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.2.tgz",
- "integrity": "sha512-mh65xKQAzI6iBcFzwv28KVWSmCkdRBWoOh+bYQGW3+6OZvbbN3TqMGo5hqYxQniRcH9F2VZIoJCm4pa3BPDK/A==",
- "dev": true,
- "dependencies": {
- "@jridgewell/set-array": "^1.0.1",
- "@jridgewell/sourcemap-codec": "^1.4.10",
- "@jridgewell/trace-mapping": "^0.3.9"
- },
- "engines": {
- "node": ">=6.0.0"
- }
- },
"node_modules/@jridgewell/sourcemap-codec": {
"version": "1.4.11",
"dev": true,
@@ -2761,7 +2737,7 @@
}
},
"node_modules/@mapbox/mapbox-gl-style-spec": {
- "version": "13.24.0",
+ "version": "13.25.0",
"license": "ISC",
"dependencies": {
"@mapbox/jsonlint-lines-primitives": "~2.0.2",
@@ -2866,6 +2842,10 @@
"node": ">=10"
}
},
+ "node_modules/@petamoriken/float16": {
+ "version": "3.6.5",
+ "license": "MIT"
+ },
"node_modules/@pmmmwh/react-refresh-webpack-plugin": {
"version": "0.5.5",
"dev": true,
@@ -5082,18 +5062,17 @@
},
"node_modules/chromedriver": {
"version": "104.0.0",
- "resolved": "https://registry.npmjs.org/chromedriver/-/chromedriver-104.0.0.tgz",
- "integrity": "sha512-zbHZutN2ATo19xA6nXwwLn+KueD/5w8ap5m4b6bCb8MIaRFnyDwMbFoy7oFAjlSMpCFL3KSaZRiWUwjj//N3yQ==",
"dev": true,
"hasInstallScript": true,
+ "license": "Apache-2.0",
"dependencies": {
- "@testim/chrome-version": "^1.1.2",
- "axios": "^0.27.2",
- "del": "^6.0.0",
- "extract-zip": "^2.0.1",
- "https-proxy-agent": "^5.0.0",
- "proxy-from-env": "^1.1.0",
- "tcp-port-used": "^1.0.1"
+ "@testim/chrome-version": "^1.1.2",
+ "axios": "^0.27.2",
+ "del": "^6.0.0",
+ "extract-zip": "^2.0.1",
+ "https-proxy-agent": "^5.0.0",
+ "proxy-from-env": "^1.1.0",
+ "tcp-port-used": "^1.0.1"
},
"bin": {
"chromedriver": "bin/chromedriver"
@@ -7332,6 +7311,10 @@
"stream-shift": "^1.0.0"
}
},
+ "node_modules/earcut": {
+ "version": "2.2.4",
+ "license": "ISC"
+ },
"node_modules/ecc-jsbn": {
"version": "0.1.2",
"dev": true,
@@ -9653,6 +9636,27 @@
"version": "1.52.0",
"license": "MIT"
},
+ "node_modules/geotiff": {
+ "version": "2.0.4",
+ "license": "MIT",
+ "dependencies": {
+ "@petamoriken/float16": "^3.4.7",
+ "lerc": "^3.0.0",
+ "lru-cache": "^6.0.0",
+ "pako": "^2.0.4",
+ "parse-headers": "^2.0.2",
+ "web-worker": "^1.2.0",
+ "xml-utils": "^1.0.2"
+ },
+ "engines": {
+ "browsers": "defaults",
+ "node": ">=10.19"
+ }
+ },
+ "node_modules/geotiff/node_modules/pako": {
+ "version": "2.0.4",
+ "license": "(MIT AND Zlib)"
+ },
"node_modules/get-caller-file": {
"version": "2.0.5",
"dev": true,
@@ -13633,6 +13637,10 @@
"webpack-sources": "^1.1.0"
}
},
+ "node_modules/lerc": {
+ "version": "3.0.0",
+ "license": "Apache-2.0"
+ },
"node_modules/leven": {
"version": "3.1.0",
"dev": true,
@@ -13906,7 +13914,6 @@
},
"node_modules/lru-cache": {
"version": "6.0.0",
- "dev": true,
"license": "ISC",
"dependencies": {
"yallist": "^4.0.0"
@@ -15592,10 +15599,12 @@
"license": "MIT"
},
"node_modules/ol": {
- "version": "6.4.3",
+ "version": "7.0.0",
"license": "BSD-2-Clause",
"dependencies": {
- "ol-mapbox-style": "^6.1.1",
+ "earcut": "^2.2.3",
+ "geotiff": "2.0.4",
+ "ol-mapbox-style": "9.0.0",
"pbf": "3.2.1",
"rbush": "^3.0.1"
},
@@ -15605,15 +15614,19 @@
}
},
"node_modules/ol-mapbox-style": {
- "version": "6.1.4",
+ "version": "9.1.0",
"license": "BSD-2-Clause",
"dependencies": {
- "@mapbox/mapbox-gl-style-spec": "^13.14.0",
- "mapbox-to-css-font": "^2.4.0",
- "webfont-matcher": "^1.1.0"
- },
- "peerDependencies": {
- "ol": "^6.1.0"
+ "@mapbox/mapbox-gl-style-spec": "^13.23.1",
+ "mapbox-to-css-font": "^2.4.1"
+ }
+ },
+ "node_modules/ol/node_modules/ol-mapbox-style": {
+ "version": "9.0.0",
+ "license": "BSD-2-Clause",
+ "dependencies": {
+ "@mapbox/mapbox-gl-style-spec": "^13.23.1",
+ "mapbox-to-css-font": "^2.4.1"
}
},
"node_modules/on-finished": {
@@ -16111,6 +16124,10 @@
"safe-buffer": "^5.1.1"
}
},
+ "node_modules/parse-headers": {
+ "version": "2.0.5",
+ "license": "MIT"
+ },
"node_modules/parse-json": {
"version": "4.0.0",
"dev": true,
@@ -23950,9 +23967,8 @@
}
},
"node_modules/terser": {
- "version": "4.8.1",
- "resolved": "https://registry.npmjs.org/terser/-/terser-4.8.1.tgz",
- "integrity": "sha512-4GnLC0x667eJG0ewJTa6z/yXrbLGv80D9Ru6HIpCQmO+Q4PfEtBFi0ObSckqwL6VyQv/7ENJieXHo2ANmdQwgw==",
+ "version": "4.8.0",
+ "license": "BSD-2-Clause",
"dependencies": {
"commander": "^2.20.0",
"source-map": "~0.6.1",
@@ -24016,14 +24032,13 @@
}
},
"node_modules/terser-webpack-plugin/node_modules/terser": {
- "version": "5.14.2",
- "resolved": "https://registry.npmjs.org/terser/-/terser-5.14.2.tgz",
- "integrity": "sha512-oL0rGeM/WFQCUd0y2QrWxYnq7tfSuKBiqTjRPWrRgB46WD/kiwHwF8T23z78H6Q6kGCuuHcPB+KULHRdxvVGQA==",
+ "version": "5.13.0",
"dev": true,
+ "license": "BSD-2-Clause",
"dependencies": {
- "@jridgewell/source-map": "^0.3.2",
"acorn": "^8.5.0",
"commander": "^2.20.0",
+ "source-map": "~0.8.0-beta.0",
"source-map-support": "~0.5.20"
},
"bin": {
@@ -24033,6 +24048,32 @@
"node": ">=10"
}
},
+ "node_modules/terser-webpack-plugin/node_modules/terser/node_modules/source-map": {
+ "version": "0.8.0-beta.0",
+ "dev": true,
+ "license": "BSD-3-Clause",
+ "dependencies": {
+ "whatwg-url": "^7.0.0"
+ },
+ "engines": {
+ "node": ">= 8"
+ }
+ },
+ "node_modules/terser-webpack-plugin/node_modules/webidl-conversions": {
+ "version": "4.0.2",
+ "dev": true,
+ "license": "BSD-2-Clause"
+ },
+ "node_modules/terser-webpack-plugin/node_modules/whatwg-url": {
+ "version": "7.1.0",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "lodash.sortby": "^4.7.0",
+ "tr46": "^1.0.1",
+ "webidl-conversions": "^4.0.2"
+ }
+ },
"node_modules/terser/node_modules/commander": {
"version": "2.20.3",
"license": "MIT"
@@ -25197,9 +25238,9 @@
"defaults": "^1.0.3"
}
},
- "node_modules/webfont-matcher": {
- "version": "1.1.0",
- "license": "MIT"
+ "node_modules/web-worker": {
+ "version": "1.2.0",
+ "license": "Apache-2.0"
},
"node_modules/webidl-conversions": {
"version": "6.1.0",
@@ -27040,6 +27081,10 @@
"dev": true,
"license": "Apache-2.0"
},
+ "node_modules/xml-utils": {
+ "version": "1.1.0",
+ "license": "CC0-1.0"
+ },
"node_modules/xmlchars": {
"version": "2.2.0",
"dev": true,
@@ -27070,7 +27115,6 @@
},
"node_modules/yallist": {
"version": "4.0.0",
- "dev": true,
"license": "ISC"
},
"node_modules/yaml": {
@@ -28960,29 +29004,6 @@
"version": "1.1.0",
"dev": true
},
- "@jridgewell/source-map": {
- "version": "0.3.2",
- "resolved": "https://registry.npmjs.org/@jridgewell/source-map/-/source-map-0.3.2.tgz",
- "integrity": "sha512-m7O9o2uR8k2ObDysZYzdfhb08VuEml5oWGiosa1VdaPZ/A6QyPkAJuwN0Q1lhULOf6B7MtQmHENS743hWtCrgw==",
- "dev": true,
- "requires": {
- "@jridgewell/gen-mapping": "^0.3.0",
- "@jridgewell/trace-mapping": "^0.3.9"
- },
- "dependencies": {
- "@jridgewell/gen-mapping": {
- "version": "0.3.2",
- "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.2.tgz",
- "integrity": "sha512-mh65xKQAzI6iBcFzwv28KVWSmCkdRBWoOh+bYQGW3+6OZvbbN3TqMGo5hqYxQniRcH9F2VZIoJCm4pa3BPDK/A==",
- "dev": true,
- "requires": {
- "@jridgewell/set-array": "^1.0.1",
- "@jridgewell/sourcemap-codec": "^1.4.10",
- "@jridgewell/trace-mapping": "^0.3.9"
- }
- }
- }
- },
"@jridgewell/sourcemap-codec": {
"version": "1.4.11",
"dev": true
@@ -29008,7 +29029,7 @@
"version": "2.0.2"
},
"@mapbox/mapbox-gl-style-spec": {
- "version": "13.24.0",
+ "version": "13.25.0",
"requires": {
"@mapbox/jsonlint-lines-primitives": "~2.0.2",
"@mapbox/point-geometry": "^0.1.0",
@@ -29077,6 +29098,9 @@
}
}
},
+ "@petamoriken/float16": {
+ "version": "3.6.5"
+ },
"@pmmmwh/react-refresh-webpack-plugin": {
"version": "0.5.5",
"dev": true,
@@ -30602,8 +30626,6 @@
},
"chromedriver": {
"version": "104.0.0",
- "resolved": "https://registry.npmjs.org/chromedriver/-/chromedriver-104.0.0.tgz",
- "integrity": "sha512-zbHZutN2ATo19xA6nXwwLn+KueD/5w8ap5m4b6bCb8MIaRFnyDwMbFoy7oFAjlSMpCFL3KSaZRiWUwjj//N3yQ==",
"dev": true,
"requires": {
"@testim/chrome-version": "^1.1.2",
@@ -32106,6 +32128,9 @@
"stream-shift": "^1.0.0"
}
},
+ "earcut": {
+ "version": "2.2.4"
+ },
"ecc-jsbn": {
"version": "0.1.2",
"dev": true,
@@ -33649,6 +33674,23 @@
"geographiclib": {
"version": "1.52.0"
},
+ "geotiff": {
+ "version": "2.0.4",
+ "requires": {
+ "@petamoriken/float16": "^3.4.7",
+ "lerc": "^3.0.0",
+ "lru-cache": "^6.0.0",
+ "pako": "^2.0.4",
+ "parse-headers": "^2.0.2",
+ "web-worker": "^1.2.0",
+ "xml-utils": "^1.0.2"
+ },
+ "dependencies": {
+ "pako": {
+ "version": "2.0.4"
+ }
+ }
+ },
"get-caller-file": {
"version": "2.0.5",
"dev": true
@@ -36211,6 +36253,9 @@
"webpack-sources": "^1.1.0"
}
},
+ "lerc": {
+ "version": "3.0.0"
+ },
"leven": {
"version": "3.1.0",
"dev": true
@@ -36408,7 +36453,6 @@
},
"lru-cache": {
"version": "6.0.0",
- "dev": true,
"requires": {
"yallist": "^4.0.0"
}
@@ -37531,19 +37575,29 @@
"dev": true
},
"ol": {
- "version": "6.4.3",
+ "version": "7.0.0",
"requires": {
- "ol-mapbox-style": "^6.1.1",
+ "earcut": "^2.2.3",
+ "geotiff": "2.0.4",
+ "ol-mapbox-style": "9.0.0",
"pbf": "3.2.1",
"rbush": "^3.0.1"
+ },
+ "dependencies": {
+ "ol-mapbox-style": {
+ "version": "9.0.0",
+ "requires": {
+ "@mapbox/mapbox-gl-style-spec": "^13.23.1",
+ "mapbox-to-css-font": "^2.4.1"
+ }
+ }
}
},
"ol-mapbox-style": {
- "version": "6.1.4",
+ "version": "9.1.0",
"requires": {
- "@mapbox/mapbox-gl-style-spec": "^13.14.0",
- "mapbox-to-css-font": "^2.4.0",
- "webfont-matcher": "^1.1.0"
+ "@mapbox/mapbox-gl-style-spec": "^13.23.1",
+ "mapbox-to-css-font": "^2.4.1"
}
},
"on-finished": {
@@ -37863,6 +37917,9 @@
"safe-buffer": "^5.1.1"
}
},
+ "parse-headers": {
+ "version": "2.0.5"
+ },
"parse-json": {
"version": "4.0.0",
"dev": true,
@@ -43101,9 +43158,7 @@
}
},
"terser": {
- "version": "4.8.1",
- "resolved": "https://registry.npmjs.org/terser/-/terser-4.8.1.tgz",
- "integrity": "sha512-4GnLC0x667eJG0ewJTa6z/yXrbLGv80D9Ru6HIpCQmO+Q4PfEtBFi0ObSckqwL6VyQv/7ENJieXHo2ANmdQwgw==",
+ "version": "4.8.0",
"requires": {
"commander": "^2.20.0",
"source-map": "~0.6.1",
@@ -43146,15 +43201,35 @@
"dev": true
},
"terser": {
- "version": "5.14.2",
- "resolved": "https://registry.npmjs.org/terser/-/terser-5.14.2.tgz",
- "integrity": "sha512-oL0rGeM/WFQCUd0y2QrWxYnq7tfSuKBiqTjRPWrRgB46WD/kiwHwF8T23z78H6Q6kGCuuHcPB+KULHRdxvVGQA==",
+ "version": "5.13.0",
"dev": true,
"requires": {
- "@jridgewell/source-map": "^0.3.2",
"acorn": "^8.5.0",
"commander": "^2.20.0",
+ "source-map": "~0.8.0-beta.0",
"source-map-support": "~0.5.20"
+ },
+ "dependencies": {
+ "source-map": {
+ "version": "0.8.0-beta.0",
+ "dev": true,
+ "requires": {
+ "whatwg-url": "^7.0.0"
+ }
+ }
+ }
+ },
+ "webidl-conversions": {
+ "version": "4.0.2",
+ "dev": true
+ },
+ "whatwg-url": {
+ "version": "7.1.0",
+ "dev": true,
+ "requires": {
+ "lodash.sortby": "^4.7.0",
+ "tr46": "^1.0.1",
+ "webidl-conversions": "^4.0.2"
}
}
}
@@ -43964,8 +44039,8 @@
"defaults": "^1.0.3"
}
},
- "webfont-matcher": {
- "version": "1.1.0"
+ "web-worker": {
+ "version": "1.2.0"
},
"webidl-conversions": {
"version": "6.1.0",
@@ -45224,6 +45299,9 @@
"version": "3.0.0",
"dev": true
},
+ "xml-utils": {
+ "version": "1.1.0"
+ },
"xmlchars": {
"version": "2.2.0",
"dev": true
@@ -45242,8 +45320,7 @@
"version": "4.0.3"
},
"yallist": {
- "version": "4.0.0",
- "dev": true
+ "version": "4.0.0"
},
"yaml": {
"version": "1.10.2"
diff --git a/package.json b/package.json
index 79f9ec0d8..75f324cb5 100644
--- a/package.json
+++ b/package.json
@@ -190,8 +190,8 @@
"moment": "^2.29.4",
"moment-locales-webpack-plugin": "^1.1.2",
"node-dir": "^0.1.17",
- "ol": "6.4.x",
- "ol-mapbox-style": "6.1.x",
+ "ol": "7.0.0",
+ "ol-mapbox-style": "9.1.0",
"p-queue": "^7.1.0",
"proj4": "2.6.1",
"promise-queue": "2.2.5",
@@ -245,7 +245,7 @@
"^googleTagManager$": "<rootDir>/web/js/components/util/google-tag-manager.js"
},
"transformIgnorePatterns": [
- "node_modules/(?!(ol|ol-mapbox-style|@mapbox)/)"
+ "node_modules/(?!(ol|ol-mapbox-style|quick-lru|geotiff|@mapbox)/)"
],
"modulePathIgnorePatterns": [
"<rootDir>/build/"
@@ -254,4 +254,4 @@
"prettier": {
"singleQuote": true
}
-}
\ No newline at end of file
+}
diff --git a/patches/ol-mapbox-style+6.1.4.patch b/patches/ol-mapbox-style+6.1.4.patch
deleted file mode 100644
index f6affc7a0..000000000
--- a/patches/ol-mapbox-style+6.1.4.patch
+++ /dev/null
@@ -1,1780 +0,0 @@
-diff --git a/node_modules/ol-mapbox-style/dist/stylefunction.js b/node_modules/ol-mapbox-style/dist/stylefunction.js
-index 473b267..edfa51f 100644
---- a/node_modules/ol-mapbox-style/dist/stylefunction.js
-+++ b/node_modules/ol-mapbox-style/dist/stylefunction.js
-@@ -3,6 +3,9 @@ ol-mapbox-style - Use Mapbox Style objects with OpenLayers
- Copyright 2016-present ol-mapbox-style contributors
- License: https://raw.githubusercontent.com/openlayers/ol-mapbox-style/master/LICENSE
- */
-+
-+
-+import * as olExtent from 'ol/extent';
- import Style from 'ol/style/Style';
- import Fill from 'ol/style/Fill';
- import Stroke from 'ol/style/Stroke';
-@@ -11,7 +14,13 @@ import Text from 'ol/style/Text';
- import Circle from 'ol/style/Circle';
- import RenderFeature from 'ol/render/Feature';
- import { derefLayers } from '@mapbox/mapbox-gl-style-spec';
--import { expression, Color, function as fn, latest as spec, featureFilter as createFilter } from '@mapbox/mapbox-gl-style-spec';
-+
-+import {
-+ expression, Color,
-+ function as fn,
-+ latest as spec,
-+ featureFilter as createFilter
-+} from '@mapbox/mapbox-gl-style-spec';
- import mb2css from 'mapbox-to-css-font';
- import { deg2rad, defaultResolutions, getZoomForResolution, wrapText, applyLetterSpacing, createCanvas } from './util';
- /**
-@@ -19,41 +28,63 @@ import { deg2rad, defaultResolutions, getZoomForResolution, wrapText, applyLette
- * @typedef {import("ol/layer/VectorTile").default} VectorTileLayer
- * @typedef {import("ol/style/Style").StyleFunction} StyleFunction
- */
--var isFunction = fn.isFunction;
--var convertFunction = fn.convertFunction;
--var isExpression = expression.isExpression;
--var createPropertyExpression = expression.createPropertyExpression;
--var types = {
-- 'Point': 1,
-- 'MultiPoint': 1,
-- 'LineString': 2,
-- 'MultiLineString': 2,
-- 'Polygon': 3,
-- 'MultiPolygon': 3
-+
-+const isFunction = fn.isFunction;
-+const convertFunction = fn.convertFunction;
-+const isExpression = expression.isExpression;
-+const createPropertyExpression = expression.createPropertyExpression;
-+
-+const types = {
-+ 'Point': 1,
-+ 'MultiPoint': 1,
-+ 'LineString': 2,
-+ 'MultiLineString': 2,
-+ 'Polygon': 3,
-+ 'MultiPolygon': 3
- };
--var anchor = {
-- 'center': [0.5, 0.5],
-- 'left': [0, 0.5],
-- 'right': [1, 0.5],
-- 'top': [0.5, 0],
-- 'bottom': [0.5, 1],
-- 'top-left': [0, 0],
-- 'top-right': [1, 0],
-- 'bottom-left': [0, 1],
-- 'bottom-right': [1, 1]
-+const anchor = {
-+ 'center': [0.5, 0.5],
-+ 'left': [0, 0.5],
-+ 'right': [1, 0.5],
-+ 'top': [0.5, 0],
-+ 'bottom': [0.5, 1],
-+ 'top-left': [0, 0],
-+ 'top-right': [1, 0],
-+ 'bottom-left': [0, 1],
-+ 'bottom-right': [1, 1]
- };
--var expressionData = function (rawExpression, propertySpec) {
-- var compiledExpression = createPropertyExpression(rawExpression, propertySpec);
-- if (compiledExpression.result === 'error') {
-- throw new Error(compiledExpression.value.map(function (err) { return err.key + ": " + err.message; }).join(', '));
-+
-+const containsCoordinates = function (layerExtent, pixels, olMap) {
-+ let bool = true;
-+ pixels.forEach(pixel => {
-+ if (!olExtent.containsCoordinate(layerExtent, olMap.getCoordinateFromPixel(pixel))) {
-+ bool = false;
-+ return
- }
-- return compiledExpression.value;
-+ });
-+ return bool;
-+}
-+const getTextWidth = function (text, font, canvas) {
-+ var context = canvas.getContext('2d');
-+ context.clearRect(0, 0, canvas.width, canvas.height);
-+ context.font = font;
-+ var metrics = context.measureText(text);
-+ return metrics.width;
-+};
-+const expressionData = function (rawExpression, propertySpec) {
-+ const compiledExpression = createPropertyExpression(rawExpression, propertySpec);
-+ if (compiledExpression.result === 'error') {
-+ throw new Error(compiledExpression.value.map(err => `${err.key}: ${err.message}`).join(', '));
-+ }
-+ return compiledExpression.value;
- };
--var emptyObj = {};
--var zoomObj = { zoom: 0 };
-+
-+const emptyObj = {};
-+const zoomObj = { zoom: 0 };
- /** @private */
--var functionCache = {};
--var renderFeatureCoordinates, renderFeature;
-+const functionCache = {};
-+let renderFeatureCoordinates, renderFeature;
-+
- /**
- * @private
- * @param {Object} layer Gl object layer.
-@@ -64,40 +95,41 @@ var renderFeatureCoordinates, renderFeature;
- * @return {?} Value.
- */
- export function getValue(layer, layoutOrPaint, property, zoom, feature) {
-- var layerId = layer.id;
-- if (!functionCache[layerId]) {
-- functionCache[layerId] = {};
-+ const layerId = layer.id;
-+ if (!functionCache[layerId]) {
-+ functionCache[layerId] = {};
-+ }
-+ const functions = functionCache[layerId];
-+ if (!functions[property]) {
-+ let value = (layer[layoutOrPaint] || emptyObj)[property];
-+ const propertySpec = spec[`${layoutOrPaint}_${layer.type}`][property];
-+ if (value === undefined) {
-+ value = propertySpec.default;
- }
-- var functions = functionCache[layerId];
-- if (!functions[property]) {
-- var value_1 = (layer[layoutOrPaint] || emptyObj)[property];
-- var propertySpec = spec[layoutOrPaint + "_" + layer.type][property];
-- if (value_1 === undefined) {
-- value_1 = propertySpec.default;
-- }
-- var isExpr = isExpression((value_1));
-- if (!isExpr && isFunction(value_1)) {
-- value_1 = convertFunction(value_1, propertySpec);
-- isExpr = true;
-- }
-- if (isExpr) {
-- var compiledExpression = expressionData(value_1, propertySpec);
-- functions[property] = compiledExpression.evaluate.bind(compiledExpression);
-- }
-- else {
-- if (propertySpec.type == 'color') {
-- value_1 = Color.parse(value_1);
-- }
-- functions[property] = function () {
-- return value_1;
-- };
-- }
-+ let isExpr = isExpression((value));
-+ if (!isExpr && isFunction(value)) {
-+ value = convertFunction(value, propertySpec);
-+ isExpr = true;
-+ }
-+ if (isExpr) {
-+ const compiledExpression = expressionData(value, propertySpec);
-+ functions[property] = compiledExpression.evaluate.bind(compiledExpression);
-+ } else {
-+ if (propertySpec.type == 'color') {
-+ value = Color.parse(value);
-+ }
-+ functions[property] = function () {
-+ return value;
-+ };
- }
-- zoomObj.zoom = zoom;
-- return functions[property](zoomObj, feature);
-+ }
-+ zoomObj.zoom = zoom;
-+ return functions[property](zoomObj, feature);
- }
-+
- /** @private */
--var filterCache = {};
-+const filterCache = {};
-+
- /**
- * @private
- * @param {string} layerId Layer id.
-@@ -107,12 +139,13 @@ var filterCache = {};
- * @return {boolean} Filter result.
- */
- function evaluateFilter(layerId, filter, feature, zoom) {
-- if (!(layerId in filterCache)) {
-- filterCache[layerId] = createFilter(filter).filter;
-- }
-- zoomObj.zoom = zoom;
-- return filterCache[layerId](zoomObj, feature);
-+ if (!(layerId in filterCache)) {
-+ filterCache[layerId] = createFilter(filter).filter;
-+ }
-+ zoomObj.zoom = zoom;
-+ return filterCache[layerId](zoomObj, feature);
- }
-+
- /**
- * @private
- * @param {?} color Color.
-@@ -120,18 +153,20 @@ function evaluateFilter(layerId, filter, feature, zoom) {
- * @return {string} Color.
- */
- function colorWithOpacity(color, opacity) {
-- if (color) {
-- if (color.a === 0 || opacity === 0) {
-- return undefined;
-- }
-- var a = color.a;
-- opacity = opacity === undefined ? 1 : opacity;
-- return 'rgba(' + Math.round(color.r * 255 / a) + ',' + Math.round(color.g * 255 / a) +
-- ',' + Math.round(color.b * 255 / a) + ',' + (a * opacity) + ')';
-+ if (color) {
-+ if (color.a === 0 || opacity === 0) {
-+ return undefined;
- }
-- return color;
-+ const a = color.a;
-+ opacity = opacity === undefined ? 1 : opacity;
-+ return 'rgba(' + Math.round(color.r * 255 / a) + ',' + Math.round(color.g * 255 / a) +
-+ ',' + Math.round(color.b * 255 / a) + ',' + (a * opacity) + ')';
-+ }
-+ return color;
- }
--var templateRegEx = /^([^]*)\{(.*)\}([^]*)$/;
-+
-+const templateRegEx = /^([^]*)\{(.*)\}([^]*)$/;
-+
- /**
- * @private
- * @param {string} text Text.
-@@ -139,16 +174,32 @@ var templateRegEx = /^([^]*)\{(.*)\}([^]*)$/;
- * @return {string} Text.
- */
- function fromTemplate(text, properties) {
-- var parts;
-- do {
-- parts = text.match(templateRegEx);
-- if (parts) {
-- var value = properties[parts[2]] || '';
-- text = parts[1] + value + parts[3];
-- }
-- } while (parts);
-- return text;
-+ let parts;
-+ do {
-+ parts = text.match(templateRegEx);
-+ if (parts) {
-+ const value = properties[parts[2]] || '';
-+ text = parts[1] + value + parts[3];
-+ }
-+ } while (parts);
-+ return text;
- }
-+
-+let recordLayer = false;
-+
-+/**
-+ * ```js
-+ * import {recordStyleLayer} from 'ol-mapbox-style/dist/stylefunction';
-+ * ```
-+ * Turns recording of the Mapbox Style's `layer` on and off. When turned on,
-+ * the layer that a rendered feature belongs to will be set as the feature's
-+ * `mapbox-layer` property.
-+ * @param {boolean} [record=false] Recording of the style layer is on.
-+ */
-+export function recordStyleLayer(record) {
-+ recordLayer = record;
-+}
-+
- /**
- * ```js
- * import stylefunction from 'ol-mapbox-style/dist/stylefunction';
-@@ -220,462 +271,572 @@ function fromTemplate(text, properties) {
- * @return {StyleFunction} Style function for use in
- * `ol.layer.Vector` or `ol.layer.VectorTile`.
- */
--export default function (olLayer, glStyle, source, resolutions, spriteData, spriteImageUrl, getFonts) {
-- if (resolutions === void 0) { resolutions = defaultResolutions; }
-- if (typeof glStyle == 'string') {
-- glStyle = JSON.parse(glStyle);
-- }
-- if (glStyle.version != 8) {
-- throw new Error('glStyle version 8 required.');
-+export default function (olLayer, glStyle, source, olMap, resolutions = defaultResolutions, spriteData, spriteImageUrl, getFonts) {
-+ if (typeof glStyle == 'string') {
-+ glStyle = JSON.parse(glStyle);
-+ }
-+ if (glStyle.version != 8) {
-+ throw new Error('glStyle version 8 required.');
-+ }
-+ const textWidthCanvas = createCanvas(1040, 1040);
-+ let spriteImage, spriteImgSize;
-+ if (spriteImageUrl) {
-+ if (typeof Image !== 'undefined') {
-+ const img = new Image();
-+ img.crossOrigin = 'anonymous';
-+ img.onload = function () {
-+ spriteImage = img;
-+ spriteImgSize = [img.width, img.height];
-+ olLayer.changed();
-+ img.onload = null;
-+ };
-+ img.src = spriteImageUrl;
-+ } else if (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope) { //eslint-disable-line
-+ const worker = /** @type {*} */ (self);
-+ // Main thread needs to handle 'loadImage' and dispatch 'imageLoaded'
-+ worker.postMessage({
-+ action: 'loadImage',
-+ src: spriteImageUrl
-+ });
-+ worker.addEventListener('message', function handler(event) {
-+ if (event.data.action === 'imageLoaded' && event.data.src === spriteImageUrl) {
-+ spriteImage = event.data.image;
-+ spriteImgSize = [spriteImage.width, spriteImage.height];
-+ }
-+ });
- }
-- var spriteImage, spriteImgSize;
-- if (spriteImageUrl) {
-- if (typeof Image !== 'undefined') {
-- var img_1 = new Image();
-- img_1.crossOrigin = 'anonymous';
-- img_1.onload = function () {
-- spriteImage = img_1;
-- spriteImgSize = [img_1.width, img_1.height];
-- olLayer.changed();
-- img_1.onload = null;
-- };
-- img_1.src = spriteImageUrl;
-+ }
-+
-+
-+ const allLayers = derefLayers(glStyle.layers);
-+
-+ const layersBySourceLayer = {};
-+ const mapboxLayers = [];
-+ let mapboxSource;
-+ for (let i = 0, ii = allLayers.length; i < ii; ++i) {
-+ const layer = allLayers[i];
-+ const layerId = layer.id;
-+ if (typeof source == 'string' && layer.source == source ||
-+ source.indexOf(layerId) !== -1) {
-+ const sourceLayer = layer['source-layer'];
-+ if (!mapboxSource) {
-+ mapboxSource = layer.source;
-+ const source = glStyle.sources[mapboxSource];
-+ if (!source) {
-+ throw new Error(`Source "${mapboxSource}" is not defined`);
- }
-- else if (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope) { //eslint-disable-line
-- var worker = /** @type {*} */ (self);
-- // Main thread needs to handle 'loadImage' and dispatch 'imageLoaded'
-- worker.postMessage({
-- action: 'loadImage',
-- src: spriteImageUrl
-- });
-- worker.addEventListener('message', function handler(event) {
-- if (event.data.action === 'imageLoaded' && event.data.src === spriteImageUrl) {
-- spriteImage = event.data.image;
-- spriteImgSize = [spriteImage.width, spriteImage.height];
-- }
-- });
-+ const type = source.type;
-+ if (type !== 'vector' && type !== 'geojson') {
-+ throw new Error(`Source "${mapboxSource}" is not of type "vector" or "geojson", but "${type}"`);
- }
-+ }
-+ let layers = layersBySourceLayer[sourceLayer];
-+ if (!layers) {
-+ layers = layersBySourceLayer[sourceLayer] = [];
-+ }
-+ layers.push({
-+ layer: layer,
-+ index: i
-+ });
-+ mapboxLayers.push(layerId);
-+ }
-+ // TODO revisit when diffing gets added
-+ delete functionCache[layerId];
-+ delete filterCache[layerId];
-+ }
-+
-+ const textHalo = new Stroke();
-+ const textColor = new Fill();
-+
-+ const iconImageCache = {};
-+ const patternCache = {};
-+ const styles = [];
-+
-+ const styleFunction = function (feature, resolution) {
-+ const properties = feature.getProperties();
-+ const layers = layersBySourceLayer[properties.layer];
-+ if (!layers) {
-+ return;
-+ }
-+ let zoom = resolutions.indexOf(resolution);
-+ if (zoom == -1) {
-+ zoom = getZoomForResolution(resolution, resolutions);
- }
-- var allLayers = derefLayers(glStyle.layers);
-- var layersBySourceLayer = {};
-- var mapboxLayers = [];
-- var mapboxSource;
-- for (var i = 0, ii = allLayers.length; i < ii; ++i) {
-- var layer = allLayers[i];
-- var layerId = layer.id;
-- if (typeof source == 'string' && layer.source == source ||
-- source.indexOf(layerId) !== -1) {
-- var sourceLayer = layer['source-layer'];
-- if (!mapboxSource) {
-- mapboxSource = layer.source;
-- var source_1 = glStyle.sources[mapboxSource];
-- if (!source_1) {
-- throw new Error("Source \"" + mapboxSource + "\" is not defined");
-+ const type = types[feature.getGeometry().getType()];
-+ const f = {
-+ properties: properties,
-+ type: type
-+ };
-+ let stylesLength = -1;
-+ let featureBelongsToLayer;
-+ for (let i = 0, ii = layers.length; i < ii; ++i) {
-+ const layerData = layers[i];
-+ const layer = layerData.layer;
-+ const layerId = layer.id;
-+
-+ const layout = layer.layout || emptyObj;
-+ const paint = layer.paint || emptyObj;
-+ if (layout.visibility === 'none' || ('minzoom' in layer && zoom < layer.minzoom) ||
-+ ('maxzoom' in layer && zoom >= layer.maxzoom)) {
-+ continue;
-+ }
-+ const filter = layer.filter;
-+ if (!filter || evaluateFilter(layerId, filter, f, zoom)) {
-+ featureBelongsToLayer = layer;
-+ let color, opacity, fill, stroke, strokeColor, style;
-+ const index = layerData.index;
-+ if (type == 3 && (layer.type == 'fill' || layer.type == 'fill-extrusion')) {
-+ opacity = getValue(layer, 'paint', layer.type + '-opacity', zoom, f);
-+ if (layer.type + '-pattern' in paint) {
-+ const fillIcon = getValue(layer, 'paint', layer.type + '-pattern', zoom, f);
-+ if (fillIcon) {
-+ const icon = typeof fillIcon === 'string'
-+ ? fromTemplate(fillIcon, properties)
-+ : fillIcon.toString();
-+ if (spriteImage && spriteData && spriteData[icon]) {
-+ ++stylesLength;
-+ style = styles[stylesLength];
-+ if (!style || !style.getFill() || style.getStroke() || style.getText()) {
-+ style = styles[stylesLength] = new Style({
-+ fill: new Fill()
-+ });
- }
-- var type = source_1.type;
-- if (type !== 'vector' && type !== 'geojson') {
-- throw new Error("Source \"" + mapboxSource + "\" is not of type \"vector\" or \"geojson\", but \"" + type + "\"");
-+ fill = style.getFill();
-+ style.setZIndex(index);
-+ const icon_cache_key = icon + '.' + opacity;
-+ let pattern = patternCache[icon_cache_key];
-+ if (!pattern) {
-+ const spriteImageData = spriteData[icon];
-+ const canvas = createCanvas(spriteImageData.width, spriteImageData.height);
-+ const ctx = /** @type {CanvasRenderingContext2D} */ (canvas.getContext('2d'));
-+ ctx.globalAlpha = opacity;
-+ ctx.drawImage(
-+ spriteImage,
-+ spriteImageData.x,
-+ spriteImageData.y,
-+ spriteImageData.width,
-+ spriteImageData.height,
-+ 0,
-+ 0,
-+ spriteImageData.width,
-+ spriteImageData.height
-+ );
-+ pattern = ctx.createPattern(canvas, 'repeat');
-+ patternCache[icon_cache_key] = pattern;
- }
-+ fill.setColor(pattern);
-+ }
- }
-- var layers = layersBySourceLayer[sourceLayer];
-- if (!layers) {
-- layers = layersBySourceLayer[sourceLayer] = [];
-+ } else {
-+ color = colorWithOpacity(getValue(layer, 'paint', layer.type + '-color', zoom, f), opacity);
-+ if (color) {
-+ if (layer.type + '-outline-color' in paint) {
-+ strokeColor = colorWithOpacity(getValue(layer, 'paint', layer.type + '-outline-color', zoom, f), opacity);
-+ }
-+ if (!strokeColor) {
-+ strokeColor = color;
-+ }
-+ ++stylesLength;
-+ style = styles[stylesLength];
-+ if (!style || !(style.getFill() && style.getStroke()) || style.getText()) {
-+ style = styles[stylesLength] = new Style({
-+ fill: new Fill(),
-+ stroke: new Stroke()
-+ });
-+ }
-+ fill = style.getFill();
-+ fill.setColor(color);
-+ stroke = style.getStroke();
-+ stroke.setColor(strokeColor);
-+ stroke.setWidth(1);
-+ style.setZIndex(index);
- }
-- layers.push({
-- layer: layer,
-- index: i
-- });
-- mapboxLayers.push(layerId);
-- }
-- // TODO revisit when diffing gets added
-- delete functionCache[layerId];
-- delete filterCache[layerId];
-- }
-- var textHalo = new Stroke();
-- var textColor = new Fill();
-- var iconImageCache = {};
-- var patternCache = {};
-- var styles = [];
-- var styleFunction = function (feature, resolution) {
-- var properties = feature.getProperties();
-- var layers = layersBySourceLayer[properties.layer];
-- if (!layers) {
-- return;
-+ }
- }
-- var zoom = resolutions.indexOf(resolution);
-- if (zoom == -1) {
-- zoom = getZoomForResolution(resolution, resolutions);
-- }
-- var type = types[feature.getGeometry().getType()];
-- var f = {
-- properties: properties,
-- type: type
-- };
-- var stylesLength = -1;
-- var _loop_1 = function (i, ii) {
-- var layerData = layers[i];
-- var layer = layerData.layer;
-- var layerId = layer.id;
-- var layout = layer.layout || emptyObj;
-- var paint = layer.paint || emptyObj;
-- if (layout.visibility === 'none' || ('minzoom' in layer && zoom < layer.minzoom) ||
-- ('maxzoom' in layer && zoom >= layer.maxzoom)) {
-- return "continue";
-+ if (type != 1 && layer.type == 'line') {
-+ color = !('line-pattern' in paint) && 'line-color' in paint ?
-+ colorWithOpacity(getValue(layer, 'paint', 'line-color', zoom, f), getValue(layer, 'paint', 'line-opacity', zoom, f)) :
-+ undefined;
-+ const width = getValue(layer, 'paint', 'line-width', zoom, f);
-+ if (color && width > 0) {
-+ ++stylesLength;
-+ style = styles[stylesLength];
-+ if (!style || !style.getStroke() || style.getFill() || style.getText()) {
-+ style = styles[stylesLength] = new Style({
-+ stroke: new Stroke()
-+ });
- }
-- var filter = layer.filter;
-- if (!filter || evaluateFilter(layerId, filter, f, zoom)) {
-- var color = void 0, opacity = void 0, fill = void 0, stroke = void 0, strokeColor = void 0, style = void 0;
-- var index = layerData.index;
-- if (type == 3 && layer.type == 'fill') {
-- opacity = getValue(layer, 'paint', 'fill-opacity', zoom, f);
-- if ('fill-pattern' in paint) {
-- var fillIcon = getValue(layer, 'paint', 'fill-pattern', zoom, f);
-- if (fillIcon) {
-- var icon_1 = typeof fillIcon === 'string'
-- ? fromTemplate(fillIcon, properties)
-- : fillIcon.toString();
-- if (spriteImage && spriteData && spriteData[icon_1]) {
-- ++stylesLength;
-- style = styles[stylesLength];
-- if (!style || !style.getFill() || style.getStroke() || style.getText()) {
-- style = styles[stylesLength] = new Style({
-- fill: new Fill()
-- });
-- }
-- fill = style.getFill();
-- style.setZIndex(index);
-- var icon_cache_key = icon_1 + '.' + opacity;
-- var pattern = patternCache[icon_cache_key];
-- if (!pattern) {
-- var spriteImageData = spriteData[icon_1];
-- var canvas = createCanvas(spriteImageData.width, spriteImageData.height);
-- var ctx = /** @type {CanvasRenderingContext2D} */ (canvas.getContext('2d'));
-- ctx.globalAlpha = opacity;
-- ctx.drawImage(spriteImage, spriteImageData.x, spriteImageData.y, spriteImageData.width, spriteImageData.height, 0, 0, spriteImageData.width, spriteImageData.height);
-- pattern = ctx.createPattern(canvas, 'repeat');
-- patternCache[icon_cache_key] = pattern;
-- }
-- fill.setColor(pattern);
-- }
-- }
-- }
-- else {
-- color = colorWithOpacity(getValue(layer, 'paint', 'fill-color', zoom, f), opacity);
-- if (color) {
-- if ('fill-outline-color' in paint) {
-- strokeColor = colorWithOpacity(getValue(layer, 'paint', 'fill-outline-color', zoom, f), opacity);
-- }
-- if (!strokeColor) {
-- strokeColor = color;
-- }
-- ++stylesLength;
-- style = styles[stylesLength];
-- if (!style || !(style.getFill() && style.getStroke()) || style.getText()) {
-- style = styles[stylesLength] = new Style({
-- fill: new Fill(),
-- stroke: new Stroke()
-- });
-- }
-- fill = style.getFill();
-- fill.setColor(color);
-- stroke = style.getStroke();
-- stroke.setColor(strokeColor);
-- stroke.setWidth(1);
-- style.setZIndex(index);
-- }
-+ stroke = style.getStroke();
-+ stroke.setLineCap(getValue(layer, 'layout', 'line-cap', zoom, f));
-+ stroke.setLineJoin(getValue(layer, 'layout', 'line-join', zoom, f));
-+ stroke.setMiterLimit(getValue(layer, 'layout', 'line-miter-limit', zoom, f));
-+ stroke.setColor(color);
-+ stroke.setWidth(width);
-+ stroke.setLineDash(paint['line-dasharray'] ?
-+ getValue(layer, 'paint', 'line-dasharray', zoom, f).map(function (x) {
-+ return x * width;
-+ }) : null);
-+ style.setZIndex(index);
-+ }
-+ }
-+
-+ let hasImage = false;
-+ let text = null;
-+ let placementAngle = 0;
-+ let icon, iconImg, skipLabel;
-+ if ((type == 1 || type == 2) && 'icon-image' in layout) {
-+ const iconImage = getValue(layer, 'layout', 'icon-image', zoom, f);
-+ if (iconImage) {
-+ icon = typeof iconImage === 'string'
-+ ? fromTemplate(iconImage, properties)
-+ : iconImage.toString();
-+ let styleGeom = undefined;
-+ if (spriteImage && spriteData && spriteData[icon]) {
-+ const iconRotationAlignment = getValue(layer, 'layout', 'icon-rotation-alignment', zoom, f);
-+ if (type == 2) {
-+ const geom = feature.getGeometry();
-+ // ol package and ol-debug.js only
-+ if (geom.getFlatMidpoint || geom.getFlatMidpoints) {
-+ const extent = geom.getExtent();
-+ const size = Math.sqrt(Math.max(
-+ Math.pow((extent[2] - extent[0]) / resolution, 2),
-+ Math.pow((extent[3] - extent[1]) / resolution, 2))
-+ );
-+ if (size > 150) {
-+ //FIXME Do not hard-code a size of 150
-+ const midpoint = geom.getType() === 'MultiLineString' ? geom.getFlatMidpoints() : geom.getFlatMidpoint();
-+ if (!renderFeature) {
-+ renderFeatureCoordinates = [NaN, NaN];
-+ renderFeature = new RenderFeature('Point', renderFeatureCoordinates, [], {}, null);
- }
-- }
-- if (type != 1 && layer.type == 'line') {
-- color = !('line-pattern' in paint) && 'line-color' in paint ?
-- colorWithOpacity(getValue(layer, 'paint', 'line-color', zoom, f), getValue(layer, 'paint', 'line-opacity', zoom, f)) :
-- undefined;
-- var width_1 = getValue(layer, 'paint', 'line-width', zoom, f);
-- if (color && width_1 > 0) {
-- ++stylesLength;
-- style = styles[stylesLength];
-- if (!style || !style.getStroke() || style.getFill() || style.getText()) {
-- style = styles[stylesLength] = new Style({
-- stroke: new Stroke()
-- });
-+ styleGeom = renderFeature;
-+ renderFeatureCoordinates[0] = midpoint[0];
-+ renderFeatureCoordinates[1] = midpoint[1];
-+ const placement = getValue(layer, 'layout', 'symbol-placement', zoom, f);
-+ if (placement === 'line' && iconRotationAlignment === 'map') {
-+ const stride = geom.getStride();
-+ const coordinates = geom.getFlatCoordinates();
-+ for (let i = 0, ii = coordinates.length - stride; i < ii; i += stride) {
-+ const x1 = coordinates[i];
-+ const y1 = coordinates[i + 1];
-+ const x2 = coordinates[i + stride];
-+ const y2 = coordinates[i + stride + 1];
-+ const minX = Math.min(x1, x2);
-+ const minY = Math.min(y1, y2);
-+ const maxX = Math.max(x1, x2);
-+ const maxY = Math.max(y1, y2);
-+ if (midpoint[0] >= minX && midpoint[0] <= maxX &&
-+ midpoint[1] >= minY && midpoint[1] <= maxY) {
-+ placementAngle = Math.atan2(y1 - y2, x2 - x1);
-+ break;
- }
-- stroke = style.getStroke();
-- stroke.setLineCap(getValue(layer, 'layout', 'line-cap', zoom, f));
-- stroke.setLineJoin(getValue(layer, 'layout', 'line-join', zoom, f));
-- stroke.setMiterLimit(getValue(layer, 'layout', 'line-miter-limit', zoom, f));
-- stroke.setColor(color);
-- stroke.setWidth(width_1);
-- stroke.setLineDash(paint['line-dasharray'] ?
-- getValue(layer, 'paint', 'line-dasharray', zoom, f).map(function (x) {
-- return x * width_1;
-- }) : null);
-- style.setZIndex(index);
-+ }
- }
-+ }
- }
-- var hasImage = false;
-- var text = null;
-- var placementAngle = 0;
-- var icon = void 0, iconImg = void 0, skipLabel = void 0;
-- if ((type == 1 || type == 2) && 'icon-image' in layout) {
-- var iconImage = getValue(layer, 'layout', 'icon-image', zoom, f);
-- if (iconImage) {
-- icon = typeof iconImage === 'string'
-- ? fromTemplate(iconImage, properties)
-- : iconImage.toString();
-- var styleGeom = undefined;
-- if (spriteImage && spriteData && spriteData[icon]) {
-- var iconRotationAlignment = getValue(layer, 'layout', 'icon-rotation-alignment', zoom, f);
-- if (type == 2) {
-- var geom = feature.getGeometry();
-- // ol package and ol-debug.js only
-- if (geom.getFlatMidpoint || geom.getFlatMidpoints) {
-- var extent = geom.getExtent();
-- var size = Math.sqrt(Math.max(Math.pow((extent[2] - extent[0]) / resolution, 2), Math.pow((extent[3] - extent[1]) / resolution, 2)));
-- if (size > 150) {
-- //FIXME Do not hard-code a size of 150
-- var midpoint = geom.getType() === 'MultiLineString' ? geom.getFlatMidpoints() : geom.getFlatMidpoint();
-- if (!renderFeature) {
-- renderFeatureCoordinates = [NaN, NaN];
-- renderFeature = new RenderFeature('Point', renderFeatureCoordinates, [], {}, null);
-- }
-- styleGeom = renderFeature;
-- renderFeatureCoordinates[0] = midpoint[0];
-- renderFeatureCoordinates[1] = midpoint[1];
-- var placement = getValue(layer, 'layout', 'symbol-placement', zoom, f);
-- if (placement === 'line' && iconRotationAlignment === 'map') {
-- var stride = geom.getStride();
-- var coordinates = geom.getFlatCoordinates();
-- for (var i_1 = 0, ii_1 = coordinates.length - stride; i_1 < ii_1; i_1 += stride) {
-- var x1 = coordinates[i_1];
-- var y1 = coordinates[i_1 + 1];
-- var x2 = coordinates[i_1 + stride];
-- var y2 = coordinates[i_1 + stride + 1];
-- var minX = Math.min(x1, x2);
-- var minY = Math.min(y1, y2);
-- var maxX = Math.max(x1, x2);
-- var maxY = Math.max(y1, y2);
-- if (midpoint[0] >= minX && midpoint[0] <= maxX &&
-- midpoint[1] >= minY && midpoint[1] <= maxY) {
-- placementAngle = Math.atan2(y1 - y2, x2 - x1);
-- break;
-- }
-- }
-- }
-- }
-- }
-- }
-- if (type !== 2 || styleGeom) {
-- ++stylesLength;
-- style = styles[stylesLength];
-- if (!style || !style.getImage() || style.getFill() || style.getStroke()) {
-- style = styles[stylesLength] = new Style();
-- }
-- style.setGeometry(styleGeom);
-- var iconSize = getValue(layer, 'layout', 'icon-size', zoom, f);
-- var iconColor = paint['icon-color'] !== undefined ? getValue(layer, 'paint', 'icon-color', zoom, f) : null;
-- var icon_cache_key = icon + '.' + iconSize;
-- if (iconColor !== null) {
-- icon_cache_key += '.' + iconColor;
-- }
-- iconImg = iconImageCache[icon_cache_key];
-- if (!iconImg) {
-- var spriteImageData = spriteData[icon];
-- if (iconColor !== null) {
-- // cut out the sprite and color it
-- var canvas = createCanvas(spriteImageData.width, spriteImageData.height);
-- var ctx = /** @type {CanvasRenderingContext2D} */ (canvas.getContext('2d'));
-- ctx.drawImage(spriteImage, spriteImageData.x, spriteImageData.y, spriteImageData.width, spriteImageData.height, 0, 0, spriteImageData.width, spriteImageData.height);
-- var data = ctx.getImageData(0, 0, canvas.width, canvas.height);
-- for (var c = 0, cc = data.data.length; c < cc; c += 4) {
-- var a = iconColor.a;
-- if (a !== 0) {
-- data.data[c] = iconColor.r * 255 / a;
-- data.data[c + 1] = iconColor.g * 255 / a;
-- data.data[c + 2] = iconColor.b * 255 / a;
-- }
-- data.data[c + 3] = a;
-- }
-- ctx.putImageData(data, 0, 0);
-- iconImg = iconImageCache[icon_cache_key] = new Icon({
-- img: canvas,
-- imgSize: [canvas.width, canvas.height],
-- scale: iconSize / spriteImageData.pixelRatio
-- });
-- }
-- else {
-- iconImg = iconImageCache[icon_cache_key] = new Icon({
-- img: spriteImage,
-- imgSize: spriteImgSize,
-- size: [spriteImageData.width, spriteImageData.height],
-- offset: [spriteImageData.x, spriteImageData.y],
-- rotateWithView: iconRotationAlignment === 'map',
-- scale: iconSize / spriteImageData.pixelRatio
-- });
-- }
-- }
-- iconImg.setRotation(placementAngle + deg2rad(getValue(layer, 'layout', 'icon-rotate', zoom, f)));
-- iconImg.setOpacity(getValue(layer, 'paint', 'icon-opacity', zoom, f));
-- iconImg.setAnchor(anchor[getValue(layer, 'layout', 'icon-anchor', zoom, f)]);
-- style.setImage(iconImg);
-- text = style.getText();
-- style.setText(undefined);
-- style.setZIndex(index);
-- hasImage = true;
-- skipLabel = false;
-- }
-- else {
-- skipLabel = true;
-- }
-+ }
-+ if (type !== 2 || styleGeom) {
-+ const iconSize = getValue(layer, 'layout', 'icon-size', zoom, f);
-+ const iconColor = paint['icon-color'] !== undefined ? getValue(layer, 'paint', 'icon-color', zoom, f) : null;
-+ if (!iconColor || iconColor.a !== 0) {
-+ let icon_cache_key = icon + '.' + iconSize;
-+ if (iconColor !== null) {
-+ icon_cache_key += '.' + iconColor;
-+ }
-+ iconImg = iconImageCache[icon_cache_key];
-+ if (!iconImg) {
-+ const spriteImageData = spriteData[icon];
-+ if (iconColor !== null) {
-+ // cut out the sprite and color it
-+ const canvas = createCanvas(spriteImageData.width, spriteImageData.height);
-+ const ctx = /** @type {CanvasRenderingContext2D} */ (canvas.getContext('2d'));
-+ ctx.drawImage(
-+ spriteImage,
-+ spriteImageData.x,
-+ spriteImageData.y,
-+ spriteImageData.width,
-+ spriteImageData.height,
-+ 0,
-+ 0,
-+ spriteImageData.width,
-+ spriteImageData.height
-+ );
-+ const data = ctx.getImageData(0, 0, canvas.width, canvas.height);
-+ for (let c = 0, cc = data.data.length; c < cc; c += 4) {
-+ const a = iconColor.a;
-+ if (a !== 0) {
-+ data.data[c] = iconColor.r * 255 / a;
-+ data.data[c + 1] = iconColor.g * 255 / a;
-+ data.data[c + 2] = iconColor.b * 255 / a;
- }
-+ data.data[c + 3] = a;
-+ }
-+ ctx.putImageData(data, 0, 0);
-+ iconImg = iconImageCache[icon_cache_key] = new Icon({
-+ img: canvas,
-+ imgSize: [canvas.width, canvas.height],
-+ scale: iconSize / spriteImageData.pixelRatio
-+ });
-+ } else {
-+ iconImg = iconImageCache[icon_cache_key] = new Icon({
-+ img: spriteImage,
-+ imgSize: spriteImgSize,
-+ size: [spriteImageData.width, spriteImageData.height],
-+ offset: [spriteImageData.x, spriteImageData.y],
-+ rotateWithView: iconRotationAlignment === 'map',
-+ scale: iconSize / spriteImageData.pixelRatio
-+ });
- }
-+ }
- }
-- if (type == 1 && 'circle-radius' in paint) {
-- ++stylesLength;
-- style = styles[stylesLength];
-- if (!style || !style.getImage() || style.getFill() || style.getStroke()) {
-- style = styles[stylesLength] = new Style();
-- }
-- var circleRadius = getValue(layer, 'paint', 'circle-radius', zoom, f);
-- var circleStrokeColor = colorWithOpacity(getValue(layer, 'paint', 'circle-stroke-color', zoom, f), getValue(layer, 'paint', 'circle-stroke-opacity', zoom, f));
-- var circleColor = colorWithOpacity(getValue(layer, 'paint', 'circle-color', zoom, f), getValue(layer, 'paint', 'circle-opacity', zoom, f));
-- var circleStrokeWidth = getValue(layer, 'paint', 'circle-stroke-width', zoom, f);
-- var cache_key = circleRadius + '.' + circleStrokeColor + '.' +
-- circleColor + '.' + circleStrokeWidth;
-- iconImg = iconImageCache[cache_key];
-- if (!iconImg) {
-- iconImg = iconImageCache[cache_key] = new Circle({
-- radius: circleRadius,
-- stroke: circleStrokeColor && circleStrokeWidth > 0 ? new Stroke({
-- width: circleStrokeWidth,
-- color: circleStrokeColor
-- }) : undefined,
-- fill: circleColor ? new Fill({
-- color: circleColor
-- }) : undefined
-- });
-- }
-- style.setImage(iconImg);
-- text = style.getText();
-- style.setText(undefined);
-- style.setGeometry(undefined);
-- style.setZIndex(index);
-- hasImage = true;
-- }
-- var label = void 0;
-- if ('text-field' in layout) {
-- var textField = getValue(layer, 'layout', 'text-field', zoom, f).toString();
-- label = fromTemplate(textField, properties).trim();
-- opacity = getValue(layer, 'paint', 'text-opacity', zoom, f);
-+ if (iconImg) {
-+ ++stylesLength;
-+ style = styles[stylesLength];
-+ if (!style || !style.getImage() || style.getFill() || style.getStroke()) {
-+ style = styles[stylesLength] = new Style();
-+ }
-+ style.setGeometry(styleGeom);
-+ iconImg.setRotation(placementAngle + deg2rad(getValue(layer, 'layout', 'icon-rotate', zoom, f)));
-+ iconImg.setOpacity(getValue(layer, 'paint', 'icon-opacity', zoom, f));
-+ iconImg.setAnchor(anchor[getValue(layer, 'layout', 'icon-anchor', zoom, f)]);
-+ style.setImage(iconImg);
-+ text = style.getText();
-+ style.setText(undefined);
-+ style.setZIndex(index);
-+ hasImage = true;
-+ skipLabel = false;
- }
-- if (label && opacity && !skipLabel) {
-- if (!hasImage) {
-- ++stylesLength;
-- style = styles[stylesLength];
-- if (!style || !style.getText() || style.getFill() || style.getStroke()) {
-- style = styles[stylesLength] = new Style();
-- }
-- style.setImage(undefined);
-- style.setGeometry(undefined);
-- }
-- if (!style.getText()) {
-- style.setText(text || new Text({
-- padding: [2, 2, 2, 2]
-- }));
-- }
-- text = style.getText();
-- var textSize = Math.round(getValue(layer, 'layout', 'text-size', zoom, f));
-- var fontArray = getValue(layer, 'layout', 'text-font', zoom, f);
-- var textLineHeight = getValue(layer, 'layout', 'text-line-height', zoom, f);
-- var font = mb2css(getFonts ? getFonts(fontArray) : fontArray, textSize, textLineHeight);
-- var textTransform = layout['text-transform'];
-- if (textTransform == 'uppercase') {
-- label = label.toUpperCase();
-- }
-- else if (textTransform == 'lowercase') {
-- label = label.toLowerCase();
-- }
-- var maxTextWidth = getValue(layer, 'layout', 'text-max-width', zoom, f);
-- var letterSpacing = getValue(layer, 'layout', 'text-letter-spacing', zoom, f);
-- var wrappedLabel = type == 2 ? applyLetterSpacing(label, letterSpacing) : wrapText(label, font, maxTextWidth, letterSpacing);
-- text.setText(wrappedLabel);
-- text.setFont(font);
-- text.setRotation(deg2rad(getValue(layer, 'layout', 'text-rotate', zoom, f)));
-- var textAnchor = getValue(layer, 'layout', 'text-anchor', zoom, f);
-- var placement = (hasImage || type == 1) ? 'point' : getValue(layer, 'layout', 'symbol-placement', zoom, f);
-- text.setPlacement(placement);
-- var textHaloWidth = getValue(layer, 'paint', 'text-halo-width', zoom, f);
-- var textOffset = getValue(layer, 'layout', 'text-offset', zoom, f);
-- var textTranslate = getValue(layer, 'paint', 'text-translate', zoom, f);
-- // Text offset has to take halo width and line height into account
-- var vOffset = 0;
-- var hOffset = 0;
-- if (placement == 'point') {
-- var textAlign = 'center';
-- if (textAnchor.indexOf('left') !== -1) {
-- textAlign = 'left';
-- hOffset = textHaloWidth;
-- }
-- else if (textAnchor.indexOf('right') !== -1) {
-- textAlign = 'right';
-- hOffset = -textHaloWidth;
-- }
-- text.setTextAlign(textAlign);
-- var textRotationAlignment = getValue(layer, 'layout', 'text-rotation-alignment', zoom, f);
-- text.setRotateWithView(textRotationAlignment == 'map');
-- }
-- else {
-- text.setMaxAngle(deg2rad(getValue(layer, 'layout', 'text-max-angle', zoom, f)) * label.length / wrappedLabel.length);
-- text.setTextAlign();
-- text.setRotateWithView(false);
-- }
-- var textBaseline = 'middle';
-- if (textAnchor.indexOf('bottom') == 0) {
-- textBaseline = 'bottom';
-- vOffset = -textHaloWidth - (0.5 * (textLineHeight - 1)) * textSize;
-- }
-- else if (textAnchor.indexOf('top') == 0) {
-- textBaseline = 'top';
-- vOffset = textHaloWidth + (0.5 * (textLineHeight - 1)) * textSize;
-- }
-- text.setTextBaseline(textBaseline);
-- text.setOffsetX(textOffset[0] * textSize + hOffset + textTranslate[0]);
-- text.setOffsetY(textOffset[1] * textSize + vOffset + textTranslate[1]);
-- textColor.setColor(colorWithOpacity(getValue(layer, 'paint', 'text-color', zoom, f), opacity));
-- text.setFill(textColor);
-- var haloColor = colorWithOpacity(getValue(layer, 'paint', 'text-halo-color', zoom, f), opacity);
-- if (haloColor) {
-- textHalo.setColor(haloColor);
-- // spec here : https://docs.mapbox.com/mapbox-gl-js/style-spec/#paint-symbol-text-halo-width
-- // Halo width must be doubled because it is applied around the center of the text outline
-- textHaloWidth *= 2;
-- // 1/4 of text size (spec) x 2
-- var halfTextSize = 0.5 * textSize;
-- textHalo.setWidth(textHaloWidth <= halfTextSize ? textHaloWidth : halfTextSize);
-- text.setStroke(textHalo);
-- }
-- else {
-- text.setStroke(undefined);
-- }
-- var textPadding = getValue(layer, 'layout', 'text-padding', zoom, f);
-- var padding = text.getPadding();
-- if (textPadding !== padding[0]) {
-- padding[0] = padding[1] = padding[2] = padding[3] = textPadding;
-- }
-- style.setZIndex(index);
-+ } else {
-+ skipLabel = true;
-+ }
-+ }
-+ }
-+ }
-+
-+ if (type == 1 && 'circle-radius' in paint) {
-+ ++stylesLength;
-+ style = styles[stylesLength];
-+ if (!style || !style.getImage() || style.getFill() || style.getStroke()) {
-+ style = styles[stylesLength] = new Style();
-+ }
-+ const circleRadius = getValue(layer, 'paint', 'circle-radius', zoom, f);
-+ const circleStrokeColor = colorWithOpacity(getValue(layer, 'paint', 'circle-stroke-color', zoom, f), getValue(layer, 'paint', 'circle-stroke-opacity', zoom, f));
-+ const circleColor = colorWithOpacity(getValue(layer, 'paint', 'circle-color', zoom, f), getValue(layer, 'paint', 'circle-opacity', zoom, f));
-+ const circleStrokeWidth = getValue(layer, 'paint', 'circle-stroke-width', zoom, f);
-+ const cache_key = circleRadius + '.' + circleStrokeColor + '.' +
-+ circleColor + '.' + circleStrokeWidth;
-+ iconImg = iconImageCache[cache_key];
-+ if (!iconImg) {
-+ iconImg = iconImageCache[cache_key] = new Circle({
-+ radius: circleRadius,
-+ stroke: circleStrokeColor && circleStrokeWidth > 0 ? new Stroke({
-+ width: circleStrokeWidth,
-+ color: circleStrokeColor
-+ }) : undefined,
-+ fill: circleColor ? new Fill({
-+ color: circleColor
-+ }) : undefined
-+ });
-+ }
-+ style.setImage(iconImg);
-+ text = style.getText();
-+ style.setText(undefined);
-+ style.setGeometry(undefined);
-+ style.setZIndex(index);
-+ hasImage = true;
-+ }
-+
-+ let label;
-+ if ('text-field' in layout) {
-+ const textField = getValue(layer, 'layout', 'text-field', zoom, f).toString();
-+ label = fromTemplate(textField, properties).trim();
-+ opacity = getValue(layer, 'paint', 'text-opacity', zoom, f);
-+ }
-+ if (label && opacity && !skipLabel) {
-+ if (!hasImage) {
-+ ++stylesLength;
-+ style = styles[stylesLength];
-+ if (!style || !style.getText() || style.getFill() || style.getStroke()) {
-+ style = styles[stylesLength] = new Style();
-+ }
-+ style.setImage(undefined);
-+ style.setGeometry(undefined);
-+ }
-+ if (!style.getText()) {
-+ style.setText(text || new Text({
-+ padding: [2, 2, 2, 2]
-+ }));
-+ }
-+ text = style.getText();
-+ const textSize = Math.round(getValue(layer, 'layout', 'text-size', zoom, f));
-+ const fontArray = getValue(layer, 'layout', 'text-font', zoom, f);
-+ const textLineHeight = getValue(layer, 'layout', 'text-line-height', zoom, f);
-+ const font = mb2css(getFonts ? getFonts(fontArray) : fontArray, textSize, textLineHeight);
-+ const textTransform = layout['text-transform'];
-+ if (textTransform == 'uppercase') {
-+ label = label.toUpperCase();
-+ } else if (textTransform == 'lowercase') {
-+ label = label.toLowerCase();
-+ }
-+ const maxTextWidth = getValue(layer, 'layout', 'text-max-width', zoom, f);
-+ const letterSpacing = getValue(layer, 'layout', 'text-letter-spacing', zoom, f);
-+ const wrappedLabel = type == 2 ? applyLetterSpacing(label, letterSpacing) : wrapText(label, font, maxTextWidth, letterSpacing);
-+
-+ if (!opacity || !textSize) {
-+ text.setText('');
-+ } else {
-+ text.setText(wrappedLabel);
-+ }
-+ text.setFont(font);
-+ text.setRotation(deg2rad(getValue(layer, 'layout', 'text-rotate', zoom, f)));
-+
-+ const textAnchor = getValue(layer, 'layout', 'text-anchor', zoom, f);
-+ const textVariableAnchor = getValue(layer, 'layout', 'text-variable-anchor', zoom, f);
-+ const textRadialOffset = getValue(layer, 'layout', 'text-radial-offset', zoom, f);
-+
-+ const placement = (hasImage || type == 1) ? 'point' : getValue(layer, 'layout', 'symbol-placement', zoom, f);
-+ text.setPlacement(placement);
-+ let textHaloWidth = getValue(layer, 'paint', 'text-halo-width', zoom, f);
-+
-+ const textOffset = getValue(layer, 'layout', 'text-offset', zoom, f);
-+ const textTranslate = getValue(layer, 'paint', 'text-translate', zoom, f);
-+ let textAlign = 'center';
-+ let textBaseline = 'middle';
-+ // Text offset has to take halo width and line height into account
-+ let vOffset = 0;
-+ let hOffset = 0;
-+ let xOffset = 0;
-+ let yOffset = 0;
-+ let coordinates = [];
-+ const textWidth = getTextWidth(wrappedLabel, font, textWidthCanvas);
-+ if (placement == 'point') {
-+ if (textVariableAnchor) {
-+ const layerExtent = olLayer.getSource().tileGrid.getExtent();
-+ const pointPixel = olMap.getPixelFromCoordinate(feature.getFlatCoordinates());
-+ if (olExtent.containsCoordinate(layerExtent, feature.getFlatCoordinates())) {
-+ let pass = false;
-+ const padding = 10;
-+ for (let i = 0, len = textVariableAnchor.length; i < len; i++) {
-+ if (pass) {
-+ break;
-+ }
-+ switch (textVariableAnchor[i]) {
-+ case 'left':
-+ textAlign = 'left';
-+ textBaseline = 'middle';
-+ hOffset = -textHaloWidth;
-+ yOffset = 0;
-+ xOffset = textRadialOffset ? textRadialOffset : textOffset ? textOffset[0] : 0;
-+ pointPixel[0] = pointPixel[0] + xOffset + textWidth + hOffset + textTranslate[0] + padding;
-+ coordinates = [pointPixel, [pointPixel[0] - textWidth, pointPixel[1]]];
-+ break;
-+ case 'right':
-+ textAlign = 'right';
-+ textBaseline = 'middle';
-+ hOffset = textHaloWidth;
-+ yOffset = 0;
-+ xOffset = textRadialOffset ? -textRadialOffset : textOffset ? textOffset[0] : 0;
-+ pointPixel[0] = pointPixel[0] - (xOffset + textWidth + hOffset + textTranslate[0] + padding);
-+ coordinates = [pointPixel, [pointPixel[0] + textWidth, pointPixel[1]]];
-+ break;
-+ case 'top':
-+ textBaseline = 'top';
-+ vOffset = textHaloWidth + (0.5 * (textLineHeight - 1)) * textSize;
-+ xOffset = 0;
-+ yOffset = textRadialOffset ? textRadialOffset : textOffset ? textOffset[1] : 0;
-+ pointPixel[1] = pointPixel[1] - yOffset - textSize - vOffset;
-+
-+ coordinates = [pointPixel, [pointPixel[0] - 0.5 * textWidth, pointPixel[1]], [pointPixel[0] + 0.5 * textWidth, pointPixel[1]]]
-+ break;
-+ case 'bottom':
-+ textBaseline = 'bottom';
-+ vOffset = -textHaloWidth - (0.5 * (textLineHeight - 1)) * textSize;
-+ xOffset = 0;
-+
-+ yOffset = textRadialOffset ? -textRadialOffset : textOffset ? textOffset[1] : 0;
-+ pointPixel[1] = pointPixel[1] + yOffset + textSize + vOffset;
-+ coordinates = [pointPixel, [pointPixel[0] - (0.5 * textWidth), pointPixel[1]], [pointPixel[0] + 0.5 * textWidth, pointPixel[1]]];
-+ break;
-+ default:
-+ textBaseline = 'middle';
-+ textAlign = 'center';
-+ }
-+
-+ if (containsCoordinates(layerExtent, coordinates, olMap)) {
-+ pass = true;
-+ break;
-+ } else if (i == len) {
-+ text.setText('');
-+ }
- }
-+ } else {
-+ text.setText('');
-+ }
-+
-+ text.setTextAlign(textAlign);
- }
-- };
-- for (var i = 0, ii = layers.length; i < ii; ++i) {
-- _loop_1(i, ii);
-+ text.setTextAlign(textAlign);
-+ const textRotationAlignment = getValue(layer, 'layout', 'text-rotation-alignment', zoom, f);
-+ text.setRotateWithView(textRotationAlignment == 'map');
-+ } else {
-+ text.setMaxAngle(deg2rad(getValue(layer, 'layout', 'text-max-angle', zoom, f)) * label.length / wrappedLabel.length);
-+ text.setTextAlign();
-+ text.setRotateWithView(false);
-+ }
-+ text.setTextBaseline(textBaseline);
-+ text.setOffsetX(xOffset * textSize + hOffset + textTranslate[0]);
-+ text.setOffsetY(yOffset * textSize + vOffset + textTranslate[1]);
-+ textColor.setColor(colorWithOpacity(getValue(layer, 'paint', 'text-color', zoom, f), opacity));
-+ text.setFill(textColor);
-+ const haloColor = colorWithOpacity(getValue(layer, 'paint', 'text-halo-color', zoom, f), opacity);
-+ if (haloColor) {
-+ textHalo.setColor(haloColor);
-+ // spec here : https://docs.mapbox.com/mapbox-gl-js/style-spec/#paint-symbol-text-halo-width
-+ // Halo width must be doubled because it is applied around the center of the text outline
-+ textHaloWidth *= 2;
-+ // 1/4 of text size (spec) x 2
-+ const halfTextSize = 0.5 * textSize;
-+ textHalo.setWidth(textHaloWidth <= halfTextSize ? textHaloWidth : halfTextSize);
-+ text.setStroke(textHalo);
-+ } else {
-+ text.setStroke(undefined);
-+ }
-+ const textPadding = getValue(layer, 'layout', 'text-padding', zoom, f);
-+ const padding = text.getPadding();
-+ if (textPadding !== padding[0]) {
-+ padding[0] = padding[1] = padding[2] = padding[3] = textPadding;
-+ }
-+ style.setZIndex(index);
- }
-- if (stylesLength > -1) {
-- styles.length = stylesLength + 1;
-- return styles;
-+ }
-+ }
-+
-+ if (stylesLength > -1) {
-+ styles.length = stylesLength + 1;
-+ if (recordLayer) {
-+ if (typeof feature.set === 'function') {
-+ // ol/Feature
-+ feature.set('mapbox-layer', featureBelongsToLayer);
-+ } else {
-+ // ol/render/Feature
-+ feature.getProperties()['mapbox-layer'] = featureBelongsToLayer;
- }
-- };
-- olLayer.setStyle(styleFunction);
-- olLayer.set('mapbox-source', mapboxSource);
-- olLayer.set('mapbox-layers', mapboxLayers);
-- return styleFunction;
-+ }
-+ return styles;
-+ }
-+ };
-+
-+ olLayer.setStyle(styleFunction);
-+ olLayer.set('mapbox-source', mapboxSource);
-+ olLayer.set('mapbox-layers', mapboxLayers);
-+ return styleFunction;
- }
--export { colorWithOpacity as _colorWithOpacity, filterCache as _filterCache, evaluateFilter as _evaluateFilter, fromTemplate as _fromTemplate, getValue as _getValue, functionCache as _functionCache };
--//# sourceMappingURL=stylefunction.js.map
-\ No newline at end of file
-+
-+export {
-+ colorWithOpacity as _colorWithOpacity,
-+ filterCache as _filterCache,
-+ evaluateFilter as _evaluateFilter,
-+ fromTemplate as _fromTemplate,
-+ getValue as _getValue,
-+ functionCache as _functionCache
-+};
-diff --git a/node_modules/ol-mapbox-style/src/stylefunction.js b/node_modules/ol-mapbox-style/src/stylefunction.js
-index 009d17f..bea065c 100644
---- a/node_modules/ol-mapbox-style/src/stylefunction.js
-+++ b/node_modules/ol-mapbox-style/src/stylefunction.js
-@@ -4,6 +4,8 @@ Copyright 2016-present ol-mapbox-style contributors
- License: https://raw.githubusercontent.com/openlayers/ol-mapbox-style/master/LICENSE
- */
-
-+
-+import * as olExtent from 'ol/extent';
- import Style from 'ol/style/Style';
- import Fill from 'ol/style/Fill';
- import Stroke from 'ol/style/Stroke';
-@@ -11,7 +13,7 @@ import Icon from 'ol/style/Icon';
- import Text from 'ol/style/Text';
- import Circle from 'ol/style/Circle';
- import RenderFeature from 'ol/render/Feature';
--import {derefLayers} from '@mapbox/mapbox-gl-style-spec';
-+import { derefLayers } from '@mapbox/mapbox-gl-style-spec';
-
- import {
- expression, Color,
-@@ -20,8 +22,7 @@ import {
- featureFilter as createFilter
- } from '@mapbox/mapbox-gl-style-spec';
- import mb2css from 'mapbox-to-css-font';
--import {deg2rad, defaultResolutions, getZoomForResolution, wrapText, applyLetterSpacing, createCanvas} from './util';
--
-+import { deg2rad, defaultResolutions, getZoomForResolution, wrapText, applyLetterSpacing, createCanvas } from './util';
- /**
- * @typedef {import("ol/layer/Vector").default} VectorLayer
- * @typedef {import("ol/layer/VectorTile").default} VectorTileLayer
-@@ -53,7 +54,23 @@ const anchor = {
- 'bottom-right': [1, 1]
- };
-
--const expressionData = function(rawExpression, propertySpec) {
-+const containsCoordinates = function (layerExtent, pixels, olMap) {
-+ let bool = true;
-+ pixels.forEach(pixel => {
-+ if (!olExtent.containsCoordinate(layerExtent, olMap.getCoordinateFromPixel(pixel))) {
-+ bool = false;
-+ return
-+ }
-+ });
-+ return bool;
-+}
-+const getTextWidth = function (text, font, canvas) {
-+ var context = canvas.getContext('2d');
-+ context.font = font;
-+ var metrics = context.measureText(text);
-+ return metrics.width;
-+};
-+const expressionData = function (rawExpression, propertySpec) {
- const compiledExpression = createPropertyExpression(rawExpression, propertySpec);
- if (compiledExpression.result === 'error') {
- throw new Error(compiledExpression.value.map(err => `${err.key}: ${err.message}`).join(', '));
-@@ -62,7 +79,7 @@ const expressionData = function(rawExpression, propertySpec) {
- };
-
- const emptyObj = {};
--const zoomObj = {zoom: 0};
-+const zoomObj = { zoom: 0 };
- /** @private */
- const functionCache = {};
- let renderFeatureCoordinates, renderFeature;
-@@ -100,7 +117,7 @@ export function getValue(layer, layoutOrPaint, property, zoom, feature) {
- if (propertySpec.type == 'color') {
- value = Color.parse(value);
- }
-- functions[property] = function() {
-+ functions[property] = function () {
- return value;
- };
- }
-@@ -167,6 +184,21 @@ function fromTemplate(text, properties) {
- return text;
- }
-
-+let recordLayer = false;
-+
-+/**
-+ * ```js
-+ * import {recordStyleLayer} from 'ol-mapbox-style/dist/stylefunction';
-+ * ```
-+ * Turns recording of the Mapbox Style's `layer` on and off. When turned on,
-+ * the layer that a rendered feature belongs to will be set as the feature's
-+ * `mapbox-layer` property.
-+ * @param {boolean} [record=false] Recording of the style layer is on.
-+ */
-+export function recordStyleLayer(record) {
-+ recordLayer = record;
-+}
-+
- /**
- * ```js
- * import stylefunction from 'ol-mapbox-style/dist/stylefunction';
-@@ -238,20 +270,20 @@ function fromTemplate(text, properties) {
- * @return {StyleFunction} Style function for use in
- * `ol.layer.Vector` or `ol.layer.VectorTile`.
- */
--export default function(olLayer, glStyle, source, resolutions = defaultResolutions, spriteData, spriteImageUrl, getFonts) {
-+export default function (olLayer, glStyle, source, olMap, resolutions = defaultResolutions, spriteData, spriteImageUrl, getFonts) {
- if (typeof glStyle == 'string') {
- glStyle = JSON.parse(glStyle);
- }
- if (glStyle.version != 8) {
- throw new Error('glStyle version 8 required.');
- }
--
-+ const textWidthCanvas = createCanvas(1040, 1040);
- let spriteImage, spriteImgSize;
- if (spriteImageUrl) {
- if (typeof Image !== 'undefined') {
- const img = new Image();
- img.crossOrigin = 'anonymous';
-- img.onload = function() {
-+ img.onload = function () {
- spriteImage = img;
- spriteImgSize = [img.width, img.height];
- olLayer.changed();
-@@ -284,7 +316,7 @@ export default function(olLayer, glStyle, source, resolutions = defaultResolutio
- const layer = allLayers[i];
- const layerId = layer.id;
- if (typeof source == 'string' && layer.source == source ||
-- source.indexOf(layerId) !== -1) {
-+ source.indexOf(layerId) !== -1) {
- const sourceLayer = layer['source-layer'];
- if (!mapboxSource) {
- mapboxSource = layer.source;
-@@ -319,7 +351,7 @@ export default function(olLayer, glStyle, source, resolutions = defaultResolutio
- const patternCache = {};
- const styles = [];
-
-- const styleFunction = function(feature, resolution) {
-+ const styleFunction = function (feature, resolution) {
- const properties = feature.getProperties();
- const layers = layersBySourceLayer[properties.layer];
- if (!layers) {
-@@ -335,6 +367,7 @@ export default function(olLayer, glStyle, source, resolutions = defaultResolutio
- type: type
- };
- let stylesLength = -1;
-+ let featureBelongsToLayer;
- for (let i = 0, ii = layers.length; i < ii; ++i) {
- const layerData = layers[i];
- const layer = layerData.layer;
-@@ -343,17 +376,18 @@ export default function(olLayer, glStyle, source, resolutions = defaultResolutio
- const layout = layer.layout || emptyObj;
- const paint = layer.paint || emptyObj;
- if (layout.visibility === 'none' || ('minzoom' in layer && zoom < layer.minzoom) ||
-- ('maxzoom' in layer && zoom >= layer.maxzoom)) {
-+ ('maxzoom' in layer && zoom >= layer.maxzoom)) {
- continue;
- }
- const filter = layer.filter;
- if (!filter || evaluateFilter(layerId, filter, f, zoom)) {
-+ featureBelongsToLayer = layer;
- let color, opacity, fill, stroke, strokeColor, style;
- const index = layerData.index;
-- if (type == 3 && layer.type == 'fill') {
-- opacity = getValue(layer, 'paint', 'fill-opacity', zoom, f);
-- if ('fill-pattern' in paint) {
-- const fillIcon = getValue(layer, 'paint', 'fill-pattern', zoom, f);
-+ if (type == 3 && (layer.type == 'fill' || layer.type == 'fill-extrusion')) {
-+ opacity = getValue(layer, 'paint', layer.type + '-opacity', zoom, f);
-+ if (layer.type + '-pattern' in paint) {
-+ const fillIcon = getValue(layer, 'paint', layer.type + '-pattern', zoom, f);
- if (fillIcon) {
- const icon = typeof fillIcon === 'string'
- ? fromTemplate(fillIcon, properties)
-@@ -393,10 +427,10 @@ export default function(olLayer, glStyle, source, resolutions = defaultResolutio
- }
- }
- } else {
-- color = colorWithOpacity(getValue(layer, 'paint', 'fill-color', zoom, f), opacity);
-+ color = colorWithOpacity(getValue(layer, 'paint', layer.type + '-color', zoom, f), opacity);
- if (color) {
-- if ('fill-outline-color' in paint) {
-- strokeColor = colorWithOpacity(getValue(layer, 'paint', 'fill-outline-color', zoom, f), opacity);
-+ if (layer.type + '-outline-color' in paint) {
-+ strokeColor = colorWithOpacity(getValue(layer, 'paint', layer.type + '-outline-color', zoom, f), opacity);
- }
- if (!strokeColor) {
- strokeColor = color;
-@@ -438,7 +472,7 @@ export default function(olLayer, glStyle, source, resolutions = defaultResolutio
- stroke.setColor(color);
- stroke.setWidth(width);
- stroke.setLineDash(paint['line-dasharray'] ?
-- getValue(layer, 'paint', 'line-dasharray', zoom, f).map(function(x) {
-+ getValue(layer, 'paint', 'line-dasharray', zoom, f).map(function (x) {
- return x * width;
- }) : null);
- style.setZIndex(index);
-@@ -491,7 +525,7 @@ export default function(olLayer, glStyle, source, resolutions = defaultResolutio
- const maxX = Math.max(x1, x2);
- const maxY = Math.max(y1, y2);
- if (midpoint[0] >= minX && midpoint[0] <= maxX &&
-- midpoint[1] >= minY && midpoint[1] <= maxY) {
-+ midpoint[1] >= minY && midpoint[1] <= maxY) {
- placementAngle = Math.atan2(y1 - y2, x2 - x1);
- break;
- }
-@@ -501,72 +535,76 @@ export default function(olLayer, glStyle, source, resolutions = defaultResolutio
- }
- }
- if (type !== 2 || styleGeom) {
-- ++stylesLength;
-- style = styles[stylesLength];
-- if (!style || !style.getImage() || style.getFill() || style.getStroke()) {
-- style = styles[stylesLength] = new Style();
-- }
-- style.setGeometry(styleGeom);
- const iconSize = getValue(layer, 'layout', 'icon-size', zoom, f);
- const iconColor = paint['icon-color'] !== undefined ? getValue(layer, 'paint', 'icon-color', zoom, f) : null;
-- let icon_cache_key = icon + '.' + iconSize;
-- if (iconColor !== null) {
-- icon_cache_key += '.' + iconColor;
-- }
-- iconImg = iconImageCache[icon_cache_key];
-- if (!iconImg) {
-- const spriteImageData = spriteData[icon];
-+ if (!iconColor || iconColor.a !== 0) {
-+ let icon_cache_key = icon + '.' + iconSize;
- if (iconColor !== null) {
-- // cut out the sprite and color it
-- const canvas = createCanvas(spriteImageData.width, spriteImageData.height);
-- const ctx = /** @type {CanvasRenderingContext2D} */ (canvas.getContext('2d'));
-- ctx.drawImage(
-- spriteImage,
-- spriteImageData.x,
-- spriteImageData.y,
-- spriteImageData.width,
-- spriteImageData.height,
-- 0,
-- 0,
-- spriteImageData.width,
-- spriteImageData.height
-- );
-- const data = ctx.getImageData(0, 0, canvas.width, canvas.height);
-- for (let c = 0, cc = data.data.length; c < cc; c += 4) {
-- const a = iconColor.a;
-- if (a !== 0) {
-- data.data[c] = iconColor.r * 255 / a;
-- data.data[c + 1] = iconColor.g * 255 / a;
-- data.data[c + 2] = iconColor.b * 255 / a;
-+ icon_cache_key += '.' + iconColor;
-+ }
-+ iconImg = iconImageCache[icon_cache_key];
-+ if (!iconImg) {
-+ const spriteImageData = spriteData[icon];
-+ if (iconColor !== null) {
-+ // cut out the sprite and color it
-+ const canvas = createCanvas(spriteImageData.width, spriteImageData.height);
-+ const ctx = /** @type {CanvasRenderingContext2D} */ (canvas.getContext('2d'));
-+ ctx.drawImage(
-+ spriteImage,
-+ spriteImageData.x,
-+ spriteImageData.y,
-+ spriteImageData.width,
-+ spriteImageData.height,
-+ 0,
-+ 0,
-+ spriteImageData.width,
-+ spriteImageData.height
-+ );
-+ const data = ctx.getImageData(0, 0, canvas.width, canvas.height);
-+ for (let c = 0, cc = data.data.length; c < cc; c += 4) {
-+ const a = iconColor.a;
-+ if (a !== 0) {
-+ data.data[c] = iconColor.r * 255 / a;
-+ data.data[c + 1] = iconColor.g * 255 / a;
-+ data.data[c + 2] = iconColor.b * 255 / a;
-+ }
-+ data.data[c + 3] = a;
- }
-- data.data[c + 3] = a;
-+ ctx.putImageData(data, 0, 0);
-+ iconImg = iconImageCache[icon_cache_key] = new Icon({
-+ img: canvas,
-+ imgSize: [canvas.width, canvas.height],
-+ scale: iconSize / spriteImageData.pixelRatio
-+ });
-+ } else {
-+ iconImg = iconImageCache[icon_cache_key] = new Icon({
-+ img: spriteImage,
-+ imgSize: spriteImgSize,
-+ size: [spriteImageData.width, spriteImageData.height],
-+ offset: [spriteImageData.x, spriteImageData.y],
-+ rotateWithView: iconRotationAlignment === 'map',
-+ scale: iconSize / spriteImageData.pixelRatio
-+ });
- }
-- ctx.putImageData(data, 0, 0);
-- iconImg = iconImageCache[icon_cache_key] = new Icon({
-- img: canvas,
-- imgSize: [canvas.width, canvas.height],
-- scale: iconSize / spriteImageData.pixelRatio
-- });
-- } else {
-- iconImg = iconImageCache[icon_cache_key] = new Icon({
-- img: spriteImage,
-- imgSize: spriteImgSize,
-- size: [spriteImageData.width, spriteImageData.height],
-- offset: [spriteImageData.x, spriteImageData.y],
-- rotateWithView: iconRotationAlignment === 'map',
-- scale: iconSize / spriteImageData.pixelRatio
-- });
- }
- }
-- iconImg.setRotation(placementAngle + deg2rad(getValue(layer, 'layout', 'icon-rotate', zoom, f)));
-- iconImg.setOpacity(getValue(layer, 'paint', 'icon-opacity', zoom, f));
-- iconImg.setAnchor(anchor[getValue(layer, 'layout', 'icon-anchor', zoom, f)]);
-- style.setImage(iconImg);
-- text = style.getText();
-- style.setText(undefined);
-- style.setZIndex(index);
-- hasImage = true;
-- skipLabel = false;
-+ if (iconImg) {
-+ ++stylesLength;
-+ style = styles[stylesLength];
-+ if (!style || !style.getImage() || style.getFill() || style.getStroke()) {
-+ style = styles[stylesLength] = new Style();
-+ }
-+ style.setGeometry(styleGeom);
-+ iconImg.setRotation(placementAngle + deg2rad(getValue(layer, 'layout', 'icon-rotate', zoom, f)));
-+ iconImg.setOpacity(getValue(layer, 'paint', 'icon-opacity', zoom, f));
-+ iconImg.setAnchor(anchor[getValue(layer, 'layout', 'icon-anchor', zoom, f)]);
-+ style.setImage(iconImg);
-+ text = style.getText();
-+ style.setText(undefined);
-+ style.setZIndex(index);
-+ hasImage = true;
-+ skipLabel = false;
-+ }
- } else {
- skipLabel = true;
- }
-@@ -642,26 +680,99 @@ export default function(olLayer, glStyle, source, resolutions = defaultResolutio
- const maxTextWidth = getValue(layer, 'layout', 'text-max-width', zoom, f);
- const letterSpacing = getValue(layer, 'layout', 'text-letter-spacing', zoom, f);
- const wrappedLabel = type == 2 ? applyLetterSpacing(label, letterSpacing) : wrapText(label, font, maxTextWidth, letterSpacing);
-- text.setText(wrappedLabel);
-+
-+ if (!opacity || !textSize) {
-+ text.setText('');
-+ } else {
-+ text.setText(wrappedLabel);
-+ }
- text.setFont(font);
- text.setRotation(deg2rad(getValue(layer, 'layout', 'text-rotate', zoom, f)));
-+
- const textAnchor = getValue(layer, 'layout', 'text-anchor', zoom, f);
-+ const textVariableAnchor = getValue(layer, 'layout', 'text-variable-anchor', zoom, f);
-+ const textRadialOffset = getValue(layer, 'layout', 'text-radial-offset', zoom, f);
-+
- const placement = (hasImage || type == 1) ? 'point' : getValue(layer, 'layout', 'symbol-placement', zoom, f);
- text.setPlacement(placement);
- let textHaloWidth = getValue(layer, 'paint', 'text-halo-width', zoom, f);
-+
- const textOffset = getValue(layer, 'layout', 'text-offset', zoom, f);
- const textTranslate = getValue(layer, 'paint', 'text-translate', zoom, f);
-+ let textAlign = 'center';
-+ let textBaseline = 'middle';
- // Text offset has to take halo width and line height into account
- let vOffset = 0;
- let hOffset = 0;
-+ let xOffset = 0;
-+ let yOffset = 0;
-+ let coordinates = [];
-+ const textWidth = getTextWidth(wrappedLabel, font, textWidthCanvas);
- if (placement == 'point') {
-- let textAlign = 'center';
-- if (textAnchor.indexOf('left') !== -1) {
-- textAlign = 'left';
-- hOffset = textHaloWidth;
-- } else if (textAnchor.indexOf('right') !== -1) {
-- textAlign = 'right';
-- hOffset = -textHaloWidth;
-+ if (textVariableAnchor) {
-+ const layerExtent = olLayer.getSource().tileGrid.getExtent();
-+ const pointPixel = olMap.getPixelFromCoordinate(feature.getFlatCoordinates());
-+ if (olExtent.containsCoordinate(layerExtent, feature.getFlatCoordinates())) {
-+ let pass = false;
-+ const padding = 10;
-+ for (let i = 0, len = textVariableAnchor.length; i < len; i++) {
-+ if (pass) {
-+ break;
-+ }
-+ switch (textVariableAnchor[i]) {
-+ case 'left':
-+ textAlign = 'left';
-+ textBaseline = 'middle';
-+ hOffset = -textHaloWidth;
-+ yOffset = 0;
-+ xOffset = textRadialOffset ? textRadialOffset : textOffset ? textOffset[0] : 0;
-+ pointPixel[0] = pointPixel[0] + xOffset + textWidth + hOffset + textTranslate[0] + padding;
-+ coordinates = [pointPixel, [pointPixel[0] - textWidth, pointPixel[1]]];
-+ break;
-+ case 'right':
-+ textAlign = 'right';
-+ textBaseline = 'middle';
-+ hOffset = textHaloWidth;
-+ yOffset = 0;
-+ xOffset = textRadialOffset ? -textRadialOffset : textOffset ? textOffset[0] : 0;
-+ pointPixel[0] = pointPixel[0] - (xOffset + textWidth + hOffset + textTranslate[0] + padding);
-+ coordinates = [pointPixel, [pointPixel[0] + textWidth, pointPixel[1]]];
-+ break;
-+ case 'top':
-+ textBaseline = 'top';
-+ vOffset = textHaloWidth + (0.5 * (textLineHeight - 1)) * textSize;
-+ xOffset = 0;
-+ yOffset = textRadialOffset ? textRadialOffset : textOffset ? textOffset[1] : 0;
-+ pointPixel[1] = pointPixel[1] - yOffset - textSize - vOffset;
-+
-+ coordinates = [pointPixel, [pointPixel[0] - 0.5 * textWidth, pointPixel[1]], [pointPixel[0] + 0.5 * textWidth, pointPixel[1]]]
-+ break;
-+ case 'bottom':
-+ textBaseline = 'bottom';
-+ vOffset = -textHaloWidth - (0.5 * (textLineHeight - 1)) * textSize;
-+ xOffset = 0;
-+
-+ yOffset = textRadialOffset ? -textRadialOffset : textOffset ? textOffset[1] : 0;
-+ pointPixel[1] = pointPixel[1] + yOffset + textSize + vOffset;
-+ coordinates = [pointPixel, [pointPixel[0] - (0.5 * textWidth), pointPixel[1]], [pointPixel[0] + 0.5 * textWidth, pointPixel[1]]];
-+ break;
-+ default:
-+ textBaseline = 'middle';
-+ textAlign = 'center';
-+ }
-+
-+ if (containsCoordinates(layerExtent, coordinates, olMap)) {
-+ pass = true;
-+ break;
-+ } else if (i == len) {
-+ text.setText('');
-+ }
-+ }
-+ } else {
-+ text.setText('');
-+ }
-+
-+ text.setTextAlign(textAlign);
- }
- text.setTextAlign(textAlign);
- const textRotationAlignment = getValue(layer, 'layout', 'text-rotation-alignment', zoom, f);
-@@ -671,17 +782,9 @@ export default function(olLayer, glStyle, source, resolutions = defaultResolutio
- text.setTextAlign();
- text.setRotateWithView(false);
- }
-- let textBaseline = 'middle';
-- if (textAnchor.indexOf('bottom') == 0) {
-- textBaseline = 'bottom';
-- vOffset = -textHaloWidth - (0.5 * (textLineHeight - 1)) * textSize;
-- } else if (textAnchor.indexOf('top') == 0) {
-- textBaseline = 'top';
-- vOffset = textHaloWidth + (0.5 * (textLineHeight - 1)) * textSize;
-- }
- text.setTextBaseline(textBaseline);
-- text.setOffsetX(textOffset[0] * textSize + hOffset + textTranslate[0]);
-- text.setOffsetY(textOffset[1] * textSize + vOffset + textTranslate[1]);
-+ text.setOffsetX(xOffset * textSize + hOffset + textTranslate[0]);
-+ text.setOffsetY(yOffset * textSize + vOffset + textTranslate[1]);
- textColor.setColor(colorWithOpacity(getValue(layer, 'paint', 'text-color', zoom, f), opacity));
- text.setFill(textColor);
- const haloColor = colorWithOpacity(getValue(layer, 'paint', 'text-halo-color', zoom, f), opacity);
-@@ -709,6 +812,15 @@ export default function(olLayer, glStyle, source, resolutions = defaultResolutio
-
- if (stylesLength > -1) {
- styles.length = stylesLength + 1;
-+ if (recordLayer) {
-+ if (typeof feature.set === 'function') {
-+ // ol/Feature
-+ feature.set('mapbox-layer', featureBelongsToLayer);
-+ } else {
-+ // ol/render/Feature
-+ feature.getProperties()['mapbox-layer'] = featureBelongsToLayer;
-+ }
-+ }
- return styles;
- }
- };
diff --git a/web/js/containers/sidebar/layer-list.js b/web/js/containers/sidebar/layer-list.js
index 4bf2e0590..11a32ac3b 100644
--- a/web/js/containers/sidebar/layer-list.js
+++ b/web/js/containers/sidebar/layer-list.js
@@ -1,5 +1,5 @@
/* eslint-disable react/jsx-props-no-spreading */
-import React, { useState, useEffect } from 'react';
+import React, { useState } from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import { Droppable, DragDropContext } from 'react-beautiful-dnd';
@@ -21,10 +21,6 @@ import {
removeLayer as removeLayerAction,
toggleGroupVisibility as toggleGroupVisibilityAction,
} from '../../modules/layers/actions';
-import util from '../../util/util';
-import { MAP_RUNNING_DATA } from '../../util/constants';
-
-const { events } = util;
const reorder = (list, startIndex, endIndex) => {
const result = Array.from(list);
@@ -60,14 +56,6 @@ function LayerList(props) {
const layersInProj = layers.filter(({ projections }) => projections[projId]);
const [showDropdownBtn, setDropdownBtnVisible] = useState(false);
const [showDropdownMenu, setDropdownMenuVisible] = useState(false);
- const [runningDataObj, setRunningDataObj] = useState({});
-
- useEffect(() => {
- events.on(MAP_RUNNING_DATA, setRunningDataObj);
- return () => {
- events.off(MAP_RUNNING_DATA, setRunningDataObj);
- };
- }, []);
const toggleDropdownMenuVisible = () => {
if (showDropdownMenu) {
@@ -125,7 +113,6 @@ function LayerList(props) {
names={getNames(id)}
isDisabled={!available(id)}
isVisible={visible}
- runningObject={runningDataObj[id]}
/>
);
};
diff --git a/web/js/containers/sidebar/layer-row.js b/web/js/containers/sidebar/layer-row.js
index 0103421aa..9cec8cf38 100644
--- a/web/js/containers/sidebar/layer-row.js
+++ b/web/js/containers/sidebar/layer-row.js
@@ -31,7 +31,7 @@ import { isVectorLayerClickable } from '../../modules/layers/util';
import { MODAL_PROPERTIES } from '../../modules/alerts/constants';
import { getActiveLayers, makeGetDescription } from '../../modules/layers/selectors';
import { coverageDateFormatter } from '../../modules/date/util';
-import { SIDEBAR_LAYER_HOVER } from '../../util/constants';
+import { SIDEBAR_LAYER_HOVER, MAP_RUNNING_DATA } from '../../util/constants';
const { events } = util;
const { vectorModalProps } = MODAL_PROPERTIES;
@@ -74,7 +74,6 @@ function LayerRow (props) {
isInProjection,
tracksForLayer,
isVectorLayer,
- runningObject,
measurementDescriptionPath,
isAnimating,
} = props;
@@ -92,6 +91,14 @@ function LayerRow (props) {
const [showButtons, toggleShowButtons] = useState(isMobile);
const [showDropdownBtn, setDropdownBtnVisible] = useState(false);
const [showDropdownMenu, setDropdownMenuVisible] = useState(false);
+ const [runningDataObj, setRunningDataObj] = useState({});
+
+ useEffect(() => {
+ events.on(MAP_RUNNING_DATA, setRunningDataObj);
+ return () => {
+ events.off(MAP_RUNNING_DATA, setRunningDataObj);
+ };
+ }, []);
const toggleDropdownMenuVisible = () => {
if (showDropdownMenu) {
@@ -102,10 +109,11 @@ function LayerRow (props) {
const getPaletteLegend = () => {
if (!lodashIsEmpty(renderedPalette)) {
+ const runningDataForLayer = runningDataObj[layer.id];
const isRunningData = compare.active
- ? compare.activeString === compareState && !!runningObject
- : !!runningObject;
- const colorHex = isRunningData ? runningObject.paletteHex : null;
+ ? compare.activeString === compareState && !!runningDataForLayer
+ : !!runningDataForLayer;
+ const colorHex = isRunningData ? runningDataForLayer.paletteHex : null;
let width = zot ? 220 : 231;
if (isEmbedModeActive) {
width = 201;
@@ -257,7 +265,7 @@ function LayerRow (props) {
<div
id={layerVectorBtnId}
aria-label={title}
- className={runningObject ? `${classNames} running` : classNames}
+ className={runningDataObj ? `${classNames} running` : classNames}
onMouseDown={stopPropagation}
onClick={openVectorAlertModal}
>
@@ -547,7 +555,6 @@ LayerRow.propTypes = {
paletteLegends: PropTypes.array,
renderedPalette: PropTypes.object,
requestPalette: PropTypes.func,
- runningObject: PropTypes.object,
toggleVisibility: PropTypes.func,
hasClickableFeature: PropTypes.bool,
tracksForLayer: PropTypes.array,
diff --git a/web/js/map/compare/swipe.js b/web/js/map/compare/swipe.js
index e5c7393c9..e2e62dd20 100644
--- a/web/js/map/compare/swipe.js
+++ b/web/js/map/compare/swipe.js
@@ -1,8 +1,9 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
-import lodashEach from 'lodash/each';
import lodashRound from 'lodash/round';
+import lodashEach from 'lodash/each';
+
import util from '../../util/util';
import { getCompareDates } from '../../modules/compare/selectors';
import { COMPARE_MOVE_START } from '../../util/constants';
@@ -11,14 +12,28 @@ const { events } = util;
let swipeOffset = null;
let line = null;
-let bottomLayers = [];
-let topLayers = [];
+let layersSideA = [];
+let layersSideB = [];
let mapCase;
let listenerObj;
let percentSwipe = null;
const SWIPE_PADDING = 30;
let dragging = false;
+const restore = function(event) {
+ const ctx = event.context;
+ ctx.restore();
+};
+
+const applyListenersA = function(layer) {
+ layer.on('prerender', this.clipA);
+ layer.on('postrender', restore);
+};
+const applyListenersB = function(layer) {
+ layer.on('prerender', this.clipB);
+ layer.on('postrender', restore);
+};
+
export default class Swipe {
constructor(
olMap,
@@ -43,59 +58,55 @@ export default class Swipe {
const { dateA, dateB } = getCompareDates(state);
this.dateA = dateA;
this.dateB = dateB;
- line = addLineOverlay(this.map, this.dateA, this.dateB);
+ line = addLineOverlay(this.map, this.dateA, this.dateB, this.updateExtents);
this.update(store);
}
- getSwipeOffset = () => swipeOffset
-
- /**
- * Recursively apply listeners to layers
- * @param {Object} layer | Layer or layer Group obj
- * @param {Function} callback | Function that will apply event listeners to layer
- */
- applyEventsToBaseLayers(layer, callback) {
- const layers = layer.get('layers');
- if (layers) {
- lodashEach(layers.getArray(), (layer) => {
- this.applyEventsToBaseLayers(layer, callback);
- });
- } else {
- callback.call(this, layer);
- }
+ destroy = () => {
+ mapCase.removeChild(line);
+ lodashEach(layersSideA, (layer) => {
+ layer.un('prerender', this.clipA);
+ layer.un('postrender', restore);
+ });
+ lodashEach(layersSideB, (layer) => {
+ layer.un('prerender', this.clipB);
+ layer.un('postrender', restore);
+ });
+ layersSideA = [];
+ layersSideB = [];
}
- update(store, groupName) {
+ getSwipeOffset = () => swipeOffset;
+
+ update(store) {
const state = store.getState();
const { dateA, dateB } = getCompareDates(state);
+
if (dateA !== this.dateA || dateB !== this.dateB) {
this.destroy();
this.create(store);
} else {
- const mapLayers = this.map.getLayers().getArray();
- if (!groupName) {
- this.applyEventsToBaseLayers(mapLayers[1], applyLayerListeners);
- this.applyEventsToBaseLayers(mapLayers[0], applyReverseLayerListeners);
- } else if (groupName === 'active') {
- this.applyEventsToBaseLayers(mapLayers[0], applyReverseLayerListeners);
- } else {
- this.applyEventsToBaseLayers(mapLayers[1], applyLayerListeners);
- }
+ const layerGroups = this.map.getLayers().getArray();
+ layersSideA = layerGroups[0].getLayersArray();
+ layersSideB = layerGroups[1].getLayersArray();
+ layersSideA.forEach((l) => {
+ this.applyEventListeners(l, applyListenersA);
+ });
+ layersSideB.forEach((l) => {
+ this.applyEventListeners(l, applyListenersB);
+ });
}
}
- /**
- * Clip the top layer at the right xOffset
- * @param {Object} event | OL Precompose event object
- */
- clip = (event) => {
- const ctx = event.context;
- const viewportWidth = event.frameState.size[0];
- const width = ctx.canvas.width * (swipeOffset / viewportWidth);
- ctx.save();
- ctx.beginPath();
- ctx.rect(width, 0, ctx.canvas.width - width, ctx.canvas.height);
- ctx.clip();
+ applyEventListeners(layer, callback) {
+ const layers = layer.get('layers');
+ if (layers) {
+ lodashEach(layers.getArray(), (l) => {
+ this.applyEventListeners(l, callback);
+ });
+ } else {
+ callback.call(this, layer);
+ }
}
/**
@@ -103,7 +114,7 @@ export default class Swipe {
* Layer group is transparent
* @param {Object} event | OL Precompose event object
*/
- reverseClip = (event) => {
+ clipA = (event) => {
const ctx = event.context;
const viewportWidth = event.frameState.size[0];
const width = ctx.canvas.width * (1 - swipeOffset / viewportWidth);
@@ -113,34 +124,18 @@ export default class Swipe {
ctx.clip();
}
- destroy() {
- mapCase.removeChild(line);
- this.removeListenersFromLayers(topLayers);
- this.removeListenersFromBottomLayers(bottomLayers);
- topLayers = [];
- bottomLayers = [];
- }
-
- /**
- * Remove all listeners from layer group
- * @param {Array} layers | Layer group
- */
- removeListenersFromBottomLayers(layers) {
- lodashEach(layers, (layer) => {
- layer.un('prerender', this.reverseClip);
- layer.un('postrender', restore);
- });
- }
-
/**
- * Remove all listeners from layer group
- * @param {Array} layers | Layer group
+ * Clip the top layer at the right xOffset
+ * @param {Object} event | OL Precompose event object
*/
- removeListenersFromLayers(layers) {
- lodashEach(layers, (layer) => {
- layer.un('prerender', this.clip);
- layer.un('postrender', restore);
- });
+ clipB = (event) => {
+ const ctx = event.context;
+ const viewportWidth = event.frameState.size[0];
+ const width = ctx.canvas.width * (swipeOffset / viewportWidth);
+ ctx.save();
+ ctx.beginPath();
+ ctx.rect(width, 0, ctx.canvas.width - width, ctx.canvas.height);
+ ctx.clip();
}
}
@@ -253,45 +248,19 @@ const dragLine = function(listenerObj, lineCaseEl, map) {
: swipeOffset;
percentSwipe = swipeOffset / windowWidth;
lineCaseEl.style.transform = `translateX( ${swipeOffset}px)`;
-
map.render();
}
+
function end(evt) {
dragging = false;
events.trigger(
'compare:moveend',
lodashRound((swipeOffset / mapCase.offsetWidth) * 100, 0),
);
-
window.removeEventListener(listenerObj.move, move);
window.removeEventListener(listenerObj.end, end);
}
+
window.addEventListener(listenerObj.move, move);
window.addEventListener(listenerObj.end, end);
};
-
-/**
- * Add listeners for layer clipping
- * @param {Object} layer | Ol Layer object
- */
-const applyLayerListeners = function(layer) {
- layer.on('prerender', this.clip);
- layer.on('postrender', restore);
- bottomLayers.push(layer);
-};
-
-/**
- * Layers need to be inversely clipped so that they can't be seen through
- * the other layergroup in cases where the layergroups layer opacity is < 100%
- * @param {Object} layer | Ol Layer object
- */
-const applyReverseLayerListeners = function(layer) {
- layer.on('prerender', this.reverseClip);
- layer.on('postrender', restore);
- topLayers.push(layer);
-};
-
-const restore = function(event) {
- const ctx = event.context;
- ctx.restore();
-};
diff --git a/web/js/map/layerbuilder.js b/web/js/map/layerbuilder.js
index c6307bd70..55e10257b 100644
--- a/web/js/map/layerbuilder.js
+++ b/web/js/map/layerbuilder.js
@@ -38,28 +38,15 @@ import {
import {
nearestInterval,
} from '../modules/layers/util';
-import { startLoading, stopLoading, LOADING_TILES } from '../modules/loading/actions';
import {
LEFT_WING_EXTENT, RIGHT_WING_EXTENT, LEFT_WING_ORIGIN, RIGHT_WING_ORIGIN, CENTER_MAP_ORIGIN,
} from '../modules/map/constants';
-let loadingCounter = 0;
export default function mapLayerBuilder(config, cache, store) {
const { getGranuleLayer } = granuleLayerBuilder(cache, store, createLayerWMTS);
- const tileLoadStart = () => {
- if (loadingCounter === 0) {
- store.dispatch(startLoading(LOADING_TILES));
- }
- loadingCounter += 1;
- };
- const tileLoadEnd = () => {
- loadingCounter -= 1;
- if (loadingCounter === 0) {
- store.dispatch(stopLoading(LOADING_TILES));
- }
- };
+
/**
* Return a layer, or layergroup, created with the supplied function
@@ -443,7 +430,7 @@ export default function mapLayerBuilder(config, cache, store) {
const { tileMatrices, resolutions, tileSize } = configMatrixSet;
const { origin, extent } = calcExtentsFromLimits(configMatrixSet, matrixSetLimits, day, proj.selected);
- const sizes = !tileMatrices ? [] : tileMatrices.map(({ matrixWidth, matrixHeight }) => [matrixWidth, -matrixHeight]);
+ const sizes = !tileMatrices ? [] : tileMatrices.map(({ matrixWidth, matrixHeight }) => [matrixWidth, matrixHeight]);
// Also need to shift this if granule is shifted
const tileGridOptions = {
@@ -474,10 +461,6 @@ export default function mapLayerBuilder(config, cache, store) {
sourceOptions.tileClass = lookupFactory(lookup, sourceOptions);
}
const tileSource = new OlSourceWMTS(sourceOptions);
- tileSource.on('tileloadstart', tileLoadStart);
- tileSource.on('tileloadend', tileLoadEnd);
- tileSource.on('tileloaderror', tileLoadEnd);
-
const granuleExtent = polygon && getGranuleTileLayerExtent(polygon, extent);
return new OlLayerTile({
@@ -567,15 +550,12 @@ export default function mapLayerBuilder(config, cache, store) {
sizes: matrixSet.tileMatrices,
}),
});
- tileSource.on('tileloadstart', tileLoadStart);
- tileSource.on('tileloadend', tileLoadEnd);
- tileSource.on('tileloaderror', tileLoadEnd);
+
const layer = new LayerVectorTile({
extent: layerExtent,
source: tileSource,
- renderMode: 'image',
+ renderMode: 'vector',
className: def.id,
- vector: true,
preload: 0,
...isMaxBreakPoint && { maxResolution: breakPointResolution },
...isMinBreakPoint && { minResolution: breakPointResolution },
@@ -584,6 +564,7 @@ export default function mapLayerBuilder(config, cache, store) {
layer.wrap = day;
layer.wv = attributes;
layer.isVector = true;
+
if (breakPointLayerDef && !animationIsPlaying) {
const newDef = { ...def, ...breakPointLayerDef };
const wmsLayer = createLayerWMS(newDef, options, day, state);
@@ -592,7 +573,9 @@ export default function mapLayerBuilder(config, cache, store) {
});
wmsLayer.wv = attributes;
return layerGroup;
- } if (breakPointResolution && animationIsPlaying) {
+ }
+
+ if (breakPointResolution && animationIsPlaying) {
delete breakPointLayerDef.projections[proj.id].resolutionBreakPoint;
const newDef = { ...def, ...breakPointLayerDef };
const wmsLayer = createLayerWMS(newDef, options, day, state);
@@ -680,9 +663,6 @@ export default function mapLayerBuilder(config, cache, store) {
}
const resolutionBreakPoint = lodashGet(def, `breakPointLayer.projections.${proj.id}.resolutionBreakPoint`);
const tileSource = new OlSourceTileWMS(sourceOptions);
- tileSource.on('tileloadstart', tileLoadStart);
- tileSource.on('tileloadend', tileLoadEnd);
- tileSource.on('tileloaderror', tileLoadEnd);
const layer = new OlLayerTile({
preload: 0,
diff --git a/web/js/map/runningdata.js b/web/js/map/runningdata.js
index 8417266be..d53dbcb62 100644
--- a/web/js/map/runningdata.js
+++ b/web/js/map/runningdata.js
@@ -14,60 +14,53 @@ import { MAP_RUNNING_DATA } from '../util/constants';
const { events } = util;
export default function MapRunningData(compareUi, store) {
- const self = this;
let dataObj = {};
- /**
- * Clear running data value
- */
- self.clearAll = function() {
+
+ function clearAll() {
if (!lodashIsEmpty(dataObj)) {
dataObj = {};
events.trigger(MAP_RUNNING_DATA, dataObj);
}
- };
- /*
- * Compare old and new arrays to determine which Layers need to be
- * removed
- *
- * @method LayersToRemove
- *
- * @param {Array} pixels - Array of pixels values
- *
- * @param {Object} map - OpenLayers Map Object
- *
- * @return {Void}
- *
- */
- self.newPoint = function(pixels, map) {
+ }
+
+ function newPoint(pixel, map) {
const state = store.getState();
const { proj, compare } = state;
const activeLayerObj = {};
- const [lon, lat] = map.getCoordinateFromPixel(pixels);
+ const [lon, lat] = map.getCoordinateFromPixel(pixel);
let swipeOffset;
if (compareUi && compare.active) {
swipeOffset = Math.floor(compareUi.getOffset());
}
- map.forEachFeatureAtPixel(pixels, (feature, layer) => {
+ // Determine if we should do anything with this vector layer
+ const shouldNotProcessVectorLayer = (layer) => {
const def = lodashGet(layer, 'wv.def');
if (!def) return;
- const isWrapped = proj.id === 'geographic' && (def.wrapadjacentdays || def.wrapX);
+ const { wrapX, wrapadjacentdays } = def;
+ const isWrapped = proj.id === 'geographic' && (wrapadjacentdays || wrapX);
const isRenderedFeature = isWrapped ? lon > -250 || lon < 250 || lat > -90 || lat < 90 : true;
- const featureOutsideExtent = !olExtent.containsCoordinate(layer.get('extent'), map.getCoordinateFromPixel(pixels));
- if (!isRenderedFeature || !isFromActiveCompareRegion(pixels, layer.wv.group, compare, swipeOffset) || featureOutsideExtent) return;
-
+ const coords = map.getCoordinateFromPixel(pixel);
+ const featureOutsideExtent = !olExtent.containsCoordinate(layer.get('extent'), coords);
+ const inCompareRegion = isFromActiveCompareRegion(pixel, layer.wv.group, compare, swipeOffset);
const hasPalette = !lodashIsEmpty(def.palette);
- if (!hasPalette) return;
- const identifier = def.palette.styleProperty;
- const layerId = def.id;
- const paletteLegends = getPalette(layerId, undefined, undefined, state);
+ return !isRenderedFeature || !inCompareRegion || featureOutsideExtent || !hasPalette;
+ };
+
+ // Running data for vector layers
+ map.forEachFeatureAtPixel(pixel, (feature, layer) => {
+ if (shouldNotProcessVectorLayer(layer)) return;
+
+ const { id, palette } = layer.wv.def;
+ const identifier = palette.styleProperty;
+ const paletteLegends = getPalette(id, undefined, undefined, state);
const { legend } = paletteLegends;
+ let color;
if (!identifier && legend.colors.length > 1) return;
- let color;
if (identifier) {
const properties = feature.getProperties();
- const value = properties[identifier] || def.palette.unclassified;
+ const value = properties[identifier] || palette.unclassified;
if (!value) return;
const tooltips = legend.tooltips.map((c) => c.toLowerCase().replace(/\s/g, ''));
const colorIndex = tooltips.indexOf(value.toLowerCase().replace(/\s/g, ''));
@@ -75,34 +68,42 @@ export default function MapRunningData(compareUi, store) {
} else if (legend.colors.length === 1) {
[color] = legend.colors;
}
- activeLayerObj[layerId] = {
+ activeLayerObj[id] = {
paletteLegends,
paletteHex: color,
};
});
- map.forEachLayerAtPixel(pixels, (layer, data) => {
- if (!layer.wv) return;
- const { def, group } = layer.wv;
- if (!isFromActiveCompareRegion(pixels, group, compare, swipeOffset)) return;
- if (def.palette && !lodashGet(layer, 'wv.def.disableHoverValue')) {
- activeLayerObj[def.id] = {
- paletteLegends: getPalette(def.id, undefined, undefined, state),
- paletteHex: util.rgbaToHex(data[0], data[1], data[2], data[3]),
- };
- }
- }, {
- // Don't include granules for perfomance reasons
- layerFilter: (layer) => {
- const type = lodashGet(layer, 'wv.def.type');
- return !(type === 'granule' && !layer.get('granuleGroup'));
- },
+ // Determine if we should do anything with this raster layer
+ const shouldNotProcessRasterLayer = (layer) => {
+ const type = lodashGet(layer, 'wv.def.type');
+ const isGranule = type === 'granule' && !layer.get('granuleGroup');
+ const hasPalette = !!lodashGet(layer, 'wv.def.palette');
+ return isGranule || layer.isVector || !hasPalette;
+ };
+
+ // Running data for raster layers
+ map.getAllLayers().forEach((layer) => {
+ if (shouldNotProcessRasterLayer(layer)) return;
+ const { wv: { def: { id } } } = layer;
+ const data = layer.getData(pixel);
+ if (!data) return;
+ const [red, green, blue, alpha] = data;
+ const hexColor = util.rgbaToHex(red, green, blue, alpha);
+ activeLayerObj[id] = {
+ paletteLegends: getPalette(id, undefined, undefined, state),
+ paletteHex: hexColor,
+ };
});
if (!lodashIsEqual(activeLayerObj, dataObj)) {
dataObj = activeLayerObj;
events.trigger(MAP_RUNNING_DATA, dataObj);
}
+ }
+
+ return {
+ clearAll,
+ newPoint,
};
- return self;
}
diff --git a/web/js/map/ui.js b/web/js/map/ui.js
index 34461110a..345b98a94 100644
--- a/web/js/map/ui.js
+++ b/web/js/map/ui.js
@@ -31,7 +31,7 @@ import Cache from 'cachai';
import PQueue from 'p-queue/dist';
import mapLayerBuilder from './layerbuilder';
import MapRunningData from './runningdata';
-import { getActiveLayerGroup, fly, saveRotation } from './util';
+import { fly, saveRotation } from './util';
import mapCompare from './compare/compare';
import { granuleFootprint } from './granule/util';
import { LOCATION_POP_ACTION } from '../redux-location-state-customs';
@@ -52,6 +52,7 @@ import { setStyleFunction } from '../modules/vector-styles/selectors';
import {
getLayers,
getActiveLayers,
+ getActiveLayerGroup,
isRenderable as isRenderableLayer,
getMaxZoomLevelLayerCollection,
getAllActiveLayers,
@@ -70,7 +71,7 @@ import { updateVectorSelection } from '../modules/vector-styles/util';
import { animateCoordinates, getCoordinatesMarker, areCoordinatesWithinExtent } from '../modules/location-search/util';
import { getNormalizedCoordinate } from '../components/location-search/util';
import { reverseGeocode } from '../modules/location-search/util-api';
-import { startLoading, stopLoading, PRELOAD_TILES } from '../modules/loading/actions';
+import { startLoading, stopLoading, MAP_LOADING } from '../modules/loading/actions';
import {
MAP_DISABLE_CLICK_ZOOM,
MAP_ENABLE_CLICK_ZOOM,
@@ -111,10 +112,6 @@ export default function mapui(models, config, store) {
processingPromise: null,
};
- layerQueue.on('idle', () => {
- store.dispatch(stopLoading(PRELOAD_TILES));
- });
-
/**
* Subscribe to redux store and listen for
* specific action types
@@ -221,7 +218,9 @@ export default function mapui(models, config, store) {
updateVectorSelection(
action.payload,
self.selectedVectors,
- getActiveLayers(state), type, state,
+ getActiveLayers(state),
+ type,
+ state,
);
self.selectedVectors = newSelection;
return;
@@ -801,8 +800,10 @@ export default function mapui(models, config, store) {
if (def.type === 'granule') {
updateGranuleLayerOpacity(def, activeStr, opacity, compare);
} else {
- const layer = findLayer(def, activeStr);
- layer.setOpacity(opacity);
+ const layerGroup = findLayer(def, activeStr);
+ layerGroup.getLayersArray().forEach((l) => {
+ l.setOpacity(opacity);
+ });
}
updateLayerVisibilities();
}
@@ -850,7 +851,7 @@ export default function mapui(models, config, store) {
layersToRemove.forEach((def) => {
const layer = findLayer(def, compare.activeString);
if (compare && compare.active) {
- const layerGroup = getActiveLayerGroup(self.selected, compare.activeString);
+ const layerGroup = getActiveLayerGroup(state);
if (layerGroup) layerGroup.getLayers().remove(layer);
} else {
self.selected.removeLayer(layer);
@@ -878,22 +879,6 @@ export default function mapui(models, config, store) {
setStyleFunction(def, vectorStyleId, vectorStyles, null, state);
}
- function getLayerGroup (state) {
- const { compare } = state;
- const { active, activeString } = compare || {};
- if (active) {
- const layerGroups = self.selected.getLayers().getArray();
- if (layerGroups.length > 1) {
- return layerGroups[0].get('group') === activeString
- ? layerGroups[0]
- : layerGroups[1].get('group') === activeString
- ? layerGroups[1]
- : null;
- }
- }
- return self.selected;
- }
-
async function updateCompareLayer (def, index, layerCollection) {
const state = store.getState();
const { compare } = state;
@@ -910,7 +895,7 @@ export default function mapui(models, config, store) {
async function updateDate(outOfStepChange) {
const state = store.getState();
const { compare = {} } = state;
- const layerGroup = getLayerGroup(state);
+ const layerGroup = getActiveLayerGroup(state);
const mapLayerCollection = layerGroup.getLayers();
const layers = mapLayerCollection.getArray();
const activeLayers = getAllActiveLayers(state);
@@ -971,8 +956,6 @@ export default function mapui(models, config, store) {
const prevDate = getNextDateTime(state, -1, useDate);
const subsequentDate = lastArrowDirection === 'right' ? nextDate : prevDate;
- store.dispatch(startLoading(PRELOAD_TILES));
-
// If we've preloaded N dates out, we need to use the latest
// preloaded date the next time we call this function or the buffer
// won't stay ahead of the 'animation' when holding down timetep arrows
@@ -1080,7 +1063,7 @@ export default function mapui(models, config, store) {
*/
function findLayerIndex({ id }) {
const state = store.getState();
- const layerGroup = getLayerGroup(state);
+ const layerGroup = getActiveLayerGroup(state);
const layers = layerGroup.getLayers().getArray();
return lodashFindIndex(layers, {
wv: { id },
@@ -1241,6 +1224,13 @@ export default function mapui(models, config, store) {
setTimeout(preloadForCompareMode, 250);
map.un('rendercomplete', onRenderComplete);
};
+
+ map.on('loadstart', () => {
+ store.dispatch(startLoading(MAP_LOADING));
+ });
+ map.on('loadend', () => {
+ store.dispatch(stopLoading(MAP_LOADING));
+ });
map.on('rendercomplete', onRenderComplete);
granuleFootprints[proj.crs] = granuleFootprint(map);
window.addEventListener('resize', () => {
@@ -1249,18 +1239,10 @@ export default function mapui(models, config, store) {
return map;
}
- /*
+ /**
* Creates map events based on mouse position
- *
- *
- * @method createMousePosSel
- * @static
- *
* @param {object} map - OpenLayers Map Object
- *
* @returns {void}
- *
- * @todo move this component to another Location
*/
function createMousePosSel(map) {
const throttledOnMouseMove = lodashThrottle(({ pixel }) => {
@@ -1274,6 +1256,7 @@ export default function mapui(models, config, store) {
const isEventsTabActive = typeof events !== 'undefined' && events.active;
const isMapAnimating = animation.isPlaying;
+ if (map.proj !== state.map.ui.selected.proj) return;
if (self.mapIsbeingZoomed) return;
if (self.mapIsbeingDragged) return;
if (compareMapUi && compareMapUi.dragging) return;
diff --git a/web/js/map/util.js b/web/js/map/util.js
index 551540568..d445e27ea 100644
--- a/web/js/map/util.js
+++ b/web/js/map/util.js
@@ -61,25 +61,6 @@ export function getGeographicResolutionWMS(tileSize) {
if (!tileSize || !tileSize.length) return RESOLUTION_FOR_LARGE_WMS_TILES;
return tileSize[0] === 256 ? RESOLUTION_FOR_SMALL_WMS_TILES : RESOLUTION_FOR_LARGE_WMS_TILES;
}
-/**
- * getActiveLayerGroup
- * @param {Object} map
- * @param {string} layerGroupString
- *
- * @return {Object} group
- */
-export function getActiveLayerGroup(map, layerGroupString) {
- let group = null;
- const array = map.getLayers().getArray();
- for (let i = 0, len = array.length; i < len; i += 1) {
- const layerGroup = array[i];
- if (layerGroup.get('group') === layerGroupString) {
- group = layerGroup;
- break;
- }
- }
- return group;
-}
/**
* Create x/y/z vectortile requester url
diff --git a/web/js/modules/layers/selectors.js b/web/js/modules/layers/selectors.js
index 6795b6dcf..6a7111e7b 100644
--- a/web/js/modules/layers/selectors.js
+++ b/web/js/modules/layers/selectors.js
@@ -37,6 +37,22 @@ export const getActiveLayers = (state, activeString) => {
return layers[activeString || compare.activeString].layers;
};
+export const getActiveLayerGroup = (state) => {
+ const { compare, map } = state;
+ const { active, activeString } = compare || {};
+ if (active) {
+ const layerGroups = map.ui.selected.getLayers().getArray();
+ if (layerGroups.length > 1) {
+ return layerGroups[0].get('group') === activeString
+ ? layerGroups[0]
+ : layerGroups[1].get('group') === activeString
+ ? layerGroups[1]
+ : null;
+ }
+ }
+ return map.ui.selected;
+};
+
export const getActiveGranuleLayers = (state, activeString) => {
const { compare, layers } = state;
const { granuleLayers } = layers[activeString || compare.activeString] || {};
diff --git a/web/js/modules/loading/actions.js b/web/js/modules/loading/actions.js
index e7ff20df3..de0ea88ba 100644
--- a/web/js/modules/loading/actions.js
+++ b/web/js/modules/loading/actions.js
@@ -1,8 +1,7 @@
import { LOADING_START, LOADING_STOP } from './constants';
export const LOADING_GRANULES = 'LOADING/GRANULES';
-export const PRELOAD_TILES = 'LOADING/TILE_PRELOAD';
-export const LOADING_TILES = 'LOADING/LAYER_TILES';
+export const MAP_LOADING = 'LOADING/MAP_LOADING';
export function startLoading(key, msg) {
return (dispatch, getState) => {
diff --git a/web/js/modules/vector-styles/selectors.js b/web/js/modules/vector-styles/selectors.js
index 253dcb954..99c5db182 100644
--- a/web/js/modules/vector-styles/selectors.js
+++ b/web/js/modules/vector-styles/selectors.js
@@ -7,12 +7,12 @@ import {
import update from 'immutability-helper';
import { containsCoordinate } from 'ol/extent';
-import stylefunction from 'ol-mapbox-style/dist/stylefunction';
+import { stylefunction } from 'ol-mapbox-style';
import {
getMinValue, getMaxValue, selectedStyleFunction,
} from './util';
import {
- getAllActiveLayers,
+ getActiveLayers,
} from '../layers/selectors';
/**
@@ -81,82 +81,58 @@ export function setRange(layerId, props, index, palettes, state) {
}
export function setStyleFunction(def, vectorStyleId, vectorStyles, layer, state) {
- const { compare, proj } = state;
- let styleFunction;
+ const map = lodashGet(state, 'map.ui.selected');
+ if (!map) return;
+ const { proj } = state;
+ const { selected } = state.vectorStyles;
+ const { resolutions } = proj.selected;
const layerId = def.id;
const styleId = lodashGet(def, `vectorStyle.${proj.id}.id`) || vectorStyleId || lodashGet(def, 'vectorStyle.id') || layerId;
const glStyle = vectorStyles[styleId];
- const olMap = lodashGet(state, 'map.ui.selected');
- const { selected } = state.vectorStyles;
- const activeLayers = [...getAllActiveLayers(state)].reverse();
- let layerGroups;
- let layerGroup;
- if (olMap) {
- layerGroups = olMap.getLayers().getArray();
- if (compare && compare.active) {
- if (layerGroups.length > 1) {
- layerGroup = layerGroups[0].get('group') === compare.activeString
- ? layerGroups[0]
- : layerGroups[1].get('group') === compare.activeString
- ? layerGroups[1]
- : null;
- }
- }
- lodashEach(activeLayers, (def) => {
- if (compare && compare.active) {
- if (layerGroup && layerGroup.getLayers().getArray().length) {
- lodashEach(layerGroup.getLayers().getArray(), (subLayer) => {
- if (subLayer.wv && (subLayer.wv.id === layerId)) {
- layer = subLayer;
- }
- });
+ if (!layer || layer.isWMS) {
+ return; // WMS breakpoint tile
+ }
+
+ layer = layer.getLayers
+ ? lodashFind(layer.getLayers().getArray(), 'isVector')
+ : layer;
+
+ const styleFunction = stylefunction(layer, glStyle, layerId, resolutions);
+ const selectedFeatures = selected[layerId];
+
+ // Handle selected feature style
+ if ((glStyle.name !== 'Orbit Tracks') && selectedFeatures) {
+ const extentStartX = layer.getExtent()[0];
+ const acceptableExtent = extentStartX === 180
+ ? [-180, -90, -110, 90]
+ : extentStartX === -250
+ ? [110, -90, 180, 90]
+ : null;
+
+ layer.setStyle((feature, resolution) => {
+ const data = state.config.vectorData[def.vectorData.id];
+ const properties = data.mvt_properties;
+ const features = feature.getProperties();
+ const idKey = lodashFind(properties, { Function: 'Identify' }).Identifier;
+ const uniqueIdentifier = features[idKey];
+ if (shouldRenderFeature(feature, acceptableExtent)) {
+ if (uniqueIdentifier && selectedFeatures && selectedFeatures.includes(uniqueIdentifier)) {
+ return selectedStyleFunction(feature, styleFunction(feature, resolution));
}
- } else {
- lodashEach(layerGroups, (subLayer) => {
- if (subLayer.wv && (subLayer.wv.id === layerId)) {
- layer = subLayer;
- }
- });
+ return styleFunction(feature, resolution);
}
});
}
- if (!layer) {
- return null;
- }
- const layerArray = layer.getLayers ? layer.getLayers().getArray() : [layer];
- lodashEach(layerArray, (layerInLayerGroup) => {
- if (!layerInLayerGroup || layerInLayerGroup.isWMS) return; // WMS breakpoint tile
- layerInLayerGroup = layerInLayerGroup.getLayers ? lodashFind(layerInLayerGroup.getLayers().getArray(), 'isVector') : layerInLayerGroup;
- // Apply mapbox-gl styles
- const extentStartX = layerInLayerGroup.getExtent()[0];
- const acceptableExtent = extentStartX === 180 ? [-180, -90, -110, 90] : extentStartX === -250 ? [110, -90, 180, 90] : null;
- styleFunction = stylefunction(layerInLayerGroup, glStyle, layerId, olMap, proj.selected.resolutions);
- if ((glStyle.name !== 'Orbit Tracks')
- && (selected[layerId] && selected[layerId].length)) {
- const selectedFeatures = selected[layerId];
-
- layerInLayerGroup.setStyle((feature, resolution) => {
- const data = state.config.vectorData[def.vectorData.id];
- const properties = data.mvt_properties;
- const features = feature.getProperties();
- const idKey = lodashFind(properties, { Function: 'Identify' }).Identifier;
- const uniqueIdentifier = features[idKey];
- if (shouldRenderFeature(feature, acceptableExtent)) {
- if (uniqueIdentifier && selectedFeatures && selectedFeatures.includes(uniqueIdentifier)) {
- return selectedStyleFunction(feature, styleFunction(feature, resolution));
- }
- return styleFunction(feature, resolution);
- }
- });
- }
- });
+
return vectorStyleId;
}
const shouldRenderFeature = (feature, acceptableExtent) => {
if (!acceptableExtent) return true;
- const midpoint = feature.getFlatCoordinates ? feature.getFlatCoordinates() : feature.getGeometry().getFlatCoordinates();
+ const midpoint = feature.getFlatCoordinates
+ ? feature.getFlatCoordinates()
+ : feature.getGeometry().getFlatCoordinates();
if (containsCoordinate(acceptableExtent, midpoint)) return true;
return false;
};
@@ -220,26 +196,22 @@ export function clearStyleFunction(def, vectorStyleId, vectorStyles, layer, stat
* @param {Object} def
* @param {Object} olVectorLayer
* @param {Object} state
- * @param {Object} options
- *
- * @return {undefined}
*/
-export const applyStyle = (def, olVectorLayer, state, options) => {
- const { config, layers, compare } = state;
- const activeGroupStr = options.group ? options.group : compare.activeString;
- const activeLayers = layers[activeGroupStr].layers;
+export const applyStyle = (def, olVectorLayer, state) => {
+ const { config } = state;
+ const { vectorStyles } = config;
+ const activeLayers = getActiveLayers(state) || [];
const layerName = def.layer || def.id;
- if (config.vectorStyles && def.vectorStyle && def.vectorStyle.id) {
- const { vectorStyles } = config;
- let vectorStyleId;
- vectorStyleId = def.vectorStyle.id;
- if (activeLayers) {
- activeLayers.forEach((layer) => {
- if (layer.id === layerName && layer.custom) {
- vectorStyleId = layer.custom;
- }
- });
- }
- setStyleFunction(def, vectorStyleId, vectorStyles, olVectorLayer, state);
+ let vectorStyleId = def.vectorStyle.id;
+
+ if (!vectorStyles || !vectorStyleId) {
+ return;
}
+
+ activeLayers.forEach((layer) => {
+ if (layer.id === layerName && layer.custom) {
+ vectorStyleId = layer.custom;
+ }
+ });
+ setStyleFunction(def, vectorStyleId, vectorStyles, olVectorLayer, state);
};
diff --git a/web/js/modules/vector-styles/util.js b/web/js/modules/vector-styles/util.js
index c10c0a85c..29b62ee99 100644
--- a/web/js/modules/vector-styles/util.js
+++ b/web/js/modules/vector-styles/util.js
@@ -46,9 +46,11 @@ export function getMinValue(v) {
export function getMaxValue(v) {
return v.length ? v[v.length - 1] : v;
}
+
export function isConditional(item) {
return Array.isArray(item) && item[0] === 'case';
}
+
export function adjustCircleRadius(style) {
const styleImage = style.getImage();
const fill = styleImage.getFill();
@@ -88,6 +90,7 @@ export function selectedPolygonStyle(style) {
fill.setColor(color);
return style;
}
+
export function offsetLineStringStyle(feature, styleArray) {
return styleArray.map((style) => {
const text = style.getText();
@@ -112,6 +115,7 @@ export function selectedStyleFunction(feature, styleArray, size) {
}
});
}
+
export function getConditionalColors(color) {
const array = Array.from(color);
array.shift();
@@ -141,6 +145,7 @@ export function getConditionalColors(color) {
}
return { colors, labels };
}
+
export function getPaletteForStyle(layer, layerstyleLayerObject) {
const styleLayerObject = layerstyleLayerObject.layers[0];
const color = styleLayerObject.paint['line-color'] || styleLayerObject.paint['circle-color'] || styleLayerObject.paint['fill-color'];
@@ -163,12 +168,14 @@ export function getPaletteForStyle(layer, layerstyleLayerObject) {
id: `${layer.id}0_legend`,
}];
}
+
export function isFeatureInRenderableArea(lon, wrap, acceptableExtent) {
if (acceptableExtent) {
return lon > acceptableExtent[0] && lon < acceptableExtent[2];
}
return wrap === -1 ? lon < 250 && lon > 180 : wrap === 1 ? lon > -250 && lon < -180 : false;
}
+
/**
* Use modal/screen dimensions and click pixel location
* to return X & Y offsets for modal
@@ -198,6 +205,7 @@ function getModalOffset(dimensionProps) {
}
return { offsetLeft, offsetTop };
}
+
/**
* Get Organized data for each feature at pixel
* @param {Object} mapProps
@@ -271,6 +279,7 @@ function getModalContentsAtPixel(mapProps, config, compareState, isMobile) {
selected, metaArray, exceededLengthLimit, isCoordinatesMarker, modalShouldFollowClicks,
};
}
+
/**
* Get organized vector modal contents for clicked
* map location
@@ -306,23 +315,26 @@ export function onMapClickGetVectorFeatures(pixels, map, state, swipeOffset) {
exceededLengthLimit,
};
}
+
export function updateVectorSelection(selectionObj, lastSelection, layers, type, state) {
- const { vectorStyles } = state.config;
+ const { config: { vectorStyles }, map: { ui: { selected } } } = state;
+ const layerGroups = selected.getLayers().getArray();
+ let olLayers = [];
+ layerGroups.forEach((group) => {
+ olLayers = [...olLayers, ...group.getLayers().getArray()];
+ });
+
for (const [key] of Object.entries(selectionObj)) {
const def = lodashFind(layers, { id: key });
if (!def) return;
- setStyleFunction(def, def.vectorStyle.id, vectorStyles, null, state);
+ const olLayer = olLayers.find((layer) => layer.wv.id === key);
+ setStyleFunction(def, def.vectorStyle.id, vectorStyles, olLayer, state);
if (lastSelection[key]) delete lastSelection[key];
}
for (const [key] of Object.entries(lastSelection)) {
const def = lodashFind(layers, { id: key });
if (!def) return;
- setStyleFunction(
- def,
- def.vectorStyle.id,
- vectorStyles,
- null,
- state,
- );
+ const olLayer = olLayers.find((layer) => layer.wv.id === key);
+ setStyleFunction(def, def.vectorStyle.id, vectorStyles, olLayer, state);
}
}