Add 'layers' option to Translate interaction
This commit is contained in:
@@ -2715,7 +2715,10 @@ olx.interaction.DrawOptions.prototype.wrapX;
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {{features: (ol.Collection.<ol.Feature>|undefined)}}
|
||||
* @typedef {{
|
||||
* features: (ol.Collection.<ol.Feature>|undefined),
|
||||
* layers: (undefined|Array.<ol.layer.Layer>|function(ol.layer.Layer): boolean)
|
||||
* }}
|
||||
* @api
|
||||
*/
|
||||
olx.interaction.TranslateOptions;
|
||||
@@ -2730,6 +2733,18 @@ olx.interaction.TranslateOptions;
|
||||
olx.interaction.TranslateOptions.prototype.features;
|
||||
|
||||
|
||||
/**
|
||||
* A list of layers from which features should be
|
||||
* translated. Alternatively, a filter function can be provided. The
|
||||
* function will be called for each layer in the map and should return
|
||||
* `true` for layers that you want to be translatable. If the option is
|
||||
* absent, all visible layers will be considered translatable.
|
||||
* @type {undefined|Array.<ol.layer.Layer>|function(ol.layer.Layer): boolean}
|
||||
* @api
|
||||
*/
|
||||
olx.interaction.TranslateOptions.prototype.layers;
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {{condition: (ol.events.ConditionType|undefined),
|
||||
* duration: (number|undefined),
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
goog.provide('ol.interaction.Translate');
|
||||
goog.provide('ol.interaction.TranslateEvent');
|
||||
|
||||
goog.require('goog.asserts');
|
||||
goog.require('ol.events');
|
||||
goog.require('ol.events.Event');
|
||||
goog.require('ol.array');
|
||||
@@ -106,6 +107,37 @@ ol.interaction.Translate = function(options) {
|
||||
*/
|
||||
this.features_ = options.features !== undefined ? options.features : null;
|
||||
|
||||
var layerFilter;
|
||||
if (options.layers) {
|
||||
if (goog.isFunction(options.layers)) {
|
||||
/**
|
||||
* @param {ol.layer.Layer} layer Layer.
|
||||
* @return {boolean} Include.
|
||||
*/
|
||||
layerFilter = function(layer) {
|
||||
goog.asserts.assertFunction(options.layers);
|
||||
return options.layers(layer);
|
||||
};
|
||||
} else {
|
||||
var layers = options.layers;
|
||||
/**
|
||||
* @param {ol.layer.Layer} layer Layer.
|
||||
* @return {boolean} Include.
|
||||
*/
|
||||
layerFilter = function(layer) {
|
||||
return ol.array.includes(layers, layer);
|
||||
};
|
||||
}
|
||||
} else {
|
||||
layerFilter = ol.functions.TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {function(ol.layer.Layer): boolean}
|
||||
*/
|
||||
this.layerFilter_ = layerFilter;
|
||||
|
||||
/**
|
||||
* @type {ol.Feature}
|
||||
* @private
|
||||
@@ -242,7 +274,7 @@ ol.interaction.Translate.prototype.featuresAtPixel_ = function(pixel, map) {
|
||||
var intersectingFeature = map.forEachFeatureAtPixel(pixel,
|
||||
function(feature) {
|
||||
return feature;
|
||||
});
|
||||
}, this, this.layerFilter_);
|
||||
|
||||
if (this.features_ &&
|
||||
ol.array.includes(this.features_.getArray(), intersectingFeature)) {
|
||||
|
||||
Reference in New Issue
Block a user