Adding animated zooming
This commit is contained in:
@@ -238,8 +238,7 @@ OpenLayers.Control.Navigation = OpenLayers.Class(OpenLayers.Control, {
|
||||
* evt - {Event}
|
||||
*/
|
||||
defaultDblClick: function (evt) {
|
||||
var newCenter = this.map.getLonLatFromViewPortPx( evt.xy );
|
||||
this.map.setCenter(newCenter, this.map.zoom + 1);
|
||||
this.map.zoomTo(this.map.zoom + 1, evt.xy);
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -249,8 +248,7 @@ OpenLayers.Control.Navigation = OpenLayers.Class(OpenLayers.Control, {
|
||||
* evt - {Event}
|
||||
*/
|
||||
defaultDblRightClick: function (evt) {
|
||||
var newCenter = this.map.getLonLatFromViewPortPx( evt.xy );
|
||||
this.map.setCenter(newCenter, this.map.zoom - 1);
|
||||
this.map.zoomTo(this.map.zoom - 1, evt.xy);
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -264,22 +262,14 @@ OpenLayers.Control.Navigation = OpenLayers.Class(OpenLayers.Control, {
|
||||
if (!this.map.fractionalZoom) {
|
||||
deltaZ = Math.round(deltaZ);
|
||||
}
|
||||
var currentZoom = this.map.getZoom();
|
||||
var newZoom = this.map.getZoom() + deltaZ;
|
||||
var currentZoom = this.map.getZoom(),
|
||||
newZoom = currentZoom + deltaZ;
|
||||
newZoom = Math.max(newZoom, 0);
|
||||
newZoom = Math.min(newZoom, this.map.getNumZoomLevels());
|
||||
if (newZoom === currentZoom) {
|
||||
return;
|
||||
}
|
||||
var size = this.map.getSize();
|
||||
var deltaX = size.w/2 - evt.xy.x;
|
||||
var deltaY = evt.xy.y - size.h/2;
|
||||
var newRes = this.map.baseLayer.getResolutionForZoom(newZoom);
|
||||
var zoomPoint = this.map.getLonLatFromPixel(evt.xy);
|
||||
var newCenter = new OpenLayers.LonLat(
|
||||
zoomPoint.lon + deltaX * newRes,
|
||||
zoomPoint.lat + deltaY * newRes );
|
||||
this.map.setCenter( newCenter, newZoom );
|
||||
this.map.zoomTo(newZoom, evt.xy);
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -175,8 +175,7 @@ OpenLayers.Control.TouchNavigation = OpenLayers.Class(OpenLayers.Control, {
|
||||
* evt - {Event}
|
||||
*/
|
||||
defaultDblClick: function (evt) {
|
||||
var newCenter = this.map.getLonLatFromViewPortPx(evt.xy);
|
||||
this.map.setCenter(newCenter, this.map.zoom + 1);
|
||||
this.map.zoomTo(this.map.zoom + 1, evt.xy);
|
||||
},
|
||||
|
||||
CLASS_NAME: "OpenLayers.Control.TouchNavigation"
|
||||
|
||||
@@ -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