From 105dde03e821cb480e54b614fefdd86d27815cde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nils=20B=C3=BChner?= Date: Fri, 21 Apr 2023 14:08:26 +0200 Subject: [PATCH] Refactor deprecated forEachLayerAtPixel --- src/plugin/Hover.js | 15 ++++++++++++--- src/plugin/HoverClick.js | 17 +++++++++++++---- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/plugin/Hover.js b/src/plugin/Hover.js index 107f28493..88bf1e7bd 100644 --- a/src/plugin/Hover.js +++ b/src/plugin/Hover.js @@ -327,6 +327,7 @@ Ext.define('BasiGX.plugin.Hover', { var mapComponent = me.getCmp(); var map = mapComponent.getMap(); var mapView = map.getView(); + var allLayers = map.getAllLayers(); var pixel = evt.pixel; var hoverableProp = me.self.LAYER_HOVERABLE_PROPERTY_NAME; var hoverFeaturesRevertProp = me.self.LAYER_HOVER_FEATURES_REVERT_NAME; @@ -335,7 +336,7 @@ Ext.define('BasiGX.plugin.Hover', { me.cleanupHoverArtifacts(); - map.forEachLayerAtPixel(pixel, function(layer, pixelValues) { + var callback = function(layer, pixelValues) { var source = layer.getSource(); var resolution = mapView.getResolution(); var projCode = mapView.getProjection().getCode(); @@ -423,8 +424,16 @@ Ext.define('BasiGX.plugin.Hover', { }); } } - }, { - layerFilter: me.hoverLayerFilter.bind(me) + }; + + allLayers.forEach(function(lyr) { + var layerData = lyr.getData(pixel); + if (layerData) { + var alphaValue = layerData.at(3); + if (alphaValue > 0 && me.hoverLayerFilter(lyr)) { + callback(lyr, layerData); + } + } }); me.showHoverToolTip(evt, hoverLayers, hoverFeatures); diff --git a/src/plugin/HoverClick.js b/src/plugin/HoverClick.js index 90e4bbd32..679374734 100644 --- a/src/plugin/HoverClick.js +++ b/src/plugin/HoverClick.js @@ -140,6 +140,7 @@ Ext.define('BasiGX.plugin.HoverClick', { var mapComponent = me.getCmp(); var map = mapComponent.getMap(); var mapView = map.getView(); + var allLayers = map.getAllLayers(); var pixel = evt.pixel; var hoverFeaturesRevertProp = me.self.LAYER_HOVER_FEATURES_REVERT_NAME; var clickableProp = me.self.LAYER_CLICKABLE_PROPERTY_NAME; @@ -148,7 +149,7 @@ Ext.define('BasiGX.plugin.HoverClick', { me.cleanupHoverArtifacts(); - map.forEachLayerAtPixel(pixel, function(layer, pixelValues) { + var callback = function(layer, pixelValues) { if (!layer.get(clickableProp)) { return; } @@ -158,7 +159,6 @@ Ext.define('BasiGX.plugin.HoverClick', { var projCode = mapView.getProjection().getCode(); var hoverFeaturesRevert = layer.get(hoverFeaturesRevertProp); - if (source instanceof ol.source.TileWMS || source instanceof ol.source.ImageWMS) { @@ -235,9 +235,18 @@ Ext.define('BasiGX.plugin.HoverClick', { } }); } - }, { - layerFilter: me.clickLayerFilter.bind(me) + }; + + allLayers.forEach(function(lyr) { + var layerData = lyr.getData(pixel); + if (layerData) { + var alphaValue = layerData.at(3); + if (alphaValue > 0 && me.clickLayerFilter(lyr)) { + callback(lyr, layerData); + } + } }); + }, /**