(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
This commit is contained in:
@@ -20,6 +20,12 @@ OpenLayers.Control.ZoomBox = OpenLayers.Class(OpenLayers.Control, {
|
|||||||
*/
|
*/
|
||||||
type: OpenLayers.Control.TYPE_TOOL,
|
type: OpenLayers.Control.TYPE_TOOL,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Property: out
|
||||||
|
* {Boolean} Should the control be used for zooming out?
|
||||||
|
*/
|
||||||
|
out: false,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method: draw
|
* Method: draw
|
||||||
*/
|
*/
|
||||||
@@ -36,16 +42,36 @@ OpenLayers.Control.ZoomBox = OpenLayers.Class(OpenLayers.Control, {
|
|||||||
*/
|
*/
|
||||||
zoomBox: function (position) {
|
zoomBox: function (position) {
|
||||||
if (position instanceof OpenLayers.Bounds) {
|
if (position instanceof OpenLayers.Bounds) {
|
||||||
|
if (!this.out) {
|
||||||
var minXY = this.map.getLonLatFromPixel(
|
var minXY = this.map.getLonLatFromPixel(
|
||||||
new OpenLayers.Pixel(position.left, position.bottom));
|
new OpenLayers.Pixel(position.left, position.bottom));
|
||||||
var maxXY = this.map.getLonLatFromPixel(
|
var maxXY = this.map.getLonLatFromPixel(
|
||||||
new OpenLayers.Pixel(position.right, position.top));
|
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);
|
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);
|
this.map.zoomToExtent(bounds);
|
||||||
} else { // it's a pixel
|
} else { // it's a pixel
|
||||||
|
if (!this.out) {
|
||||||
this.map.setCenter(this.map.getLonLatFromPixel(position),
|
this.map.setCenter(this.map.getLonLatFromPixel(position),
|
||||||
this.map.getZoom() + 1);
|
this.map.getZoom() + 1);
|
||||||
|
} else {
|
||||||
|
this.map.setCenter(this.map.getLonLatFromPixel(position),
|
||||||
|
this.map.getZoom() - 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user