From 4829f06bacec377e8d049ce916160e6cca12a5d8 Mon Sep 17 00:00:00 2001 From: jokd Date: Mon, 4 Apr 2022 10:43:05 +0200 Subject: [PATCH 1/6] Removed forEachLayerAtPixel method --- package-lock.json | 122 ++++++++++++++++++------------------------ package.json | 4 +- src/featureinfo.js | 16 +++--- src/getfeatureinfo.js | 54 ++----------------- 4 files changed, 67 insertions(+), 129 deletions(-) diff --git a/package-lock.json b/package-lock.json index cf5959bc9..5eeb3d1b1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -161,9 +161,9 @@ "integrity": "sha1-zlblOfg1UrWNENZy6k1vya3HsjQ=" }, "@mapbox/mapbox-gl-style-spec": { - "version": "13.23.0", - "resolved": "https://registry.npmjs.org/@mapbox/mapbox-gl-style-spec/-/mapbox-gl-style-spec-13.23.0.tgz", - "integrity": "sha512-zI26XoK0UjGOvOEUUAoKlmFKHrSD8qIMCaoQBsFxNPzGIluryT32Z1m4aq7NtxEsrfE+qc2mPPXQg+iRllqbqA==", + "version": "13.23.1", + "resolved": "https://registry.npmjs.org/@mapbox/mapbox-gl-style-spec/-/mapbox-gl-style-spec-13.23.1.tgz", + "integrity": "sha512-C6wh8A/5EdsgzhL6y6yl464VCQNIxK0yjrpnvCvchcFe3sNK2RbBw/J9u3m+p8Y6S6MsGuSMt3AkGAXOKMYweQ==", "requires": { "@mapbox/jsonlint-lines-primitives": "~2.0.2", "@mapbox/point-geometry": "^0.1.0", @@ -243,9 +243,9 @@ } }, "@petamoriken/float16": { - "version": "3.6.1", - "resolved": "https://registry.npmjs.org/@petamoriken/float16/-/float16-3.6.1.tgz", - "integrity": "sha512-SI0ovmGj/cUKYvxwbGl5TGDdFFCPLK3/zdOS0RCoYeYJMQZojsoiljIRwnBKxPFk/IsxI160Pk9n42O+XihQdw==" + "version": "3.6.3", + "resolved": "https://registry.npmjs.org/@petamoriken/float16/-/float16-3.6.3.tgz", + "integrity": "sha512-Yx6Z93kmz3JVPYoPPRFJXnt2/G4kfaxRROcZVVHsE4zOClJXvkOVidv/JfvP6hWn16lykbKYKVzUsId6mqXdGg==" }, "@polka/url": { "version": "1.0.0-next.21", @@ -1201,7 +1201,8 @@ "callsites": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz", - "integrity": "sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==" + "integrity": "sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==", + "dev": true }, "camelcase": { "version": "5.3.1", @@ -1548,6 +1549,7 @@ "version": "4.3.3", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.3.tgz", "integrity": "sha512-/zxw5+vh1Tfv+4Qn7a5nsbcJKPaSvCDhojn6FEl9vupwK2VCSDtEiEtqr8DFtzYFOdz63LBkxec7DYuc2jon6Q==", + "dev": true, "requires": { "ms": "2.1.2" } @@ -2127,12 +2129,6 @@ "schema-utils": "^3.1.1" } }, - "esm": { - "version": "3.2.25", - "resolved": "https://registry.npmjs.org/esm/-/esm-3.2.25.tgz", - "integrity": "sha512-U1suiZ2oDVWv4zPO56S0NcR5QriEahGtdN2OR6FiOG4WJvcjBVFB0qI4+eKoWFH483PKGuLuu6V8Z4T5g63UVA==", - "optional": true - }, "espree": { "version": "7.3.1", "resolved": "https://registry.npmjs.org/espree/-/espree-7.3.1.tgz", @@ -2594,17 +2590,24 @@ } }, "geotiff": { - "version": "1.0.9", - "resolved": "https://registry.npmjs.org/geotiff/-/geotiff-1.0.9.tgz", - "integrity": "sha512-PY+q1OP8RtQZkx1630pVfC3hEkxFnGW9LwIF/glSzcalyShkrH+W8uM/M4RVY12j4QkDQvRXVKOpU65hq6t0iQ==", + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/geotiff/-/geotiff-2.0.5.tgz", + "integrity": "sha512-U5kVYm118YAmw2swiLu8rhfrYnDKOFI7VaMjuQwcq6Intuuid9Pyb4jjxYUxxkq8kOu2r7Am0Rmb52PObGp4pQ==", "requires": { "@petamoriken/float16": "^3.4.7", "lerc": "^3.0.0", - "lru-cache": "^6.0.0", "pako": "^2.0.4", "parse-headers": "^2.0.2", - "threads": "^1.7.0", + "quick-lru": "^6.1.0", + "web-worker": "^1.2.0", "xml-utils": "^1.0.2" + }, + "dependencies": { + "quick-lru": { + "version": "6.1.1", + "resolved": "https://registry.npmjs.org/quick-lru/-/quick-lru-6.1.1.tgz", + "integrity": "sha512-S27GBT+F0NTRiehtbrgaSE1idUAJ5bX8dPAQTdylEyNlrdcH5X4Lz7Edz3DYzecbsCluD5zO8ZNEe04z3D3u6Q==" + } } }, "get-caller-file": { @@ -3255,11 +3258,6 @@ "has-tostringtag": "^1.0.0" } }, - "is-observable": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/is-observable/-/is-observable-2.1.0.tgz", - "integrity": "sha512-DailKdLb0WU+xX8K5w7VsJhapwHLZ9jjmazqCJq4X12CTgqq73TKnbRcnSLuXYPOoLQgV5IrD7ePiX/h1vnkBw==" - }, "is-path-cwd": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/is-path-cwd/-/is-path-cwd-2.2.0.tgz", @@ -3591,6 +3589,7 @@ "version": "6.0.0", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "dev": true, "requires": { "yallist": "^4.0.0" } @@ -3767,9 +3766,9 @@ } }, "minimist": { - "version": "1.2.5", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", - "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==" + "version": "1.2.6", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz", + "integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==" }, "minimist-options": { "version": "4.1.0", @@ -3864,7 +3863,8 @@ "ms": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", - "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", + "dev": true }, "multicast-dns": { "version": "6.2.3", @@ -3913,9 +3913,9 @@ "dev": true }, "node-forge": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/node-forge/-/node-forge-1.2.1.tgz", - "integrity": "sha512-Fcvtbb+zBcZXbTTVwqGA5W+MKBj56UjVRevvchv5XrcyXbmNdesfZL37nlcWOfpgHhgmxApw3tQbTr4CqNmX4w==", + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/node-forge/-/node-forge-1.3.1.tgz", + "integrity": "sha512-dPEtOeMvF9VMcYV/1Wb8CPoVAXtp6MKMlcbAt4ddqmGqUJ6fQZFXkNZNkNlfevtNkGtaSoXf/vNNNSvgrdXwtA==", "dev": true }, "node-gyp": { @@ -4306,11 +4306,6 @@ "es-abstract": "^1.19.1" } }, - "observable-fns": { - "version": "0.6.1", - "resolved": "https://registry.npmjs.org/observable-fns/-/observable-fns-0.6.1.tgz", - "integrity": "sha512-9gRK4+sRWzeN6AOewNBTLXir7Zl/i3GB6Yl26gK4flxz8BXVpD3kt8amREmWNb0mxYOGDotvE5a4N+PtGGKdkg==" - }, "obuf": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/obuf/-/obuf-1.1.2.tgz", @@ -4318,20 +4313,20 @@ "dev": true }, "ol": { - "version": "6.12.0", - "resolved": "https://registry.npmjs.org/ol/-/ol-6.12.0.tgz", - "integrity": "sha512-HR87aV//64aiGWbgzfsyRF5zFG+1nM1keRE4SugY0vmYyG/jjoij8qh3uaFHkFNQThdAy99sgLiQwTFk6AvGgw==", + "version": "6.14.1", + "resolved": "https://registry.npmjs.org/ol/-/ol-6.14.1.tgz", + "integrity": "sha512-sIcUWkGud3Y2gT3TJubSHlkyMXiPVh1yxfCPHxmY8+qtm79bB9oRnei9xHVIbRRG0Ro6Ldp5E+BMVSvYCxSpaA==", "requires": { - "geotiff": "^1.0.8", - "ol-mapbox-style": "^6.8.2", + "geotiff": "^2.0.2", + "ol-mapbox-style": "^7.1.1", "pbf": "3.2.1", "rbush": "^3.0.1" }, "dependencies": { "ol-mapbox-style": { - "version": "6.8.3", - "resolved": "https://registry.npmjs.org/ol-mapbox-style/-/ol-mapbox-style-6.8.3.tgz", - "integrity": "sha512-aX8aC3QHTYk9a37l6dKcC22OUkFWz01eHShbXYdXABwT9ih1MLcjR32OYCWCKasKZMEXYKyeTh9vLhOtdfx/vA==", + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/ol-mapbox-style/-/ol-mapbox-style-7.1.1.tgz", + "integrity": "sha512-GLTEYiH/Ec9Zn1eS4S/zXyR2sierVrUc+OLVP8Ra0FRyqRhoYbXdko0b7OIeSHWdtJfHssWYefDOGxfTRUUZ/A==", "requires": { "@mapbox/mapbox-gl-style-spec": "^13.20.1", "mapbox-to-css-font": "^2.4.1", @@ -4341,9 +4336,9 @@ } }, "ol-mapbox-style": { - "version": "6.8.3", - "resolved": "https://registry.npmjs.org/ol-mapbox-style/-/ol-mapbox-style-6.8.3.tgz", - "integrity": "sha512-aX8aC3QHTYk9a37l6dKcC22OUkFWz01eHShbXYdXABwT9ih1MLcjR32OYCWCKasKZMEXYKyeTh9vLhOtdfx/vA==", + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/ol-mapbox-style/-/ol-mapbox-style-7.1.0.tgz", + "integrity": "sha512-t0SXs+TB+zZOjjqOU6dbUvl9caR/5ur2rfCi28yMXc8GYNJJfYJty27ecbGVt8ABKOr9LnjNxl6BWmanxEpjbQ==", "requires": { "@mapbox/mapbox-gl-style-spec": "^13.20.1", "mapbox-to-css-font": "^2.4.1", @@ -4472,9 +4467,9 @@ } }, "parse-headers": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/parse-headers/-/parse-headers-2.0.4.tgz", - "integrity": "sha512-psZ9iZoCNFLrgRjZ1d8mn0h9WRqJwFxM9q3x7iUjN/YT2OksthDJ5TiPCu2F38kS4zutqfW+YdVVkBZZx3/1aw==" + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/parse-headers/-/parse-headers-2.0.5.tgz", + "integrity": "sha512-ft3iAoLOB/MlwbNXgzy43SWGP6sQki2jQvAyBg/zDFAgr9bfNWZIUj42Kw2eJIl8kEi4PbgE6U1Zau/HwI75HA==" }, "parse-json": { "version": "5.2.0", @@ -6001,18 +5996,6 @@ "integrity": "sha1-f17oI66AUgfACvLfSoTsP8+lcLQ=", "dev": true }, - "threads": { - "version": "1.7.0", - "resolved": "https://registry.npmjs.org/threads/-/threads-1.7.0.tgz", - "integrity": "sha512-Mx5NBSHX3sQYR6iI9VYbgHKBLisyB+xROCBGjjWm1O9wb9vfLxdaGtmT/KCjUqMsSNW6nERzCW3T6H43LqjDZQ==", - "requires": { - "callsites": "^3.1.0", - "debug": "^4.2.0", - "is-observable": "^2.1.0", - "observable-fns": "^0.6.1", - "tiny-worker": ">= 2" - } - }, "through2": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/through2/-/through2-2.0.5.tgz", @@ -6073,15 +6056,6 @@ "integrity": "sha1-dkpaEa9QVhkhsTPztE5hhofg9cM=", "dev": true }, - "tiny-worker": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/tiny-worker/-/tiny-worker-2.3.0.tgz", - "integrity": "sha512-pJ70wq5EAqTAEl9IkGzA+fN0836rycEuz2Cn6yeZ6FRzlVS5IDOkFHpIoEsksPRQV34GDqXm65+OlnZqUSyK2g==", - "optional": true, - "requires": { - "esm": "^3.2.25" - } - }, "to-regex-range": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", @@ -6317,6 +6291,11 @@ "minimalistic-assert": "^1.0.0" } }, + "web-worker": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/web-worker/-/web-worker-1.2.0.tgz", + "integrity": "sha512-PgF341avzqyx60neE9DD+XS26MMNMoUQRz9NOZwW32nPQrF6p77f1htcnjBSEV8BGMKZ16choqUG4hyI0Hx7mA==" + }, "webfont-matcher": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/webfont-matcher/-/webfont-matcher-1.1.0.tgz", @@ -6702,7 +6681,8 @@ "yallist": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", - "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", + "dev": true }, "yargs": { "version": "16.2.0", diff --git a/package.json b/package.json index cea18fd6e..448dbfdd4 100644 --- a/package.json +++ b/package.json @@ -39,9 +39,9 @@ "downloadjs": "^1.4.7", "elm-pep": "^1.0.6", "html2canvas": "^1.4.0", - "ol-mapbox-style": "6.8.3", + "ol-mapbox-style": "7.1.0", "jspdf": "^2.5.0", - "ol": "^6.12.0", + "ol": "^6.14.1", "pepjs": "^0.5.3", "proj4": "^2.7.5" }, diff --git a/src/featureinfo.js b/src/featureinfo.js index 6a0523e26..5ec2cbbae 100644 --- a/src/featureinfo.js +++ b/src/featureinfo.js @@ -662,13 +662,15 @@ const Featureinfo = function Featureinfo(options = {}) { // Check if there is a clickable feature when mouse is moved. map.on('pointermove', evt => { if (!pointerActive || evt.dragging) return; - // Just check if there is a pixel here. Pretty annoying on hatched symbols or hollow areas. - // Note that forEachLayerAtPixel actually only checks if there is a pixel on the canvas where the layer resides, - // so non queryable layers must not share canvas with queryable layers, otherwise there will be false positives. - // When a pixel is found on the canvas, the callback is called with all layers added to that canvas as it does not know which layer actually draw a pixel there. But we don't care which - // layer was hit to change the pointer. - // Hit tolerence seems to be ignored. It would probably look funny anyway. - map.getViewport().style.cursor = map.forEachLayerAtPixel(evt.pixel, () => true, { layerFilter: (l) => l.get('queryable') }) ? 'pointer' : ''; + let cursor = ''; + viewer.getQueryableLayers().some(layer => { + if (layer.getData(evt.pixel) instanceof Uint8ClampedArray && layer.getData(evt.pixel)[3] > 0) { + cursor = 'pointer'; + return true; + } + return false; + }); + map.getViewport().style.cursor = cursor; }); } }, diff --git a/src/getfeatureinfo.js b/src/getfeatureinfo.js index 93dbd0ffc..541a792fa 100644 --- a/src/getfeatureinfo.js +++ b/src/getfeatureinfo.js @@ -135,31 +135,6 @@ function getAGSIdentifyUrl({ layer, coordinate }, viewer) { }).catch(error => console.error(error)); } -function isTainted({ - pixel, - layerFilter, - map -}) { - try { - if (layerFilter) { - map.forEachLayerAtPixel(pixel, (layer) => layerFilter === layer); - } - - return false; - } catch (e) { - console.error(e); - return true; - } -} - -function layerAtPixel({ - pixel, - matchLayer, - map -}) { - map.forEachLayerAtPixel(pixel, (layer) => matchLayer === layer); -} - function getGetFeatureInfoRequest({ layer, coordinate }, viewer) { const layerType = layer.get('type'); const obj = {}; @@ -201,41 +176,22 @@ function getGetFeatureInfoRequest({ layer, coordinate }, viewer) { function getFeatureInfoRequests({ coordinate, - layers, - map, pixel }, viewer) { const requests = []; // Check for support of crossOrigin in image, absent in IE 8 and 9 if ('crossOrigin' in new (Image)()) { - map.forEachLayerAtPixel(pixel, (layer) => { - if (layer.get('queryable')) { + viewer.getQueryableLayers().forEach(layer => { + if (layer.getData(pixel) instanceof Uint8ClampedArray && layer.getData(pixel)[3] > 0) { const item = getGetFeatureInfoRequest({ layer, coordinate }, viewer); if (item) { requests.push(item); } } }); - } else if (isTainted({ map, pixel })) { // If canvas is tainted - layers.forEach((layer) => { - if (layer.get('queryable')) { - // If layer is tainted, then create request for layer - if (isTainted({ pixel, layer, map })) { - const item = getGetFeatureInfoRequest({ layer, coordinate }, viewer); - if (item) { - requests.push(item); - } - } else if (layerAtPixel({ pixel, layer, map })) { // If layer is not tainted, test if layer hit at pixel - const item = getGetFeatureInfoRequest({ layer, coordinate }, viewer); - if (item) { - requests.push(item); - } - } - } - }); - } else { // If crossOrigin is not supported and canvas not tainted - map.forEachLayerAtPixel(pixel, (layer) => { - if (layer.get('queryable') === true) { + } else { // If crossOrigin is not supported + viewer.getQueryableLayers().forEach(layer => { + if (layer.getData(pixel) instanceof Uint8ClampedArray && layer.getData(pixel)[3] > 0) { const item = getGetFeatureInfoRequest({ layer, coordinate }, viewer); if (item) { requests.push(item); From eb3c32b59014c50ab4dcef35feae1596d6ca38dc Mon Sep 17 00:00:00 2001 From: jokd Date: Mon, 4 Apr 2022 10:53:46 +0200 Subject: [PATCH 2/6] Removed unnecessary code --- src/getfeatureinfo.js | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/src/getfeatureinfo.js b/src/getfeatureinfo.js index 541a792fa..776618e90 100644 --- a/src/getfeatureinfo.js +++ b/src/getfeatureinfo.js @@ -179,26 +179,14 @@ function getFeatureInfoRequests({ pixel }, viewer) { const requests = []; - // Check for support of crossOrigin in image, absent in IE 8 and 9 - if ('crossOrigin' in new (Image)()) { - viewer.getQueryableLayers().forEach(layer => { - if (layer.getData(pixel) instanceof Uint8ClampedArray && layer.getData(pixel)[3] > 0) { - const item = getGetFeatureInfoRequest({ layer, coordinate }, viewer); - if (item) { - requests.push(item); - } - } - }); - } else { // If crossOrigin is not supported - viewer.getQueryableLayers().forEach(layer => { - if (layer.getData(pixel) instanceof Uint8ClampedArray && layer.getData(pixel)[3] > 0) { - const item = getGetFeatureInfoRequest({ layer, coordinate }, viewer); - if (item) { - requests.push(item); - } + viewer.getQueryableLayers().forEach(layer => { + if (layer.getData(pixel) instanceof Uint8ClampedArray && layer.getData(pixel)[3] > 0) { + const item = getGetFeatureInfoRequest({ layer, coordinate }, viewer); + if (item) { + requests.push(item); } - }); - } + } + }); return requests; } From 7e2f9ed2b248fb3626402a99a259a291680e7e56 Mon Sep 17 00:00:00 2001 From: jokd Date: Mon, 4 Apr 2022 13:22:06 +0200 Subject: [PATCH 3/6] Support for vector layer --- src/featureinfo.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/featureinfo.js b/src/featureinfo.js index 5ec2cbbae..0629c8d8d 100644 --- a/src/featureinfo.js +++ b/src/featureinfo.js @@ -1,4 +1,6 @@ import Overlay from 'ol/Overlay'; +import TileLayer from 'ol/layer/Tile'; +import VectorLayer from 'ol/layer/Vector'; import OGlide from './oglide'; import { Component, Modal } from './ui'; import Popup from './popup'; @@ -663,13 +665,20 @@ const Featureinfo = function Featureinfo(options = {}) { map.on('pointermove', evt => { if (!pointerActive || evt.dragging) return; let cursor = ''; - viewer.getQueryableLayers().some(layer => { - if (layer.getData(evt.pixel) instanceof Uint8ClampedArray && layer.getData(evt.pixel)[3] > 0) { + const layers = viewer.getQueryableLayers(); + for (let i = 0; i < layers.length; i += 1) { + const layer = layers[i]; + if (layer instanceof TileLayer && layer.getData(evt.pixel) instanceof Uint8ClampedArray && layer.getData(evt.pixel)[3] > 0) { cursor = 'pointer'; - return true; + break; } - return false; - }); + if (layer instanceof VectorLayer) { + if (map.getFeaturesAtPixel(evt.pixel).length > 0) { + cursor = 'pointer'; + break; + } + } + } map.getViewport().style.cursor = cursor; }); } From 5b55973616e09840083a4a2684ce0765c3ca2666 Mon Sep 17 00:00:00 2001 From: jokd Date: Mon, 4 Apr 2022 13:27:53 +0200 Subject: [PATCH 4/6] Removed o-layer-queryable class from layers --- src/layer.js | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/layer.js b/src/layer.js index 66bda81dc..a1c48cdf9 100644 --- a/src/layer.js +++ b/src/layer.js @@ -59,18 +59,6 @@ const Layer = function Layer(optOptions, viewer) { layerOptions.className = layerOptions.cls || `o-layer-${layerOptions.name}`; } - // changePointerOnHover requires that non queryable layers are not drawn on the same canvas as queryable layers. - // OL will merge layers to the same canvas if they have the same class and some other reconcilable properties. - // Note that the merge preserves layer ordering, so if a layer can not use same canvas as previous layer, a new - // canvas will be created, so keep layers with same properties together. - // Make sure that queryable layers get a class name to avoid merging with non queryable layers. - // A unique class would be best, but produces a new canvas for each layer, which could affect the - // performance. - // If user has configured a className then keep it and let the user take the consequences if they mix queryable and non queryable layers. - if (viewer.getViewerOptions().featureinfoOptions.changePointerOnHover && layerOptions.queryable && !layerOptions.className) { - layerOptions.className = 'o-layer-queryable'; - } - if (layerOptions.type) { const layer = type[layerOptions.type](layerOptions, viewer); layer.once('postrender', onChangeVisible); From 9c3d1b9ca74edb9abf7c8f5925fb79815f6cdbaa Mon Sep 17 00:00:00 2001 From: jokd Date: Mon, 4 Apr 2022 14:44:55 +0200 Subject: [PATCH 5/6] Fix --- src/featureinfo.js | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/featureinfo.js b/src/featureinfo.js index 0629c8d8d..57bc082a4 100644 --- a/src/featureinfo.js +++ b/src/featureinfo.js @@ -1,6 +1,5 @@ import Overlay from 'ol/Overlay'; import TileLayer from 'ol/layer/Tile'; -import VectorLayer from 'ol/layer/Vector'; import OGlide from './oglide'; import { Component, Modal } from './ui'; import Popup from './popup'; @@ -665,15 +664,17 @@ const Featureinfo = function Featureinfo(options = {}) { map.on('pointermove', evt => { if (!pointerActive || evt.dragging) return; let cursor = ''; - const layers = viewer.getQueryableLayers(); - for (let i = 0; i < layers.length; i += 1) { - const layer = layers[i]; - if (layer instanceof TileLayer && layer.getData(evt.pixel) instanceof Uint8ClampedArray && layer.getData(evt.pixel)[3] > 0) { - cursor = 'pointer'; - break; - } - if (layer instanceof VectorLayer) { - if (map.getFeaturesAtPixel(evt.pixel).length > 0) { + const features = map.getFeaturesAtPixel(evt.pixel, { layerFilter(layer) { + return layer.get('queryable'); + } + }); + if (features.length > 0) { + cursor = 'pointer'; + } else { + const layers = viewer.getQueryableLayers().filter(layer => layer instanceof TileLayer); + for (let i = 0; i < layers.length; i += 1) { + const layer = layers[i]; + if (layer.getData(evt.pixel) instanceof Uint8ClampedArray && layer.getData(evt.pixel)[3] > 0) { cursor = 'pointer'; break; } From bcf780898db3144c7fc7e298e5f80dabf089c423 Mon Sep 17 00:00:00 2001 From: jokd Date: Wed, 1 Jun 2022 12:00:27 +0200 Subject: [PATCH 6/6] Added ImageLayer support --- src/featureinfo.js | 8 +++++--- src/getfeatureinfo.js | 7 +++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/featureinfo.js b/src/featureinfo.js index 57bc082a4..4ec41d45e 100644 --- a/src/featureinfo.js +++ b/src/featureinfo.js @@ -1,5 +1,6 @@ import Overlay from 'ol/Overlay'; -import TileLayer from 'ol/layer/Tile'; +import BaseTileLayer from 'ol/layer/BaseTile'; +import ImageLayer from 'ol/layer/Image'; import OGlide from './oglide'; import { Component, Modal } from './ui'; import Popup from './popup'; @@ -671,10 +672,11 @@ const Featureinfo = function Featureinfo(options = {}) { if (features.length > 0) { cursor = 'pointer'; } else { - const layers = viewer.getQueryableLayers().filter(layer => layer instanceof TileLayer); + const layers = viewer.getQueryableLayers().filter(layer => layer instanceof BaseTileLayer || layer instanceof ImageLayer); for (let i = 0; i < layers.length; i += 1) { const layer = layers[i]; - if (layer.getData(evt.pixel) instanceof Uint8ClampedArray && layer.getData(evt.pixel)[3] > 0) { + const pixelVal = layer.getData(evt.pixel); + if (pixelVal instanceof Uint8ClampedArray && pixelVal[3] > 0) { cursor = 'pointer'; break; } diff --git a/src/getfeatureinfo.js b/src/getfeatureinfo.js index 776618e90..f2e3f7852 100644 --- a/src/getfeatureinfo.js +++ b/src/getfeatureinfo.js @@ -1,4 +1,6 @@ import EsriJSON from 'ol/format/EsriJSON'; +import BaseTileLayer from 'ol/layer/BaseTile'; +import ImageLayer from 'ol/layer/Image'; import maputils from './maputils'; import SelectedItem from './models/SelectedItem'; @@ -179,8 +181,9 @@ function getFeatureInfoRequests({ pixel }, viewer) { const requests = []; - viewer.getQueryableLayers().forEach(layer => { - if (layer.getData(pixel) instanceof Uint8ClampedArray && layer.getData(pixel)[3] > 0) { + viewer.getQueryableLayers().filter(layer => layer instanceof BaseTileLayer || layer instanceof ImageLayer).forEach(layer => { + const pixelVal = layer.getData(pixel); + if (pixelVal instanceof Uint8ClampedArray && pixelVal[3] > 0) { const item = getGetFeatureInfoRequest({ layer, coordinate }, viewer); if (item) { requests.push(item);