Modify interaction takes style & features options

Instead of a FeatureOverlay
This commit is contained in:
Antoine Abt
2014-02-21 12:35:30 +01:00
parent 7cea6f3240
commit ec832bdf6e
3 changed files with 17 additions and 10 deletions

View File

@@ -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');
@@ -230,13 +229,12 @@ var overlayStyle = (function() {
var select = new ol.interaction.Select({ var select = new ol.interaction.Select({
style: overlayStyle style: overlayStyle
}); });
var overlay = new ol.FeatureOverlay({
var modify = new ol.interaction.Modify({
features: select.getFeatures(), features: select.getFeatures(),
style: overlayStyle style: overlayStyle
}); });
var modify = new ol.interaction.Modify({ featureOverlay: overlay });
var map = new ol.Map({ var map = new ol.Map({
interactions: ol.interaction.defaults().extend([select, modify]), interactions: ol.interaction.defaults().extend([select, modify]),
layers: [raster, vectorLayer], layers: [raster, vectorLayer],

View File

@@ -454,7 +454,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.
*/ */
/** /**

View File

@@ -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;
} }