Merge pull request #7093 from tschaub/modify-source
Allow modify interaction to be configured with a source
This commit is contained in:
@@ -23,7 +23,7 @@ goog.require('ol.events.Event');
|
||||
* @constructor
|
||||
* @extends {ol.Object}
|
||||
* @fires ol.Collection.Event
|
||||
* @param {!Array.<T>=} opt_array Array.
|
||||
* @param {Array.<T>=} opt_array Array.
|
||||
* @param {olx.CollectionOptions=} opt_options Collection options.
|
||||
* @template T
|
||||
* @api
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
goog.provide('ol.interaction.Modify');
|
||||
|
||||
goog.require('ol');
|
||||
goog.require('ol.Collection');
|
||||
goog.require('ol.CollectionEventType');
|
||||
goog.require('ol.Feature');
|
||||
goog.require('ol.MapBrowserEventType');
|
||||
@@ -19,13 +20,22 @@ goog.require('ol.interaction.ModifyEventType');
|
||||
goog.require('ol.interaction.Pointer');
|
||||
goog.require('ol.layer.Vector');
|
||||
goog.require('ol.source.Vector');
|
||||
goog.require('ol.source.VectorEventType');
|
||||
goog.require('ol.structs.RBush');
|
||||
goog.require('ol.style.Style');
|
||||
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* Interaction for modifying feature geometries.
|
||||
* Interaction for modifying feature geometries. To modify features that have
|
||||
* been added to an existing source, construct the modify interaction with the
|
||||
* `source` option. If you want to modify features in a collection (for example,
|
||||
* the collection used by a select interaction), construct the interaction with
|
||||
* the `features` option. The interaction must be constructed with either a
|
||||
* `source` or `features` option.
|
||||
*
|
||||
* By default, the interaction will allow deletion of vertices when the `alt`
|
||||
* key is pressed. To configure the interaction with a different condition
|
||||
* for deletion, use the `deleteCondition` option.
|
||||
*
|
||||
* @constructor
|
||||
* @extends {ol.interaction.Pointer}
|
||||
@@ -56,7 +66,7 @@ ol.interaction.Modify = function(options) {
|
||||
* @return {boolean} Combined condition result.
|
||||
*/
|
||||
this.defaultDeleteCondition_ = function(mapBrowserEvent) {
|
||||
return ol.events.condition.noModifierKeys(mapBrowserEvent) &&
|
||||
return ol.events.condition.altKeyOnly(mapBrowserEvent) &&
|
||||
ol.events.condition.singleClick(mapBrowserEvent);
|
||||
};
|
||||
|
||||
@@ -175,11 +185,33 @@ ol.interaction.Modify = function(options) {
|
||||
'GeometryCollection': this.writeGeometryCollectionGeometry_
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @type {ol.source.Vector}
|
||||
* @private
|
||||
*/
|
||||
this.source_ = null;
|
||||
|
||||
var features;
|
||||
if (options.source) {
|
||||
this.source_ = options.source;
|
||||
features = new ol.Collection(this.source_.getFeatures());
|
||||
ol.events.listen(this.source_, ol.source.VectorEventType.ADDFEATURE,
|
||||
this.handleSourceAdd_, this);
|
||||
ol.events.listen(this.source_, ol.source.VectorEventType.REMOVEFEATURE,
|
||||
this.handleSourceRemove_, this);
|
||||
} else {
|
||||
features = options.features;
|
||||
}
|
||||
if (!features) {
|
||||
throw new Error('The modify interaction requires features or a source');
|
||||
}
|
||||
|
||||
/**
|
||||
* @type {ol.Collection.<ol.Feature>}
|
||||
* @private
|
||||
*/
|
||||
this.features_ = options.features;
|
||||
this.features_ = features;
|
||||
|
||||
this.features_.forEach(this.addFeature_, this);
|
||||
ol.events.listen(this.features_, ol.CollectionEventType.ADD,
|
||||
@@ -301,6 +333,28 @@ ol.interaction.Modify.prototype.setMap = function(map) {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.source.Vector.Event} event Event.
|
||||
* @private
|
||||
*/
|
||||
ol.interaction.Modify.prototype.handleSourceAdd_ = function(event) {
|
||||
if (event.feature) {
|
||||
this.features_.push(event.feature);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.source.Vector.Event} event Event.
|
||||
* @private
|
||||
*/
|
||||
ol.interaction.Modify.prototype.handleSourceRemove_ = function(event) {
|
||||
if (event.feature) {
|
||||
this.features_.remove(event.feature);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.Collection.Event} evt Event.
|
||||
* @private
|
||||
|
||||
Reference in New Issue
Block a user