Change signature of api methods
This commit is contained in:
@@ -200,7 +200,9 @@ ol.interaction.Select.handleEvent = function(mapBrowserEvent) {
|
|||||||
// pixel, or clear the selected feature(s) if there is no feature at
|
// pixel, or clear the selected feature(s) if there is no feature at
|
||||||
// the pixel.
|
// the pixel.
|
||||||
ol.obj.clear(this.featureLayerAssociation_);
|
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.Feature|ol.render.Feature} feature Feature.
|
||||||
* @param {ol.layer.Layer} layer Layer.
|
* @param {ol.layer.Layer} layer Layer.
|
||||||
@@ -212,7 +214,7 @@ ol.interaction.Select.handleEvent = function(mapBrowserEvent) {
|
|||||||
this.addFeatureLayerAssociation_(feature, layer);
|
this.addFeatureLayerAssociation_(feature, layer);
|
||||||
return !this.multi_;
|
return !this.multi_;
|
||||||
}
|
}
|
||||||
}, this, this.layerFilter_);
|
}, this);
|
||||||
var i;
|
var i;
|
||||||
for (i = features.getLength() - 1; i >= 0; --i) {
|
for (i = features.getLength() - 1; i >= 0; --i) {
|
||||||
var feature = features.item(i);
|
var feature = features.item(i);
|
||||||
@@ -230,7 +232,9 @@ ol.interaction.Select.handleEvent = function(mapBrowserEvent) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Modify the currently selected feature(s).
|
// 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.Feature|ol.render.Feature} feature Feature.
|
||||||
* @param {ol.layer.Layer} layer Layer.
|
* @param {ol.layer.Layer} layer Layer.
|
||||||
@@ -249,7 +253,7 @@ ol.interaction.Select.handleEvent = function(mapBrowserEvent) {
|
|||||||
}
|
}
|
||||||
return !this.multi_;
|
return !this.multi_;
|
||||||
}
|
}
|
||||||
}, this, this.layerFilter_);
|
}, this);
|
||||||
var j;
|
var j;
|
||||||
for (j = deselected.length - 1; j >= 0; --j) {
|
for (j = deselected.length - 1; j >= 0; --j) {
|
||||||
features.remove(deselected[j]);
|
features.remove(deselected[j]);
|
||||||
|
|||||||
@@ -197,7 +197,9 @@ ol.interaction.Translate.prototype.featuresAtPixel_ = function(pixel, map) {
|
|||||||
ol.array.includes(this.features_.getArray(), feature)) {
|
ol.array.includes(this.features_.getArray(), feature)) {
|
||||||
return feature;
|
return feature;
|
||||||
}
|
}
|
||||||
}, this, this.layerFilter_);
|
}, this, {
|
||||||
|
layerFilter: this.layerFilter_
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+25
-13
@@ -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
|
* Detect features that intersect a pixel on the viewport, and execute a
|
||||||
* callback with each intersecting feature. Layers included in the detection can
|
* callback with each intersecting feature. Layers included in the detection can
|
||||||
* be configured through `opt_layerFilter`.
|
* be configured through `opt_layerFilter`.
|
||||||
* @param {ol.Pixel} pixel Pixel.
|
* @param {ol.Pixel} pixel Pixel.
|
||||||
|
* @param {ol.MapForEachFeatureOptions=} opt_options
|
||||||
* @param {function(this: S, (ol.Feature|ol.render.Feature),
|
* @param {function(this: S, (ol.Feature|ol.render.Feature),
|
||||||
* ol.layer.Layer): T} callback Feature callback. The callback will be
|
* ol.layer.Layer): T} callback Feature callback. The callback will be
|
||||||
* called with two arguments. The first argument is one
|
* 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
|
* the {@link ol.layer.Layer layer} of the feature and will be null for
|
||||||
* unmanaged layers. To stop detection, callback functions can return a
|
* unmanaged layers. To stop detection, callback functions can return a
|
||||||
* truthy value.
|
* truthy value.
|
||||||
* @param {S=} opt_this Value to use as `this` when executing `callback`.
|
* @param {S=} opt_this
|
||||||
* @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`.
|
|
||||||
* @return {T|undefined} Callback result, i.e. the return value of last
|
* @return {T|undefined} Callback result, i.e. the return value of last
|
||||||
* callback execution, or the first truthy callback return value.
|
* callback execution, or the first truthy callback return value.
|
||||||
* @template S,T,U
|
* @template S,T,U
|
||||||
* @api stable
|
* @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_) {
|
if (!this.frameState_) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var coordinate = this.getCoordinateFromPixel(pixel);
|
var coordinate = this.getCoordinateFromPixel(pixel);
|
||||||
var thisArg = opt_this !== undefined ? opt_this : null;
|
var thisArg = opt_this !== undefined ? opt_this : null;
|
||||||
var layerFilter = opt_layerFilter !== undefined ?
|
var layerFilter = opt_options.layerFilter || ol.functions.TRUE;
|
||||||
opt_layerFilter : ol.functions.TRUE;
|
var thisArg2 = opt_options.layerFilterThis || null;
|
||||||
var thisArg2 = opt_this2 !== undefined ? opt_this2 : null;
|
|
||||||
return this.renderer_.forEachFeatureAtCoordinate(
|
return this.renderer_.forEachFeatureAtCoordinate(
|
||||||
coordinate, this.frameState_, callback, thisArg,
|
coordinate, this.frameState_, opt_options.hitTolerance || 0, callback, thisArg,
|
||||||
layerFilter, thisArg2);
|
layerFilter, thisArg2);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -111,10 +111,11 @@ describe('ol.renderer.canvas.Map', function() {
|
|||||||
map.addLayer(layer);
|
map.addLayer(layer);
|
||||||
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]), {
|
||||||
function() {
|
layerFilter: function() {
|
||||||
return false;
|
return false;
|
||||||
});
|
}
|
||||||
|
}, cb);
|
||||||
expect(cb).to.not.be.called();
|
expect(cb).to.not.be.called();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user