Adding preserveCenter config option
This commit is contained in:
@@ -22,6 +22,9 @@ var init = function () {
|
|||||||
controls: [
|
controls: [
|
||||||
new OpenLayers.Control.Attribution(),
|
new OpenLayers.Control.Attribution(),
|
||||||
new OpenLayers.Control.TouchNavigation({
|
new OpenLayers.Control.TouchNavigation({
|
||||||
|
pinchZoomOptions: {
|
||||||
|
preserveCenter: true
|
||||||
|
},
|
||||||
dragPanOptions: {
|
dragPanOptions: {
|
||||||
enableKinetic: true
|
enableKinetic: true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,6 +41,12 @@ OpenLayers.Control.PinchZoom = OpenLayers.Class(OpenLayers.Control, {
|
|||||||
*/
|
*/
|
||||||
autoActivate: true,
|
autoActivate: true,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* APIProperty: preserveCenter
|
||||||
|
* {Boolean} Force the map center to stay in place. Default is false.
|
||||||
|
*/
|
||||||
|
preserveCenter: false,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* APIProperty: handlerOptions
|
* APIProperty: handlerOptions
|
||||||
* {Object} Used to set non-default properties on the pinch handler
|
* {Object} Used to set non-default properties on the pinch handler
|
||||||
@@ -73,8 +79,10 @@ OpenLayers.Control.PinchZoom = OpenLayers.Class(OpenLayers.Control, {
|
|||||||
* of the pinch gesture. This give us the current scale of the pinch.
|
* of the pinch gesture. This give us the current scale of the pinch.
|
||||||
*/
|
*/
|
||||||
pinchStart: function(evt, pinchData) {
|
pinchStart: function(evt, pinchData) {
|
||||||
this.pinchOrigin = evt.xy;
|
var xy = (this.preserveCenter) ?
|
||||||
this.currentCenter = evt.xy;
|
this.map.getPixelFromLonLat(this.map.getCenter()) : evt.xy;
|
||||||
|
this.pinchOrigin = xy;
|
||||||
|
this.currentCenter = xy;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -89,7 +97,8 @@ OpenLayers.Control.PinchZoom = OpenLayers.Class(OpenLayers.Control, {
|
|||||||
var scale = pinchData.scale;
|
var scale = pinchData.scale;
|
||||||
var containerOrigin = this.map.layerContainerOriginPx;
|
var containerOrigin = this.map.layerContainerOriginPx;
|
||||||
var pinchOrigin = this.pinchOrigin;
|
var pinchOrigin = this.pinchOrigin;
|
||||||
var current = evt.xy;
|
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 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 dy = Math.round((current.y - pinchOrigin.y) + (scale - 1) * (containerOrigin.y - pinchOrigin.y));
|
||||||
|
|||||||
Reference in New Issue
Block a user