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
+4 -2
View File
@@ -70,7 +70,8 @@ ol.control.Zoom.prototype.handleIn_ = function(browserEvent) {
var map = this.getMap(); var map = this.getMap();
map.requestRenderFrame(); map.requestRenderFrame();
// FIXME works for View2D only // 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(); var map = this.getMap();
map.requestRenderFrame(); map.requestRenderFrame();
// FIXME works for View2D only // 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);
}; };
@@ -41,7 +41,7 @@ ol.interaction.DblClickZoom.prototype.handleMapBrowserEvent =
// FIXME works for View2D only // FIXME works for View2D only
var view = map.getView(); var view = map.getView();
goog.asserts.assert(view instanceof ol.View2D); goog.asserts.assert(view instanceof ol.View2D);
view.zoom(map, delta, anchor); view.zoomByDelta(map, delta, anchor);
mapBrowserEvent.preventDefault(); mapBrowserEvent.preventDefault();
browserEvent.preventDefault(); browserEvent.preventDefault();
} }
@@ -66,7 +66,7 @@ ol.interaction.DragRotateAndZoom.prototype.handleDrag =
this.lastAngle_ = theta; this.lastAngle_ = theta;
if (goog.isDef(this.lastMagnitude_)) { if (goog.isDef(this.lastMagnitude_)) {
var resolution = this.lastMagnitude_ * (view.getResolution() / magnitude); var resolution = this.lastMagnitude_ * (view.getResolution() / magnitude);
view.zoomToResolution(map, resolution); view.zoom(map, resolution);
} }
this.lastMagnitude_ = magnitude; this.lastMagnitude_ = magnitude;
}; };
@@ -40,7 +40,8 @@ ol.interaction.KeyboardZoom.prototype.handleMapBrowserEvent =
// FIXME works for View2D only // FIXME works for View2D only
var view = map.getView(); var view = map.getView();
goog.asserts.assert(view instanceof ol.View2D); 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(); keyEvent.preventDefault();
mapBrowserEvent.preventDefault(); mapBrowserEvent.preventDefault();
} }
@@ -111,7 +111,7 @@ ol.interaction.MouseWheelZoom.prototype.doZoom_ = function(map) {
goog.asserts.assert(view instanceof ol.View2D); goog.asserts.assert(view instanceof ol.View2D);
map.requestRenderFrame(); map.requestRenderFrame();
view.zoom(map, -delta, this.lastAnchor_, view.zoomByDelta(map, -delta, this.lastAnchor_,
ol.interaction.MOUSEWHEELZOOM_ANIMATION_DURATION); ol.interaction.MOUSEWHEELZOOM_ANIMATION_DURATION);
this.delta_ = 0; this.delta_ = 0;
+2 -2
View File
@@ -59,7 +59,7 @@ ol.interaction.TouchZoom.prototype.handleTouchMove =
var anchor = map.getCoordinateFromPixel(centroid); var anchor = map.getCoordinateFromPixel(centroid);
// scale, bypass the resolution constraint // 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 map = mapBrowserEvent.map;
var view = map.getView(); var view = map.getView();
// take the resolution constraint into account // take the resolution constraint into account
view.zoomToResolution(map, view.getResolution()); view.zoom(map, view.getResolution());
view.setHint(ol.ViewHint.INTERACTING, -1); view.setHint(ol.ViewHint.INTERACTING, -1);
return false; return false;
} else { } else {
+21 -21
View File
@@ -282,26 +282,13 @@ ol.View2D.prototype.rotate = function(map, rotation, opt_anchor) {
/** /**
* @private
* @param {ol.Map} map Map. * @param {ol.Map} map Map.
* @param {number|undefined} resolution Resolution to go to. * @param {number|undefined} resolution Resolution to go to.
* @param {ol.Coordinate=} opt_anchor Anchor coordinate. * @param {ol.Coordinate=} opt_anchor Anchor coordinate.
*/ */
ol.View2D.prototype.zoom_ = function(map, resolution, opt_anchor) { ol.View2D.prototype.zoom = function(map, resolution, opt_anchor) {
if (goog.isDefAndNotNull(resolution) && goog.isDefAndNotNull(opt_anchor)) { resolution = this.constraints_.resolution(resolution, 0);
var anchor = opt_anchor; this.zoomNoConstraint(map, resolution, 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);
}
}; };
@@ -311,7 +298,8 @@ ol.View2D.prototype.zoom_ = function(map, resolution, opt_anchor) {
* @param {ol.Coordinate=} opt_anchor Anchor coordinate. * @param {ol.Coordinate=} opt_anchor Anchor coordinate.
* @param {number=} opt_duration Duration. * @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 currentResolution = this.getResolution();
var currentCenter = this.getCenter(); var currentCenter = this.getCenter();
if (goog.isDef(currentResolution) && goog.isDef(currentCenter) && 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); 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 {number|undefined} resolution Resolution to go to.
* @param {ol.Coordinate=} opt_anchor Anchor coordinate. * @param {ol.Coordinate=} opt_anchor Anchor coordinate.
*/ */
ol.View2D.prototype.zoomToResolution = function(map, resolution, opt_anchor) { ol.View2D.prototype.zoomNoConstraint = function(map, resolution, opt_anchor) {
resolution = this.constraints_.resolution(resolution, 0); if (goog.isDefAndNotNull(resolution) && goog.isDefAndNotNull(opt_anchor)) {
this.zoom_(map, resolution, 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);
}
}; };