Merge pull request #1740 from tonio/interaction_api
Editing interaction api cleanup
This commit is contained in:
@@ -1,4 +1,3 @@
|
|||||||
goog.require('ol.FeatureOverlay');
|
|
||||||
goog.require('ol.Map');
|
goog.require('ol.Map');
|
||||||
goog.require('ol.View2D');
|
goog.require('ol.View2D');
|
||||||
goog.require('ol.interaction');
|
goog.require('ol.interaction');
|
||||||
@@ -227,12 +226,14 @@ var overlayStyle = (function() {
|
|||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
|
||||||
var overlay = new ol.FeatureOverlay({
|
var select = new ol.interaction.Select({
|
||||||
style: overlayStyle
|
style: overlayStyle
|
||||||
});
|
});
|
||||||
|
|
||||||
var modify = new ol.interaction.Modify({ featureOverlay: overlay });
|
var modify = new ol.interaction.Modify({
|
||||||
var select = new ol.interaction.Select({ featureOverlay: overlay });
|
features: select.getFeatures(),
|
||||||
|
style: overlayStyle
|
||||||
|
});
|
||||||
|
|
||||||
var map = new ol.Map({
|
var map = new ol.Map({
|
||||||
interactions: ol.interaction.defaults().extend([select, modify]),
|
interactions: ol.interaction.defaults().extend([select, modify]),
|
||||||
|
|||||||
@@ -31,11 +31,9 @@ var vector = new ol.layer.Vector({
|
|||||||
});
|
});
|
||||||
|
|
||||||
var select = new ol.interaction.Select({
|
var select = new ol.interaction.Select({
|
||||||
featureOverlay: new ol.FeatureOverlay({
|
style: new ol.style.Style({
|
||||||
style: new ol.style.Style({
|
fill: new ol.style.Fill({
|
||||||
fill: new ol.style.Fill({
|
color: 'rgba(255,255,255,0.5)'
|
||||||
color: 'rgba(255,255,255,0.5)'
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -388,7 +388,8 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {Object} olx.interaction.DrawOptions
|
* @typedef {Object} olx.interaction.DrawOptions
|
||||||
* @property {ol.source.Vector|undefined} source Destination source for the features.
|
* @property {ol.Collection|undefined} features Destination collection for the drawn features.
|
||||||
|
* @property {ol.source.Vector|undefined} source Destination source for the drawn features.
|
||||||
* @property {number|undefined} snapTolerance Pixel distance for snapping to the
|
* @property {number|undefined} snapTolerance Pixel distance for snapping to the
|
||||||
* drawing finish (default is 12).
|
* drawing finish (default is 12).
|
||||||
* @property {ol.geom.GeometryType} type Drawing type ('Point', 'LineString',
|
* @property {ol.geom.GeometryType} type Drawing type ('Point', 'LineString',
|
||||||
@@ -440,7 +441,7 @@
|
|||||||
* features should be selected.
|
* features should be selected.
|
||||||
* @property {Array.<ol.layer.Layer>|undefined} layers Layers. Zero or more
|
* @property {Array.<ol.layer.Layer>|undefined} layers Layers. Zero or more
|
||||||
* layers from which features should be selected.
|
* layers from which features should be selected.
|
||||||
* @property {ol.FeatureOverlay} featureOverlay Feature overlay.
|
* @property {ol.style.Style|Array.<ol.style.Style>|ol.feature.StyleFunction|undefined} style FeatureOverlay style.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -454,7 +455,8 @@
|
|||||||
* @typedef {Object} olx.interaction.ModifyOptions
|
* @typedef {Object} olx.interaction.ModifyOptions
|
||||||
* @property {number|undefined} pixelTolerance Pixel tolerance for considering
|
* @property {number|undefined} pixelTolerance Pixel tolerance for considering
|
||||||
* the pointer close enough to a vertex for editing. Default is 20 pixels.
|
* the pointer close enough to a vertex for editing. Default is 20 pixels.
|
||||||
* @property {ol.FeatureOverlay} featureOverlay Features overlay.
|
* @property {ol.style.Style|Array.<ol.style.Style>|ol.feature.StyleFunction|undefined} style FeatureOverlay style.
|
||||||
|
* @property {ol.Collection} features The features the interaction works on.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -74,6 +74,13 @@ ol.interaction.Draw = function(options) {
|
|||||||
*/
|
*/
|
||||||
this.source_ = goog.isDef(options.source) ? options.source : null;
|
this.source_ = goog.isDef(options.source) ? options.source : null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Target collection for drawn features.
|
||||||
|
* @type {ol.Collection}
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
this.features_ = goog.isDef(options.features) ? options.features : null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pixel distance for snapping.
|
* Pixel distance for snapping.
|
||||||
* @type {number}
|
* @type {number}
|
||||||
@@ -473,6 +480,9 @@ ol.interaction.Draw.prototype.finishDrawing_ = function(event) {
|
|||||||
sketchFeature.setGeometry(new ol.geom.MultiPolygon([coordinates]));
|
sketchFeature.setGeometry(new ol.geom.MultiPolygon([coordinates]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!goog.isNull(this.features_)) {
|
||||||
|
this.features_.push(sketchFeature);
|
||||||
|
}
|
||||||
if (!goog.isNull(this.source_)) {
|
if (!goog.isNull(this.source_)) {
|
||||||
this.source_.addFeature(sketchFeature);
|
this.source_.addFeature(sketchFeature);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ goog.provide('ol.interaction.Modify');
|
|||||||
|
|
||||||
goog.require('goog.array');
|
goog.require('goog.array');
|
||||||
goog.require('goog.asserts');
|
goog.require('goog.asserts');
|
||||||
|
goog.require('goog.events');
|
||||||
goog.require('ol.Collection');
|
goog.require('ol.Collection');
|
||||||
goog.require('ol.CollectionEventType');
|
goog.require('ol.CollectionEventType');
|
||||||
goog.require('ol.Feature');
|
goog.require('ol.Feature');
|
||||||
@@ -85,11 +86,19 @@ ol.interaction.Modify = function(options) {
|
|||||||
* @type {ol.FeatureOverlay}
|
* @type {ol.FeatureOverlay}
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
this.overlay_ = options.featureOverlay;
|
this.overlay_ = new ol.FeatureOverlay({
|
||||||
|
style: options.style
|
||||||
|
});
|
||||||
|
|
||||||
this.overlay_.getFeatures().listen(ol.CollectionEventType.ADD,
|
/**
|
||||||
|
* @type {ol.Collection}
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
this.features_ = options.features;
|
||||||
|
|
||||||
|
goog.events.listen(this.features_, ol.CollectionEventType.ADD,
|
||||||
this.addFeature_, false, this);
|
this.addFeature_, false, this);
|
||||||
this.overlay_.getFeatures().listen(ol.CollectionEventType.REMOVE,
|
goog.events.listen(this.features_, ol.CollectionEventType.REMOVE,
|
||||||
this.removeFeature_, false, this);
|
this.removeFeature_, false, this);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -315,8 +324,7 @@ ol.interaction.Modify.prototype.removeFeature_ = function(evt) {
|
|||||||
}
|
}
|
||||||
// There remains only vertexFeature…
|
// There remains only vertexFeature…
|
||||||
if (!goog.isNull(this.vertexFeature_) &&
|
if (!goog.isNull(this.vertexFeature_) &&
|
||||||
this.overlay_.getFeatures().getLength() === 1 &&
|
this.features_.getLength() === 0) {
|
||||||
this.overlay_.getFeatures().getAt(0) == this.vertexFeature_) {
|
|
||||||
this.overlay_.removeFeature(this.vertexFeature_);
|
this.overlay_.removeFeature(this.vertexFeature_);
|
||||||
this.vertexFeature_ = null;
|
this.vertexFeature_ = null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
@exportSymbol ol.interaction.Select
|
@exportSymbol ol.interaction.Select
|
||||||
@exportProperty ol.interaction.Select.prototype.getFeatureOverlay
|
@exportProperty ol.interaction.Select.prototype.getFeatures
|
||||||
@exportProperty ol.interaction.Select.prototype.setMap
|
@exportProperty ol.interaction.Select.prototype.setMap
|
||||||
|
|||||||
@@ -69,18 +69,20 @@ ol.interaction.Select = function(options) {
|
|||||||
* @private
|
* @private
|
||||||
* @type {ol.FeatureOverlay}
|
* @type {ol.FeatureOverlay}
|
||||||
*/
|
*/
|
||||||
this.featureOverlay_ = options.featureOverlay;
|
this.featureOverlay_ = new ol.FeatureOverlay({
|
||||||
|
style: options.style
|
||||||
|
});
|
||||||
|
|
||||||
};
|
};
|
||||||
goog.inherits(ol.interaction.Select, ol.interaction.Interaction);
|
goog.inherits(ol.interaction.Select, ol.interaction.Interaction);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return {ol.FeatureOverlay} Feature overlay.
|
* @return {ol.Collection} Features collection.
|
||||||
* @todo stability experimental
|
* @todo stability experimental
|
||||||
*/
|
*/
|
||||||
ol.interaction.Select.prototype.getFeatureOverlay = function() {
|
ol.interaction.Select.prototype.getFeatures = function() {
|
||||||
return this.featureOverlay_;
|
return this.featureOverlay_.getFeatures();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user