Modify interaction takes style & features options
Instead of a FeatureOverlay
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');
|
||||||
@@ -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],
|
||||||
|
|||||||
@@ -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.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user