Add a 'condition' option to ol.interaction.Modify
This commit is contained in:
@@ -220,3 +220,18 @@ ol.events.condition.mouseOnly = function(mapBrowserEvent) {
|
||||
// see http://www.w3.org/TR/pointerevents/#widl-PointerEvent-pointerType
|
||||
return mapBrowserEvent.pointerEvent.pointerType == 'mouse';
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Return `true` if the event originates from a primary pointer in
|
||||
* contact with the surface or if the left mouse button is pressed.
|
||||
* @see http://www.w3.org/TR/pointerevents/#button-states
|
||||
*
|
||||
* @param {ol.MapBrowserEvent} mapBrowserEvent Map browser event.
|
||||
* @return {boolean} True if the event originates from a primary pointer.
|
||||
* @api
|
||||
*/
|
||||
ol.events.condition.primaryAction = function(mapBrowserEvent) {
|
||||
var pointerEvent = mapBrowserEvent.pointerEvent;
|
||||
return pointerEvent.isPrimary && pointerEvent.button === 0;
|
||||
};
|
||||
|
||||
@@ -112,6 +112,14 @@ ol.interaction.Modify = function(options) {
|
||||
handleUpEvent: ol.interaction.Modify.handleUpEvent_
|
||||
});
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.events.ConditionType}
|
||||
*/
|
||||
this.condition_ = options.condition ?
|
||||
options.condition : ol.events.condition.primaryAction;
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {ol.MapBrowserEvent} mapBrowserEvent Browser event.
|
||||
@@ -553,6 +561,9 @@ ol.interaction.Modify.compareIndexes_ = function(a, b) {
|
||||
* @private
|
||||
*/
|
||||
ol.interaction.Modify.handleDownEvent_ = function(evt) {
|
||||
if (!this.condition_(evt)) {
|
||||
return false;
|
||||
}
|
||||
this.handlePointerAtPixel_(evt.pixel, evt.map);
|
||||
this.dragSegments_.length = 0;
|
||||
this.modified_ = false;
|
||||
|
||||
Reference in New Issue
Block a user