From b7f199c8cd77ea5e07eef3dba9d622614cdf2066 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Tue, 8 Sep 2015 23:07:47 -0600 Subject: [PATCH] Zoom to the extent of the drag box --- src/ol/interaction/dragzoominteraction.js | 35 +++++++++++++++++++---- 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/src/ol/interaction/dragzoominteraction.js b/src/ol/interaction/dragzoominteraction.js index 30398002c6..83e82cafdf 100644 --- a/src/ol/interaction/dragzoominteraction.js +++ b/src/ol/interaction/dragzoominteraction.js @@ -1,10 +1,11 @@ goog.provide('ol.interaction.DragZoom'); goog.require('goog.asserts'); +goog.require('ol.animation'); +goog.require('ol.easing'); goog.require('ol.events.condition'); goog.require('ol.extent'); goog.require('ol.interaction.DragBox'); -goog.require('ol.interaction.Interaction'); goog.require('ol.style.Stroke'); goog.require('ol.style.Style'); @@ -58,13 +59,35 @@ goog.inherits(ol.interaction.DragZoom, ol.interaction.DragBox); */ ol.interaction.DragZoom.prototype.onBoxEnd = function() { var map = this.getMap(); + var view = map.getView(); goog.asserts.assert(!goog.isNull(view), 'view should not be null'); - var extent = this.getGeometry().getExtent(); - var center = ol.extent.getCenter(extent); + var size = map.getSize(); goog.asserts.assert(goog.isDef(size), 'size should be defined'); - ol.interaction.Interaction.zoom(map, view, - view.getResolutionForExtent(extent, size), - center, this.duration_); + + var extent = this.getGeometry().getExtent(); + + var resolution = view.constrainResolution( + view.getResolutionForExtent(extent, size)); + + var currentResolution = view.getResolution(); + goog.asserts.assert(goog.isDef(currentResolution), 'res should be defined'); + + var currentCenter = view.getCenter(); + goog.asserts.assert(goog.isDef(currentCenter), 'center should be defined'); + + map.beforeRender(ol.animation.zoom({ + resolution: currentResolution, + duration: this.duration_, + easing: ol.easing.easeOut + })); + map.beforeRender(ol.animation.pan({ + source: currentCenter, + duration: this.duration_, + easing: ol.easing.easeOut + })); + + view.setCenter(ol.extent.getCenter(extent)); + view.setResolution(resolution); };