Do not ignore layer filter for unmanaged layers
PR #3883 made `forEachFeatureAtPixel` ignore unmanaged layers. This commit reverts that change.
This commit is contained in:
committed by
Andreas Hocevar
parent
6897e3cc52
commit
279eae1dba
@@ -283,7 +283,7 @@ ol.interaction.Select.handleEvent = function(mapBrowserEvent) {
|
|||||||
* @param {ol.layer.Layer} layer Layer.
|
* @param {ol.layer.Layer} layer Layer.
|
||||||
*/
|
*/
|
||||||
function(feature, layer) {
|
function(feature, layer) {
|
||||||
if (!layer || this.filter_(feature, layer)) {
|
if (this.filter_(feature, layer)) {
|
||||||
selected.push(feature);
|
selected.push(feature);
|
||||||
this.addFeatureLayerAssociation_(feature, layer);
|
this.addFeatureLayerAssociation_(feature, layer);
|
||||||
return !this.multi_;
|
return !this.multi_;
|
||||||
|
|||||||
@@ -153,11 +153,11 @@ ol.layer.Layer.prototype.handleSourcePropertyChange_ = function() {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the layer to be rendered on a map. The map will not manage this layer in
|
* Sets the layer to be rendered on top of other layers on a map. The map will
|
||||||
* its layers collection, layer filters in {@link ol.Map#forEachLayerAtPixel}
|
* not manage this layer in its layers collection, and the callback in
|
||||||
* will not filter the layer, and it will be rendered on top. This is useful for
|
* {@link ol.Map#forEachLayerAtPixel} will receive `null` as layer. This
|
||||||
* temporary layers. To remove an unmanaged layer from the map, use
|
* is useful for temporary layers. To remove an unmanaged layer from the map,
|
||||||
* `#setMap(null)`.
|
* use `#setMap(null)`.
|
||||||
*
|
*
|
||||||
* To add the layer to a map and have it managed by the map, use
|
* To add the layer to a map and have it managed by the map, use
|
||||||
* {@link ol.Map#addLayer} instead.
|
* {@link ol.Map#addLayer} instead.
|
||||||
|
|||||||
@@ -167,9 +167,8 @@ ol.renderer.Map.prototype.forEachFeatureAtCoordinate =
|
|||||||
for (i = numLayers - 1; i >= 0; --i) {
|
for (i = numLayers - 1; i >= 0; --i) {
|
||||||
var layerState = layerStates[i];
|
var layerState = layerStates[i];
|
||||||
var layer = layerState.layer;
|
var layer = layerState.layer;
|
||||||
if (!layerState.managed ||
|
if (ol.layer.Layer.visibleAtResolution(layerState, viewResolution) &&
|
||||||
(ol.layer.Layer.visibleAtResolution(layerState, viewResolution) &&
|
layerFilter.call(thisArg2, layer)) {
|
||||||
layerFilter.call(thisArg2, layer))) {
|
|
||||||
var layerRenderer = this.getLayerRenderer(layer);
|
var layerRenderer = this.getLayerRenderer(layer);
|
||||||
if (layer.getSource()) {
|
if (layer.getSource()) {
|
||||||
result = layerRenderer.forEachFeatureAtCoordinate(
|
result = layerRenderer.forEachFeatureAtCoordinate(
|
||||||
|
|||||||
@@ -161,29 +161,6 @@ describe('ol.interaction.Select', function() {
|
|||||||
describe('filter features using the filter option', function() {
|
describe('filter features using the filter option', function() {
|
||||||
var select;
|
var select;
|
||||||
|
|
||||||
describe('with unmanaged layers', function() {
|
|
||||||
it('does not call filter for unmanaged layers', function() {
|
|
||||||
var spy = sinon.spy();
|
|
||||||
var select = new ol.interaction.Select({
|
|
||||||
multi: false,
|
|
||||||
filter: spy
|
|
||||||
});
|
|
||||||
map.addInteraction(select);
|
|
||||||
var feature = new ol.Feature(
|
|
||||||
new ol.geom.Polygon([[[0, 0], [0, 40], [40, 40], [40, 0]]]));
|
|
||||||
var unmanaged = new ol.layer.Vector({
|
|
||||||
source: new ol.source.Vector({
|
|
||||||
features: [feature]
|
|
||||||
})
|
|
||||||
});
|
|
||||||
unmanaged.setMap(map);
|
|
||||||
map.renderSync();
|
|
||||||
simulateEvent(ol.MapBrowserEvent.EventType.SINGLECLICK, 10, -20);
|
|
||||||
expect(spy.getCalls().length).to.be(0);
|
|
||||||
unmanaged.setMap(null);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('with multi set to true', function() {
|
describe('with multi set to true', function() {
|
||||||
|
|
||||||
it('only selects features that pass the filter', function() {
|
it('only selects features that pass the filter', function() {
|
||||||
|
|||||||
@@ -55,12 +55,11 @@ describe('ol.renderer.canvas.Map', function() {
|
|||||||
expect(cb.firstCall.args[1]).to.be(layer);
|
expect(cb.firstCall.args[1]).to.be(layer);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('includes unmanaged layers, but calls callback with null', function() {
|
it('calls callback with null for unmanaged layers', function() {
|
||||||
layer.setMap(map);
|
layer.setMap(map);
|
||||||
map.renderSync();
|
map.renderSync();
|
||||||
var cb = sinon.spy();
|
var cb = sinon.spy();
|
||||||
map.forEachFeatureAtPixel(map.getPixelFromCoordinate([0, 0]), cb, null,
|
map.forEachFeatureAtPixel(map.getPixelFromCoordinate([0, 0]), cb);
|
||||||
function() { return false; });
|
|
||||||
expect(cb).to.be.called();
|
expect(cb).to.be.called();
|
||||||
expect(cb.firstCall.args[1]).to.be(null);
|
expect(cb.firstCall.args[1]).to.be(null);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user