From fff63a1f9fbfb1028dec4dbba94e7bb23c07fa20 Mon Sep 17 00:00:00 2001 From: Paul Spencer Date: Thu, 17 Jan 2008 16:35:49 +0000 Subject: [PATCH] (Closes #1187.) applying Bart's patch to add a zoom out option to the zoom control. r=pspencer. git-svn-id: http://svn.openlayers.org/trunk/openlayers@5796 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Control/ZoomBox.js | 34 +++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/lib/OpenLayers/Control/ZoomBox.js b/lib/OpenLayers/Control/ZoomBox.js index 6486913085..202f474fd6 100644 --- a/lib/OpenLayers/Control/ZoomBox.js +++ b/lib/OpenLayers/Control/ZoomBox.js @@ -20,6 +20,12 @@ OpenLayers.Control.ZoomBox = OpenLayers.Class(OpenLayers.Control, { */ type: OpenLayers.Control.TYPE_TOOL, + /** + * Property: out + * {Boolean} Should the control be used for zooming out? + */ + out: false, + /** * Method: draw */ @@ -36,16 +42,36 @@ OpenLayers.Control.ZoomBox = OpenLayers.Class(OpenLayers.Control, { */ zoomBox: function (position) { if (position instanceof OpenLayers.Bounds) { - var minXY = this.map.getLonLatFromPixel( + if (!this.out) { + var minXY = this.map.getLonLatFromPixel( new OpenLayers.Pixel(position.left, position.bottom)); - var maxXY = this.map.getLonLatFromPixel( + var maxXY = this.map.getLonLatFromPixel( new OpenLayers.Pixel(position.right, position.top)); - var bounds = new OpenLayers.Bounds(minXY.lon, minXY.lat, + var bounds = new OpenLayers.Bounds(minXY.lon, minXY.lat, maxXY.lon, maxXY.lat); + } else { + var pixWidth = Math.abs(position.right-position.left); + var pixHeight = Math.abs(position.top-position.bottom); + var zoomFactor = Math.min((this.map.size.h / pixHeight), + (this.map.size.w / pixWidth)); + var extent = map.getExtent(); + var center = this.map.getLonLatFromPixel( + position.getCenterPixel()); + var xmin = center.lon - (extent.getWidth()/2)*zoomFactor; + var xmax = center.lon + (extent.getWidth()/2)*zoomFactor; + var ymin = center.lat - (extent.getHeight()/2)*zoomFactor; + var ymax = center.lat + (extent.getHeight()/2)*zoomFactor; + var bounds = new OpenLayers.Bounds(xmin, ymin, xmax, ymax); + } this.map.zoomToExtent(bounds); } else { // it's a pixel - this.map.setCenter(this.map.getLonLatFromPixel(position), + if (!this.out) { + this.map.setCenter(this.map.getLonLatFromPixel(position), this.map.getZoom() + 1); + } else { + this.map.setCenter(this.map.getLonLatFromPixel(position), + this.map.getZoom() - 1); + } } },