From 03ae41a68c466445f5a7ed7875a5f51f3f0806fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Lemoine?= Date: Mon, 4 Mar 2013 17:59:43 +0100 Subject: [PATCH] Change View2D function names Also make the TouchZoom interaction no longer use a private View2D function. --- src/ol/control/zoomcontrol.js | 6 ++- src/ol/interaction/dblclickzoominteraction.js | 2 +- .../dragrotateandzoominteraction.js | 2 +- src/ol/interaction/keyboardzoominteraction.js | 3 +- .../interaction/mousewheelzoominteraction.js | 2 +- src/ol/interaction/touchzoominteraction.js | 4 +- src/ol/view2d.js | 42 +++++++++---------- 7 files changed, 32 insertions(+), 29 deletions(-) diff --git a/src/ol/control/zoomcontrol.js b/src/ol/control/zoomcontrol.js index ffacacf55f..63e3345cbf 100644 --- a/src/ol/control/zoomcontrol.js +++ b/src/ol/control/zoomcontrol.js @@ -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); }; diff --git a/src/ol/interaction/dblclickzoominteraction.js b/src/ol/interaction/dblclickzoominteraction.js index b5e3e1e589..c8f63a37c7 100644 --- a/src/ol/interaction/dblclickzoominteraction.js +++ b/src/ol/interaction/dblclickzoominteraction.js @@ -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(); } diff --git a/src/ol/interaction/dragrotateandzoominteraction.js b/src/ol/interaction/dragrotateandzoominteraction.js index 7cf2f7ffa1..cd8425b37a 100644 --- a/src/ol/interaction/dragrotateandzoominteraction.js +++ b/src/ol/interaction/dragrotateandzoominteraction.js @@ -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; }; diff --git a/src/ol/interaction/keyboardzoominteraction.js b/src/ol/interaction/keyboardzoominteraction.js index 563827ab45..cbfe06c51e 100644 --- a/src/ol/interaction/keyboardzoominteraction.js +++ b/src/ol/interaction/keyboardzoominteraction.js @@ -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(); } diff --git a/src/ol/interaction/mousewheelzoominteraction.js b/src/ol/interaction/mousewheelzoominteraction.js index b274dd7e35..125dba9713 100644 --- a/src/ol/interaction/mousewheelzoominteraction.js +++ b/src/ol/interaction/mousewheelzoominteraction.js @@ -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; diff --git a/src/ol/interaction/touchzoominteraction.js b/src/ol/interaction/touchzoominteraction.js index 9087c5f3b4..ed14b714cf 100644 --- a/src/ol/interaction/touchzoominteraction.js +++ b/src/ol/interaction/touchzoominteraction.js @@ -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 { diff --git a/src/ol/view2d.js b/src/ol/view2d.js index 2fcc1f9016..0f3d3474c9 100644 --- a/src/ol/view2d.js +++ b/src/ol/view2d.js @@ -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); + } };