1
/* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
2
* license. See http://svn.openlayers.org/trunk/openlayers/license.txt for the
3
* full text of the license. */
6
* @requires OpenLayers/Control.js
7
* @requires OpenLayers/Handler/Box.js
11
* Class: OpenLayers.Control.ZoomBox
14
* - <OpenLayers.Control>
16
OpenLayers.Control.ZoomBox = OpenLayers.Class(OpenLayers.Control, {
19
* {OpenLayers.Control.TYPE}
21
type: OpenLayers.Control.TYPE_TOOL,
25
* {Boolean} Should the control be used for zooming out?
33
this.handler = new OpenLayers.Handler.Box( this,
34
{done: this.zoomBox}, {keyMask: this.keyMask} );
41
* position - {<OpenLayers.Bounds>} or {<OpenLayers.Pixel>}
43
zoomBox: function (position) {
44
if (position instanceof OpenLayers.Bounds) {
46
var minXY = this.map.getLonLatFromPixel(
47
new OpenLayers.Pixel(position.left, position.bottom));
48
var maxXY = this.map.getLonLatFromPixel(
49
new OpenLayers.Pixel(position.right, position.top));
50
var bounds = new OpenLayers.Bounds(minXY.lon, minXY.lat,
51
maxXY.lon, maxXY.lat);
53
var pixWidth = Math.abs(position.right-position.left);
54
var pixHeight = Math.abs(position.top-position.bottom);
55
var zoomFactor = Math.min((this.map.size.h / pixHeight),
56
(this.map.size.w / pixWidth));
57
var extent = this.map.getExtent();
58
var center = this.map.getLonLatFromPixel(
59
position.getCenterPixel());
60
var xmin = center.lon - (extent.getWidth()/2)*zoomFactor;
61
var xmax = center.lon + (extent.getWidth()/2)*zoomFactor;
62
var ymin = center.lat - (extent.getHeight()/2)*zoomFactor;
63
var ymax = center.lat + (extent.getHeight()/2)*zoomFactor;
64
var bounds = new OpenLayers.Bounds(xmin, ymin, xmax, ymax);
66
this.map.zoomToExtent(bounds);
67
} else { // it's a pixel
69
this.map.setCenter(this.map.getLonLatFromPixel(position),
70
this.map.getZoom() + 1);
72
this.map.setCenter(this.map.getLonLatFromPixel(position),
73
this.map.getZoom() - 1);
78
CLASS_NAME: "OpenLayers.Control.ZoomBox"