Long press allows modification of current vertex

This commit is contained in:
Andreas Hocevar
2018-01-14 18:41:26 +01:00
parent fbf951f005
commit 2a64990a71
2 changed files with 28 additions and 3 deletions
+5
View File
@@ -71,4 +71,9 @@ typeSelect.onchange = function() {
addInteractions(); addInteractions();
}; };
// Avoid context menu for long taps when editing on mobile
map.getTargetElement().oncontextmenu = function(e) {
e.preventDefault();
};
addInteractions(); addInteractions();
+23 -3
View File
@@ -56,6 +56,12 @@ const Draw = function(options) {
*/ */
this.downPx_ = null; this.downPx_ = null;
/**
* @type {number}
* @private
*/
this.lastDragTime_;
/** /**
* @type {boolean} * @type {boolean}
* @private * @private
@@ -255,7 +261,8 @@ const Draw = function(options) {
wrapX: options.wrapX ? options.wrapX : false wrapX: options.wrapX ? options.wrapX : false
}), }),
style: options.style ? options.style : style: options.style ? options.style :
Draw.getDefaultStyleFunction() Draw.getDefaultStyleFunction(),
updateWhileInteracting: true
}); });
/** /**
@@ -323,7 +330,18 @@ Draw.prototype.setMap = function(map) {
*/ */
Draw.handleEvent = function(event) { Draw.handleEvent = function(event) {
this.freehand_ = this.mode_ !== Draw.Mode_.POINT && this.freehandCondition_(event); this.freehand_ = this.mode_ !== Draw.Mode_.POINT && this.freehandCondition_(event);
let move = event.type === MapBrowserEventType.POINTERMOVE;
let pass = true; let pass = true;
if (this.lastDragTime_ && event.type === MapBrowserEventType.POINTERDRAG) {
const now = Date.now();
if (now - this.lastDragTime_ >= 500) {
this.downPx_ = event.pixel;
this.shouldHandle_ = !this.freehand_;
move = true;
} else {
this.lastDragTime_ = undefined;
}
}
if (this.freehand_ && if (this.freehand_ &&
event.type === MapBrowserEventType.POINTERDRAG && event.type === MapBrowserEventType.POINTERDRAG &&
this.sketchFeature_ !== null) { this.sketchFeature_ !== null) {
@@ -332,11 +350,12 @@ Draw.handleEvent = function(event) {
} else if (this.freehand_ && } else if (this.freehand_ &&
event.type === MapBrowserEventType.POINTERDOWN) { event.type === MapBrowserEventType.POINTERDOWN) {
pass = false; pass = false;
} else if (event.type === MapBrowserEventType.POINTERMOVE) { } else if (move) {
pass = this.handlePointerMove_(event); pass = event.type === MapBrowserEventType.POINTERMOVE && this.handlePointerMove_(event);
} else if (event.type === MapBrowserEventType.DBLCLICK) { } else if (event.type === MapBrowserEventType.DBLCLICK) {
pass = false; pass = false;
} }
return PointerInteraction.handleEvent.call(this, event) && pass; return PointerInteraction.handleEvent.call(this, event) && pass;
}; };
@@ -349,6 +368,7 @@ Draw.handleEvent = function(event) {
*/ */
Draw.handleDownEvent_ = function(event) { Draw.handleDownEvent_ = function(event) {
this.shouldHandle_ = !this.freehand_; this.shouldHandle_ = !this.freehand_;
this.lastDragTime_ = Date.now();
if (this.freehand_) { if (this.freehand_) {
this.downPx_ = event.pixel; this.downPx_ = event.pixel;