From 676475d902d219f2ffec817bfbfbdf0abf6ee03b Mon Sep 17 00:00:00 2001 From: crschmidt Date: Tue, 10 Mar 2009 03:50:01 +0000 Subject: [PATCH] "Always zoom in/out while drawing the zoom box." Patch from jachym, tested and example added by vdeparday. r=me. (Closes #1771) git-svn-id: http://svn.openlayers.org/trunk/openlayers@8977 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- examples/navtoolbar-alwaysZoom.html | 78 +++++++++++++++++++++++++++++ lib/OpenLayers/Control/ZoomBox.js | 11 ++++ 2 files changed, 89 insertions(+) create mode 100644 examples/navtoolbar-alwaysZoom.html diff --git a/examples/navtoolbar-alwaysZoom.html b/examples/navtoolbar-alwaysZoom.html new file mode 100644 index 0000000000..ec9309c1a9 --- /dev/null +++ b/examples/navtoolbar-alwaysZoom.html @@ -0,0 +1,78 @@ + + + A navToolbar with an alwaysZoom ZoomBox + + + + + + + + +

A navToolbar with an alwaysZoom ZoomBox

+

+ Demo of a custom NavToolbar which uses a zoomBox tool that always zoom in even when the zoom box is too big. +

+
+ + diff --git a/lib/OpenLayers/Control/ZoomBox.js b/lib/OpenLayers/Control/ZoomBox.js index 7a45ff6980..461ece4086 100644 --- a/lib/OpenLayers/Control/ZoomBox.js +++ b/lib/OpenLayers/Control/ZoomBox.js @@ -29,6 +29,12 @@ OpenLayers.Control.ZoomBox = OpenLayers.Class(OpenLayers.Control, { */ out: false, + /** + * Property: alwaysZoom + * {Boolean} Always zoom in/out, when box drawed + */ + alwaysZoom: false, + /** * Method: draw */ @@ -66,7 +72,12 @@ OpenLayers.Control.ZoomBox = OpenLayers.Class(OpenLayers.Control, { var ymax = center.lat + (extent.getHeight()/2)*zoomFactor; var bounds = new OpenLayers.Bounds(xmin, ymin, xmax, ymax); } + // always zoom in/out + var lastZoom = this.map.getZoom(); this.map.zoomToExtent(bounds); + if (lastZoom == this.map.getZoom() && this.alwaysZoom == true){ + this.map.zoomTo(lastZoom + (this.out ? -1 : 1)); + } } else { // it's a pixel if (!this.out) { this.map.setCenter(this.map.getLonLatFromPixel(position),