Change signature of api methods

This commit is contained in:
simonseyock
2016-10-19 13:24:15 +02:00
committed by simonseyock
parent a6c768ae07
commit 80188b2044
4 changed files with 40 additions and 21 deletions

View File

@@ -200,7 +200,9 @@ ol.interaction.Select.handleEvent = function(mapBrowserEvent) {
// pixel, or clear the selected feature(s) if there is no feature at
// the pixel.
ol.obj.clear(this.featureLayerAssociation_);
map.forEachFeatureAtPixel(mapBrowserEvent.pixel,
map.forEachFeatureAtPixel(mapBrowserEvent.pixel, {
layerFilter: this.layerFilter_
},
/**
* @param {ol.Feature|ol.render.Feature} feature Feature.
* @param {ol.layer.Layer} layer Layer.
@@ -212,7 +214,7 @@ ol.interaction.Select.handleEvent = function(mapBrowserEvent) {
this.addFeatureLayerAssociation_(feature, layer);
return !this.multi_;
}
}, this, this.layerFilter_);
}, this);
var i;
for (i = features.getLength() - 1; i >= 0; --i) {
var feature = features.item(i);
@@ -230,7 +232,9 @@ ol.interaction.Select.handleEvent = function(mapBrowserEvent) {
}
} else {
// Modify the currently selected feature(s).
map.forEachFeatureAtPixel(mapBrowserEvent.pixel,
map.forEachFeatureAtPixel(mapBrowserEvent.pixel, {
layerFilter: this.layerFilter_
},
/**
* @param {ol.Feature|ol.render.Feature} feature Feature.
* @param {ol.layer.Layer} layer Layer.
@@ -249,7 +253,7 @@ ol.interaction.Select.handleEvent = function(mapBrowserEvent) {
}
return !this.multi_;
}
}, this, this.layerFilter_);
}, this);
var j;
for (j = deselected.length - 1; j >= 0; --j) {
features.remove(deselected[j]);

View File

@@ -197,7 +197,9 @@ ol.interaction.Translate.prototype.featuresAtPixel_ = function(pixel, map) {
ol.array.includes(this.features_.getArray(), feature)) {
return feature;
}
}, this, this.layerFilter_);
}, this, {
layerFilter: this.layerFilter_
});
};

View File

@@ -554,11 +554,26 @@ ol.Map.prototype.disposeInternal = function() {
};
/**
* @typedef {object} ol.MapForEachFeatureOptions
* @property {(function(this: U, ol.layer.Layer): boolean)=} layerFilter Layer
* filter function. The filter function will receive one argument, the
* {@link ol.layer.Layer layer-candidate} and it should return a boolean
* value. Only layers which are visible and for which this function returns
* `true` will be tested for features. By default, all visible layers will
* be tested.
* @property {U=} layerFilterThis Value to use as `this` when executing `layerFilter`.
* @property {number=} hitTolerance the hitTolerance in pixels in which features
* get hit.
*/
/**
* Detect features that intersect a pixel on the viewport, and execute a
* callback with each intersecting feature. Layers included in the detection can
* be configured through `opt_layerFilter`.
* @param {ol.Pixel} pixel Pixel.
* @param {ol.MapForEachFeatureOptions=} opt_options
* @param {function(this: S, (ol.Feature|ol.render.Feature),
* ol.layer.Layer): T} callback Feature callback. The callback will be
* called with two arguments. The first argument is one
@@ -567,30 +582,27 @@ ol.Map.prototype.disposeInternal = function() {
* the {@link ol.layer.Layer layer} of the feature and will be null for
* 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 {(function(this: U, ol.layer.Layer): boolean)=} opt_layerFilter Layer
* filter function. The filter function will receive one argument, the
* {@link ol.layer.Layer layer-candidate} and it should return a boolean
* value. Only layers which are visible and for which this function returns
* `true` will be tested for features. By default, all visible layers will
* be tested.
* @param {U=} opt_this2 Value to use as `this` when executing `layerFilter`.
* @param {S=} opt_this
* @return {T|undefined} Callback result, i.e. the return value of last
* callback execution, or the first truthy callback return value.
* @template S,T,U
* @api stable
*/
ol.Map.prototype.forEachFeatureAtPixel = function(pixel, callback, opt_this, opt_layerFilter, opt_this2) {
ol.Map.prototype.forEachFeatureAtPixel = function(pixel, opt_options, callback, opt_this) {
if (typeof opt_options !== 'object') {
opt_this = callback;
callback = opt_options;
opt_options = {};
}
if (!this.frameState_) {
return;
}
var coordinate = this.getCoordinateFromPixel(pixel);
var thisArg = opt_this !== undefined ? opt_this : null;
var layerFilter = opt_layerFilter !== undefined ?
opt_layerFilter : ol.functions.TRUE;
var thisArg2 = opt_this2 !== undefined ? opt_this2 : null;
var layerFilter = opt_options.layerFilter || ol.functions.TRUE;
var thisArg2 = opt_options.layerFilterThis || null;
return this.renderer_.forEachFeatureAtCoordinate(
coordinate, this.frameState_, callback, thisArg,
coordinate, this.frameState_, opt_options.hitTolerance || 0, callback, thisArg,
layerFilter, thisArg2);
};

View File

@@ -111,10 +111,11 @@ describe('ol.renderer.canvas.Map', function() {
map.addLayer(layer);
map.renderSync();
var cb = sinon.spy();
map.forEachFeatureAtPixel(map.getPixelFromCoordinate([0, 0]), cb, null,
function() {
map.forEachFeatureAtPixel(map.getPixelFromCoordinate([0, 0]), {
layerFilter: function() {
return false;
});
}
}, cb);
expect(cb).to.not.be.called();
});