The Modify interaction now uses pointer events

While dragging a vertex, the feature on the original layer is
not updated until the first pointer move after dragging. See
#1796. Previously, the Modify interaction did not set the
interacting hint on the view, so the feature was also updated
on the original layer. But now, the interacting hint is set,
which exposes this behaviour.
This commit is contained in:
ahocevar
2014-03-03 19:57:25 +01:00
committed by tsauerwein
parent 32ffb1ecae
commit f6efcbcc24

View File

@@ -18,7 +18,7 @@ goog.require('ol.geom.MultiPoint');
goog.require('ol.geom.MultiPolygon'); goog.require('ol.geom.MultiPolygon');
goog.require('ol.geom.Point'); goog.require('ol.geom.Point');
goog.require('ol.geom.Polygon'); goog.require('ol.geom.Polygon');
goog.require('ol.interaction.Drag'); goog.require('ol.interaction.Pointer');
goog.require('ol.structs.RBush'); goog.require('ol.structs.RBush');
@@ -35,7 +35,7 @@ ol.interaction.SegmentDataType;
/** /**
* @constructor * @constructor
* @extends {ol.interaction.Drag} * @extends {ol.interaction.Pointer}
* @param {olx.interaction.ModifyOptions} options Options. * @param {olx.interaction.ModifyOptions} options Options.
*/ */
ol.interaction.Modify = function(options) { ol.interaction.Modify = function(options) {
@@ -126,7 +126,7 @@ ol.interaction.Modify = function(options) {
}; };
}; };
goog.inherits(ol.interaction.Modify, ol.interaction.Drag); goog.inherits(ol.interaction.Modify, ol.interaction.Pointer);
/** /**
@@ -158,7 +158,7 @@ ol.interaction.Modify.prototype.addFeature_ = function(evt) {
if (goog.isDef(this.SEGMENT_WRITERS_[geometry.getType()])) { if (goog.isDef(this.SEGMENT_WRITERS_[geometry.getType()])) {
this.SEGMENT_WRITERS_[geometry.getType()].call(this, feature, geometry); this.SEGMENT_WRITERS_[geometry.getType()].call(this, feature, geometry);
} }
this.handleMouseAtPixel_(this.lastPixel_, this.getMap()); this.handlePointerAtPixel_(this.lastPixel_, this.getMap());
}; };
@@ -368,7 +368,7 @@ ol.interaction.Modify.prototype.createOrUpdateVertexFeature_ =
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.interaction.Modify.prototype.handleDragStart = function(evt) { ol.interaction.Modify.prototype.handlePointerDown = function(evt) {
this.dragSegments_ = []; this.dragSegments_ = [];
var vertexFeature = this.vertexFeature_; var vertexFeature = this.vertexFeature_;
if (!goog.isNull(vertexFeature)) { if (!goog.isNull(vertexFeature)) {
@@ -408,7 +408,7 @@ ol.interaction.Modify.prototype.handleDragStart = function(evt) {
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.interaction.Modify.prototype.handleDrag = function(evt) { ol.interaction.Modify.prototype.handlePointerDrag = function(evt) {
var vertex = evt.coordinate; var vertex = evt.coordinate;
for (var i = 0, ii = this.dragSegments_.length; i < ii; ++i) { for (var i = 0, ii = this.dragSegments_.length; i < ii; ++i) {
var dragSegment = this.dragSegments_[i]; var dragSegment = this.dragSegments_[i];
@@ -458,7 +458,7 @@ ol.interaction.Modify.prototype.handleDrag = function(evt) {
/** /**
* @inheritDoc * @inheritDoc
*/ */
ol.interaction.Modify.prototype.handleDragEnd = function(evt) { ol.interaction.Modify.prototype.handlePointerUp = function(evt) {
var segmentData; var segmentData;
for (var i = this.dragSegments_.length - 1; i >= 0; --i) { for (var i = this.dragSegments_.length - 1; i >= 0; --i) {
segmentData = this.dragSegments_[i][0]; segmentData = this.dragSegments_[i][0];
@@ -474,9 +474,8 @@ ol.interaction.Modify.prototype.handleDragEnd = function(evt) {
ol.interaction.Modify.prototype.handleMapBrowserEvent = ol.interaction.Modify.prototype.handleMapBrowserEvent =
function(mapBrowserEvent) { function(mapBrowserEvent) {
if (!mapBrowserEvent.map.getView().getHints()[ol.ViewHint.INTERACTING] && if (!mapBrowserEvent.map.getView().getHints()[ol.ViewHint.INTERACTING] &&
!this.getDragging() && mapBrowserEvent.type == ol.MapBrowserEvent.EventType.POINTERMOVE) {
mapBrowserEvent.type == ol.MapBrowserEvent.EventType.MOUSEMOVE) { this.handlePointerMove_(mapBrowserEvent);
this.handleMouseMove_(mapBrowserEvent);
} }
goog.base(this, 'handleMapBrowserEvent', mapBrowserEvent); goog.base(this, 'handleMapBrowserEvent', mapBrowserEvent);
return !this.modifiable_; return !this.modifiable_;
@@ -487,9 +486,9 @@ ol.interaction.Modify.prototype.handleMapBrowserEvent =
* @param {ol.MapBrowserEvent} evt Event. * @param {ol.MapBrowserEvent} evt Event.
* @private * @private
*/ */
ol.interaction.Modify.prototype.handleMouseMove_ = function(evt) { ol.interaction.Modify.prototype.handlePointerMove_ = function(evt) {
this.lastPixel_ = evt.pixel; this.lastPixel_ = evt.pixel;
this.handleMouseAtPixel_(evt.pixel, evt.map); this.handlePointerAtPixel_(evt.pixel, evt.map);
}; };
@@ -498,7 +497,7 @@ ol.interaction.Modify.prototype.handleMouseMove_ = function(evt) {
* @param {ol.Map} map Map. * @param {ol.Map} map Map.
* @private * @private
*/ */
ol.interaction.Modify.prototype.handleMouseAtPixel_ = function(pixel, map) { ol.interaction.Modify.prototype.handlePointerAtPixel_ = function(pixel, map) {
var pixelCoordinate = map.getCoordinateFromPixel(pixel); var pixelCoordinate = map.getCoordinateFromPixel(pixel);
var sortByDistance = function(a, b) { var sortByDistance = function(a, b) {
return ol.coordinate.squaredDistanceToSegment(pixelCoordinate, a.segment) - return ol.coordinate.squaredDistanceToSegment(pixelCoordinate, a.segment) -