Adding animated zooming
This commit is contained in:
@@ -69,7 +69,8 @@ OpenLayers.Control.ZoomBox = OpenLayers.Class(OpenLayers.Control, {
|
||||
*/
|
||||
zoomBox: function (position) {
|
||||
if (position instanceof OpenLayers.Bounds) {
|
||||
var bounds;
|
||||
var bounds,
|
||||
targetCenterPx = position.getCenterPixel();
|
||||
if (!this.out) {
|
||||
var minXY = this.map.getLonLatFromPixel({
|
||||
x: position.left,
|
||||
@@ -87,8 +88,7 @@ OpenLayers.Control.ZoomBox = OpenLayers.Class(OpenLayers.Control, {
|
||||
var zoomFactor = Math.min((this.map.size.h / pixHeight),
|
||||
(this.map.size.w / pixWidth));
|
||||
var extent = this.map.getExtent();
|
||||
var center = this.map.getLonLatFromPixel(
|
||||
position.getCenterPixel());
|
||||
var center = this.map.getLonLatFromPixel(targetCenterPx);
|
||||
var xmin = center.lon - (extent.getWidth()/2)*zoomFactor;
|
||||
var xmax = center.lon + (extent.getWidth()/2)*zoomFactor;
|
||||
var ymin = center.lat - (extent.getHeight()/2)*zoomFactor;
|
||||
@@ -96,18 +96,27 @@ OpenLayers.Control.ZoomBox = OpenLayers.Class(OpenLayers.Control, {
|
||||
bounds = new OpenLayers.Bounds(xmin, ymin, xmax, ymax);
|
||||
}
|
||||
// always zoom in/out
|
||||
var lastZoom = this.map.getZoom();
|
||||
this.map.zoomToExtent(bounds);
|
||||
var lastZoom = this.map.getZoom(),
|
||||
size = this.map.getSize(),
|
||||
centerPx = {x: size.w / 2, y: size.h / 2},
|
||||
zoom = this.map.getZoomForExtent(bounds),
|
||||
oldRes = this.map.getResolution(),
|
||||
newRes = this.map.getResolutionForZoom(zoom),
|
||||
zoomOriginPx = {
|
||||
x: targetCenterPx.x +
|
||||
(targetCenterPx.x - centerPx.x) * newRes / oldRes,
|
||||
y: targetCenterPx.y +
|
||||
(targetCenterPx.y - centerPx.y) * newRes / oldRes
|
||||
};
|
||||
this.map.zoomTo(zoom, zoomOriginPx);
|
||||
if (lastZoom == this.map.getZoom() && this.alwaysZoom == true){
|
||||
this.map.zoomTo(lastZoom + (this.out ? -1 : 1));
|
||||
}
|
||||
} else if (this.zoomOnClick) { // it's a pixel
|
||||
if (!this.out) {
|
||||
this.map.setCenter(this.map.getLonLatFromPixel(position),
|
||||
this.map.getZoom() + 1);
|
||||
this.map.zoomTo(this.map.getZoom() + 1, position);
|
||||
} else {
|
||||
this.map.setCenter(this.map.getLonLatFromPixel(position),
|
||||
this.map.getZoom() - 1);
|
||||
this.map.zoomTo(this.map.getZoom() - 1, position);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user