diff --git a/externs/olx.js b/externs/olx.js index 9f2265a059..730c14f24c 100644 --- a/externs/olx.js +++ b/externs/olx.js @@ -2715,7 +2715,10 @@ olx.interaction.DrawOptions.prototype.wrapX; /** - * @typedef {{features: (ol.Collection.|undefined)}} + * @typedef {{ + * features: (ol.Collection.|undefined), + * layers: (undefined|Array.|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.|function(ol.layer.Layer): boolean} + * @api + */ +olx.interaction.TranslateOptions.prototype.layers; + + /** * @typedef {{condition: (ol.events.ConditionType|undefined), * duration: (number|undefined), diff --git a/src/ol/interaction/translateinteraction.js b/src/ol/interaction/translateinteraction.js index 9393fe9440..e6812186ef 100644 --- a/src/ol/interaction/translateinteraction.js +++ b/src/ol/interaction/translateinteraction.js @@ -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)) {