Skip to content

Commit

Permalink
Refactor deprecated forEachLayerAtPixel
Browse files Browse the repository at this point in the history
  • Loading branch information
buehner committed Apr 21, 2023
1 parent 05df215 commit 105dde0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
15 changes: 12 additions & 3 deletions src/plugin/Hover.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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);
Expand Down
17 changes: 13 additions & 4 deletions src/plugin/HoverClick.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand All @@ -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) {

Expand Down Expand Up @@ -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);
}
}
});

},

/**
Expand Down

0 comments on commit 105dde0

Please sign in to comment.