Move pan function from View2D to Interaction

This commit is contained in:
Éric Lemoine
2013-04-09 17:56:48 +02:00
parent 396ee5ce3d
commit 51094139a8
3 changed files with 27 additions and 22 deletions

View File

@@ -3,6 +3,8 @@
goog.provide('ol.interaction.Interaction');
goog.require('ol.MapBrowserEvent');
goog.require('ol.animation');
goog.require('ol.easing');
@@ -18,3 +20,26 @@ ol.interaction.Interaction = function() {
*/
ol.interaction.Interaction.prototype.handleMapBrowserEvent =
goog.abstractMethod;
/**
* @param {ol.Map} map Map.
* @param {ol.View2D} view View.
* @param {ol.Coordinate} delta Delta.
* @param {number=} opt_duration Duration.
*/
ol.interaction.Interaction.pan = function(
map, view, delta, opt_duration) {
var currentCenter = view.getCenter();
if (goog.isDef(currentCenter)) {
if (goog.isDef(opt_duration)) {
map.requestRenderFrame();
map.addPreRenderFunction(ol.animation.pan({
source: currentCenter,
duration: opt_duration,
easing: ol.easing.linear
}));
}
view.setCenter([currentCenter[0] + delta[0], currentCenter[1] + delta[1]]);
}
};

View File

@@ -70,7 +70,8 @@ ol.interaction.KeyboardPan.prototype.handleMapBrowserEvent =
}
var delta = [deltaX, deltaY];
ol.coordinate.rotate(delta, rotation);
view.pan(map, delta, ol.interaction.KEYBOARD_PAN_DURATION);
ol.interaction.Interaction.pan(
map, view, delta, ol.interaction.KEYBOARD_PAN_DURATION);
keyEvent.preventDefault();
mapBrowserEvent.preventDefault();
}

View File

@@ -376,27 +376,6 @@ goog.exportProperty(
ol.View2D.prototype.setRotation);
/**
* @param {ol.Map} map Map.
* @param {ol.Coordinate} delta Delta.
* @param {number=} opt_duration Duration.
*/
ol.View2D.prototype.pan = function(map, delta, opt_duration) {
var currentCenter = this.getCenter();
if (goog.isDef(currentCenter)) {
if (goog.isDef(opt_duration)) {
map.requestRenderFrame();
map.addPreRenderFunction(ol.animation.pan({
source: currentCenter,
duration: opt_duration,
easing: ol.easing.linear
}));
}
this.setCenter([currentCenter[0] + delta[0], currentCenter[1] + delta[1]]);
}
};
/**
* @param {ol.Map} map Map.
* @param {number|undefined} rotation Rotation.