Pass null as forEachFeatureAtPixel layer arg for unmanaged layers
This commit is contained in:
@@ -97,6 +97,8 @@ goog.inherits(ol.interaction.SelectEvent, goog.events.Event);
|
|||||||
* `toggle`, `add`/`remove`, and `multi` options; a `layers` filter; and a
|
* `toggle`, `add`/`remove`, and `multi` options; a `layers` filter; and a
|
||||||
* further feature filter using the `filter` option.
|
* further feature filter using the `filter` option.
|
||||||
*
|
*
|
||||||
|
* Selected features are added to an internal unmanaged layer.
|
||||||
|
*
|
||||||
* @constructor
|
* @constructor
|
||||||
* @extends {ol.interaction.Interaction}
|
* @extends {ol.interaction.Interaction}
|
||||||
* @param {olx.interaction.SelectOptions=} opt_options Options.
|
* @param {olx.interaction.SelectOptions=} opt_options Options.
|
||||||
|
|||||||
@@ -20,6 +20,11 @@ goog.require('ol.source.State');
|
|||||||
* Layers group together those properties that pertain to how the data is to be
|
* Layers group together those properties that pertain to how the data is to be
|
||||||
* displayed, irrespective of the source of that data.
|
* displayed, irrespective of the source of that data.
|
||||||
*
|
*
|
||||||
|
* Layers are usually added to a map with {@link ol.Map#addLayer}. Components
|
||||||
|
* like {@link ol.interaction.Select} use unmanaged layers internally. These
|
||||||
|
* unmanaged layers are associated with the map using
|
||||||
|
* {@link ol.layer.Layer#setMap} instead.
|
||||||
|
*
|
||||||
* A generic `change` event is fired when the state of the source changes.
|
* A generic `change` event is fired when the state of the source changes.
|
||||||
*
|
*
|
||||||
* @constructor
|
* @constructor
|
||||||
|
|||||||
@@ -599,8 +599,9 @@ ol.Map.prototype.disposeInternal = function() {
|
|||||||
* called with two arguments. The first argument is one
|
* called with two arguments. The first argument is one
|
||||||
* {@link ol.Feature feature} or
|
* {@link ol.Feature feature} or
|
||||||
* {@link ol.render.Feature render feature} at the pixel, the second is
|
* {@link ol.render.Feature render feature} at the pixel, the second is
|
||||||
* the {@link ol.layer.Layer layer} of the feature. To stop detection,
|
* the {@link ol.layer.Layer layer} of the feature and will be null for
|
||||||
* callback functions can return a truthy value.
|
* unmanaged layers. To stop detection, callback functions can return a
|
||||||
|
* truthy value.
|
||||||
* @param {S=} opt_this Value to use as `this` when executing `callback`.
|
* @param {S=} opt_this Value to use as `this` when executing `callback`.
|
||||||
* @param {(function(this: U, ol.layer.Layer): boolean)=} opt_layerFilter Layer
|
* @param {(function(this: U, ol.layer.Layer): boolean)=} opt_layerFilter Layer
|
||||||
* filter function. The filter function will receive one argument, the
|
* filter function. The filter function will receive one argument, the
|
||||||
|
|||||||
@@ -174,7 +174,9 @@ ol.renderer.Map.prototype.forEachFeatureAtCoordinate =
|
|||||||
if (layer.getSource()) {
|
if (layer.getSource()) {
|
||||||
result = layerRenderer.forEachFeatureAtCoordinate(
|
result = layerRenderer.forEachFeatureAtCoordinate(
|
||||||
layer.getSource().getWrapX() ? translatedCoordinate : coordinate,
|
layer.getSource().getWrapX() ? translatedCoordinate : coordinate,
|
||||||
frameState, callback, thisArg);
|
frameState,
|
||||||
|
layerState.managed ? callback : forEachFeatureAtCoordinate,
|
||||||
|
thisArg);
|
||||||
}
|
}
|
||||||
if (result) {
|
if (result) {
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -46,13 +46,23 @@ describe('ol.renderer.canvas.Map', function() {
|
|||||||
document.body.removeChild(target);
|
document.body.removeChild(target);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('always includes unmanaged layers', function() {
|
it('calls callback with layer for managed layers', function() {
|
||||||
|
map.addLayer(layer);
|
||||||
|
map.renderSync();
|
||||||
|
var cb = sinon.spy();
|
||||||
|
map.forEachFeatureAtPixel(map.getPixelFromCoordinate([0, 0]), cb);
|
||||||
|
expect(cb).to.be.called();
|
||||||
|
expect(cb.firstCall.args[1]).to.be(layer);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('includes unmanaged layers, but calls callback with null', 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, null,
|
||||||
function() { return false; });
|
function() { return false; });
|
||||||
expect(cb).to.be.called();
|
expect(cb).to.be.called();
|
||||||
|
expect(cb.firstCall.args[1]).to.be(null);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('filters managed layers', function() {
|
it('filters managed layers', function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user