Change View2D function names

Also make the TouchZoom interaction no longer use a private View2D function.
This commit is contained in:
Éric Lemoine
2013-03-04 17:59:43 +01:00
parent faef495cfd
commit 03ae41a68c
7 changed files with 32 additions and 29 deletions

View File

@@ -70,7 +70,8 @@ ol.control.Zoom.prototype.handleIn_ = function(browserEvent) {
var map = this.getMap();
map.requestRenderFrame();
// FIXME works for View2D only
map.getView().zoom(map, this.delta_, undefined, ol.control.ZOOM_DURATION);
map.getView().zoomByDelta(map, this.delta_, undefined,
ol.control.ZOOM_DURATION);
};
@@ -84,5 +85,6 @@ ol.control.Zoom.prototype.handleOut_ = function(browserEvent) {
var map = this.getMap();
map.requestRenderFrame();
// FIXME works for View2D only
map.getView().zoom(map, -this.delta_, undefined, ol.control.ZOOM_DURATION);
map.getView().zoomByDelta(map, -this.delta_, undefined,
ol.control.ZOOM_DURATION);
};

View File

@@ -41,7 +41,7 @@ ol.interaction.DblClickZoom.prototype.handleMapBrowserEvent =
// FIXME works for View2D only
var view = map.getView();
goog.asserts.assert(view instanceof ol.View2D);
view.zoom(map, delta, anchor);
view.zoomByDelta(map, delta, anchor);
mapBrowserEvent.preventDefault();
browserEvent.preventDefault();
}

View File

@@ -66,7 +66,7 @@ ol.interaction.DragRotateAndZoom.prototype.handleDrag =
this.lastAngle_ = theta;
if (goog.isDef(this.lastMagnitude_)) {
var resolution = this.lastMagnitude_ * (view.getResolution() / magnitude);
view.zoomToResolution(map, resolution);
view.zoom(map, resolution);
}
this.lastMagnitude_ = magnitude;
};

View File

@@ -40,7 +40,8 @@ ol.interaction.KeyboardZoom.prototype.handleMapBrowserEvent =
// FIXME works for View2D only
var view = map.getView();
goog.asserts.assert(view instanceof ol.View2D);
view.zoom(map, delta, undefined, ol.interaction.KEYBOARD_ZOOM_DURATION);
view.zoomByDelta(map, delta, undefined,
ol.interaction.KEYBOARD_ZOOM_DURATION);
keyEvent.preventDefault();
mapBrowserEvent.preventDefault();
}

View File

@@ -111,7 +111,7 @@ ol.interaction.MouseWheelZoom.prototype.doZoom_ = function(map) {
goog.asserts.assert(view instanceof ol.View2D);
map.requestRenderFrame();
view.zoom(map, -delta, this.lastAnchor_,
view.zoomByDelta(map, -delta, this.lastAnchor_,
ol.interaction.MOUSEWHEELZOOM_ANIMATION_DURATION);
this.delta_ = 0;

View File

@@ -59,7 +59,7 @@ ol.interaction.TouchZoom.prototype.handleTouchMove =
var anchor = map.getCoordinateFromPixel(centroid);
// scale, bypass the resolution constraint
view.zoom_(map, view.getResolution() * scaleDelta, anchor);
view.zoomNoConstraint(map, view.getResolution() * scaleDelta, anchor);
};
@@ -73,7 +73,7 @@ ol.interaction.TouchZoom.prototype.handleTouchEnd =
var map = mapBrowserEvent.map;
var view = map.getView();
// take the resolution constraint into account
view.zoomToResolution(map, view.getResolution());
view.zoom(map, view.getResolution());
view.setHint(ol.ViewHint.INTERACTING, -1);
return false;
} else {

View File

@@ -282,26 +282,13 @@ ol.View2D.prototype.rotate = function(map, rotation, opt_anchor) {
/**
* @private
* @param {ol.Map} map Map.
* @param {number|undefined} resolution Resolution to go to.
* @param {ol.Coordinate=} opt_anchor Anchor coordinate.
*/
ol.View2D.prototype.zoom_ = function(map, resolution, opt_anchor) {
if (goog.isDefAndNotNull(resolution) && goog.isDefAndNotNull(opt_anchor)) {
var anchor = opt_anchor;
var oldCenter = /** @type {!ol.Coordinate} */ (this.getCenter());
var oldResolution = this.getResolution();
var x = anchor.x - resolution * (anchor.x - oldCenter.x) / oldResolution;
var y = anchor.y - resolution * (anchor.y - oldCenter.y) / oldResolution;
var center = new ol.Coordinate(x, y);
map.withFrozenRendering(function() {
this.setCenter(center);
this.setResolution(resolution);
}, this);
} else {
this.setResolution(resolution);
}
ol.View2D.prototype.zoom = function(map, resolution, opt_anchor) {
resolution = this.constraints_.resolution(resolution, 0);
this.zoomNoConstraint(map, resolution, opt_anchor);
};
@@ -311,7 +298,8 @@ ol.View2D.prototype.zoom_ = function(map, resolution, opt_anchor) {
* @param {ol.Coordinate=} opt_anchor Anchor coordinate.
* @param {number=} opt_duration Duration.
*/
ol.View2D.prototype.zoom = function(map, delta, opt_anchor, opt_duration) {
ol.View2D.prototype.zoomByDelta =
function(map, delta, opt_anchor, opt_duration) {
var currentResolution = this.getResolution();
var currentCenter = this.getCenter();
if (goog.isDef(currentResolution) && goog.isDef(currentCenter) &&
@@ -331,7 +319,7 @@ ol.View2D.prototype.zoom = function(map, delta, opt_anchor, opt_duration) {
}
}
var resolution = this.constraints_.resolution(currentResolution, delta);
this.zoom_(map, resolution, opt_anchor);
this.zoomNoConstraint(map, resolution, opt_anchor);
};
@@ -340,9 +328,21 @@ ol.View2D.prototype.zoom = function(map, delta, opt_anchor, opt_duration) {
* @param {number|undefined} resolution Resolution to go to.
* @param {ol.Coordinate=} opt_anchor Anchor coordinate.
*/
ol.View2D.prototype.zoomToResolution = function(map, resolution, opt_anchor) {
resolution = this.constraints_.resolution(resolution, 0);
this.zoom_(map, resolution, opt_anchor);
ol.View2D.prototype.zoomNoConstraint = function(map, resolution, opt_anchor) {
if (goog.isDefAndNotNull(resolution) && goog.isDefAndNotNull(opt_anchor)) {
var anchor = opt_anchor;
var oldCenter = /** @type {!ol.Coordinate} */ (this.getCenter());
var oldResolution = this.getResolution();
var x = anchor.x - resolution * (anchor.x - oldCenter.x) / oldResolution;
var y = anchor.y - resolution * (anchor.y - oldCenter.y) / oldResolution;
var center = new ol.Coordinate(x, y);
map.withFrozenRendering(function() {
this.setCenter(center);
this.setResolution(resolution);
}, this);
} else {
this.setResolution(resolution);
}
};