Merge pull request #800 from ahocevar/transform
Use GPU where available; animated zooming. r=@elemoine
This commit is contained in:
@@ -245,8 +245,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);
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -256,8 +255,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);
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -271,22 +269,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);
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
* full text of the license. */
|
||||
|
||||
/**
|
||||
* @requires OpenLayers/Util/vendorPrefix.js
|
||||
* @requires OpenLayers/Handler/Pinch.js
|
||||
*/
|
||||
|
||||
@@ -105,27 +104,13 @@ OpenLayers.Control.PinchZoom = OpenLayers.Class(OpenLayers.Control, {
|
||||
var current = (this.preserveCenter) ?
|
||||
this.map.getPixelFromLonLat(this.map.getCenter()) : evt.xy;
|
||||
|
||||
var dx = Math.round((current.x - pinchOrigin.x) + (scale - 1) * (containerOrigin.x - pinchOrigin.x));
|
||||
var dy = Math.round((current.y - pinchOrigin.y) + (scale - 1) * (containerOrigin.y - pinchOrigin.y));
|
||||
var dx = Math.round((containerOrigin.x + current.x - pinchOrigin.x) + (scale - 1) * (containerOrigin.x - pinchOrigin.x));
|
||||
var dy = Math.round((containerOrigin.y + current.y - pinchOrigin.y) + (scale - 1) * (containerOrigin.y - pinchOrigin.y));
|
||||
|
||||
this.applyTransform(
|
||||
"translate(" + dx + "px, " + dy + "px) scale(" + scale + ")"
|
||||
);
|
||||
this.map.applyTransform(dx, dy, scale);
|
||||
this.currentCenter = current;
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: applyTransform
|
||||
* Applies the given transform to layers.
|
||||
*/
|
||||
applyTransform: function(transform) {
|
||||
var style = this.map.layerContainerDiv.style;
|
||||
var transformProperty = OpenLayers.Util.vendorPrefix.style("transform");
|
||||
if (transformProperty) {
|
||||
style[transformProperty] = transform;
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Method: pinchDone
|
||||
*
|
||||
@@ -137,7 +122,7 @@ OpenLayers.Control.PinchZoom = OpenLayers.Class(OpenLayers.Control, {
|
||||
* of the pinch gesture. This give us the final scale of the pinch.
|
||||
*/
|
||||
pinchDone: function(evt, start, last) {
|
||||
this.applyTransform("");
|
||||
this.map.applyTransform();
|
||||
var zoom = this.map.getZoomForResolution(this.map.getResolution() / last.scale, true);
|
||||
if (zoom !== this.map.getZoom() || !this.currentCenter.equals(this.pinchOrigin)) {
|
||||
var resolution = this.map.getResolutionForZoom(zoom);
|
||||
|
||||
@@ -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