Merge pull request #791 from fredj/mapbrowserevent

ol.MapBrowserEvent: call browserEvent.{preventDefault|stopPropagation}
This commit is contained in:
Frédéric Junod
2013-06-18 06:25:43 -07:00
7 changed files with 42 additions and 5 deletions
@@ -52,6 +52,6 @@ ol.interaction.DoubleClickZoom.prototype.handleMapBrowserEvent =
ol.interaction.Interaction.zoomByDelta(map, view, delta, anchor, ol.interaction.Interaction.zoomByDelta(map, view, delta, anchor,
ol.interaction.DOUBLECLICKZOOM_ANIMATION_DURATION); ol.interaction.DOUBLECLICKZOOM_ANIMATION_DURATION);
mapBrowserEvent.preventDefault(); mapBrowserEvent.preventDefault();
browserEvent.preventDefault(); mapBrowserEvent.stopOtherInteractions();
} }
}; };
+1 -1
View File
@@ -81,8 +81,8 @@ ol.interaction.KeyboardPan.prototype.handleMapBrowserEvent =
ol.coordinate.rotate(delta, rotation); ol.coordinate.rotate(delta, rotation);
ol.interaction.Interaction.pan( ol.interaction.Interaction.pan(
map, view, delta, ol.interaction.KEYBOARD_PAN_DURATION); map, view, delta, ol.interaction.KEYBOARD_PAN_DURATION);
keyEvent.preventDefault();
mapBrowserEvent.preventDefault(); mapBrowserEvent.preventDefault();
mapBrowserEvent.stopOtherInteractions();
} }
} }
}; };
@@ -62,8 +62,8 @@ ol.interaction.KeyboardZoom.prototype.handleMapBrowserEvent =
var view = map.getView().getView2D(); var view = map.getView().getView2D();
ol.interaction.Interaction.zoomByDelta(map, view, delta, undefined, ol.interaction.Interaction.zoomByDelta(map, view, delta, undefined,
ol.interaction.KEYBOARD_ZOOM_DURATION); ol.interaction.KEYBOARD_ZOOM_DURATION);
keyEvent.preventDefault();
mapBrowserEvent.preventDefault(); mapBrowserEvent.preventDefault();
mapBrowserEvent.stopOtherInteractions();
} }
} }
}; };
@@ -93,7 +93,7 @@ ol.interaction.MouseWheelZoom.prototype.handleMapBrowserEvent =
goog.bind(this.doZoom_, this, map), timeLeft); goog.bind(this.doZoom_, this, map), timeLeft);
mapBrowserEvent.preventDefault(); mapBrowserEvent.preventDefault();
mouseWheelEvent.preventDefault(); mapBrowserEvent.stopOtherInteractions();
} }
}; };
+1 -1
View File
@@ -644,7 +644,7 @@ ol.Map.prototype.handleMapBrowserEvent = function(mapBrowserEvent) {
for (i = interactionsArray.length - 1; i >= 0; i--) { for (i = interactionsArray.length - 1; i >= 0; i--) {
var interaction = interactionsArray[i]; var interaction = interactionsArray[i];
interaction.handleMapBrowserEvent(mapBrowserEvent); interaction.handleMapBrowserEvent(mapBrowserEvent);
if (mapBrowserEvent.defaultPrevented) { if (mapBrowserEvent.otherInteractionsStopped) {
break; break;
} }
} }
+2
View File
@@ -1,2 +1,4 @@
@exportProperty ol.MapBrowserEvent.prototype.getCoordinate @exportProperty ol.MapBrowserEvent.prototype.getCoordinate
@exportProperty ol.MapBrowserEvent.prototype.getPixel @exportProperty ol.MapBrowserEvent.prototype.getPixel
@exportProperty ol.MapBrowserEvent.prototype.preventDefault
@exportProperty ol.MapBrowserEvent.prototype.stopPropagation
+35
View File
@@ -39,6 +39,11 @@ ol.MapBrowserEvent = function(type, map, browserEvent, opt_frameState) {
*/ */
this.coordinate_ = null; this.coordinate_ = null;
/**
* @type {boolean}
*/
this.otherInteractionsStopped = false;
/** /**
* @private * @private
* @type {ol.Pixel} * @type {ol.Pixel}
@@ -98,6 +103,36 @@ ol.MapBrowserEvent.prototype.isMouseActionButton = function() {
}; };
/**
* Prevents the default browser action.
* @see https://developer.mozilla.org/en-US/docs/Web/API/event.preventDefault
* @override
*/
ol.MapBrowserEvent.prototype.preventDefault = function() {
goog.base(this, 'preventDefault');
this.browserEvent.preventDefault();
};
/**
* Stop the interaction chain.
*/
ol.MapBrowserEvent.prototype.stopOtherInteractions = function() {
this.otherInteractionsStopped = true;
};
/**
* Prevents further propagation of the current event.
* @see https://developer.mozilla.org/en-US/docs/Web/API/event.stopPropagation
* @override
*/
ol.MapBrowserEvent.prototype.stopPropagation = function() {
goog.base(this, 'stopPropagation');
this.browserEvent.stopPropagation();
};
/** /**
* @param {ol.Map} map The map with the viewport to listen to events on. * @param {ol.Map} map The map with the viewport to listen to events on.