From e87e1c0c5725bfdc0fc7528e426450009f241353 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Lemoine?= Date: Mon, 9 May 2011 08:28:35 +0000 Subject: [PATCH] make the Navigation control support pinch-zoom, r=bbinet (closes #3273) git-svn-id: http://svn.openlayers.org/trunk/openlayers@11961 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Control/Navigation.js | 29 ++++++++++++++++++++++++++++ tests/Control/Navigation.html | 26 ++++++++++++++++++++++++- 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/lib/OpenLayers/Control/Navigation.js b/lib/OpenLayers/Control/Navigation.js index ae0dccb3b0..ae61145291 100644 --- a/lib/OpenLayers/Control/Navigation.js +++ b/lib/OpenLayers/Control/Navigation.js @@ -37,6 +37,18 @@ OpenLayers.Control.Navigation = OpenLayers.Class(OpenLayers.Control, { */ dragPanOptions: null, + /** + * Property: pinchZoom + * {} + */ + pinchZoom: null, + + /** + * APIProperty: pinchZoomOptions + * {Object} Options passed to the PinchZoom control. + */ + pinchZoomOptions: null, + /** * APIProperty: documentDrag * {Boolean} Allow panning of the map by dragging outside map viewport. @@ -124,6 +136,12 @@ OpenLayers.Control.Navigation = OpenLayers.Class(OpenLayers.Control, { this.zoomBox.destroy(); } this.zoomBox = null; + + if (this.pinchZoom) { + this.pinchZoom.destroy(); + } + this.pinchZoom = null; + OpenLayers.Control.prototype.destroy.apply(this,arguments); }, @@ -139,6 +157,9 @@ OpenLayers.Control.Navigation = OpenLayers.Class(OpenLayers.Control, { if (this.zoomBoxEnabled) { this.zoomBox.activate(); } + if (this.pinchZoom) { + this.pinchZoom.activate(); + } return OpenLayers.Control.prototype.activate.apply(this,arguments); }, @@ -146,6 +167,9 @@ OpenLayers.Control.Navigation = OpenLayers.Class(OpenLayers.Control, { * Method: deactivate */ deactivate: function() { + if (this.pinchZoom) { + this.pinchZoom.deactivate(); + } this.zoomBox.deactivate(); this.dragPan.deactivate(); this.handlers.click.deactivate(); @@ -188,6 +212,11 @@ OpenLayers.Control.Navigation = OpenLayers.Class(OpenLayers.Control, { this, {"up" : this.wheelUp, "down": this.wheelDown}, this.mouseWheelOptions ); + if (OpenLayers.Control.PinchZoom) { + this.pinchZoom = new OpenLayers.Control.PinchZoom( + OpenLayers.Util.extend( + {map: this.map}, this.pinchZoomOptions)); + } }, /** diff --git a/tests/Control/Navigation.html b/tests/Control/Navigation.html index e3b6c900aa..70428f5a7b 100644 --- a/tests/Control/Navigation.html +++ b/tests/Control/Navigation.html @@ -18,8 +18,26 @@ OpenLayers.Control.prototype.initialize = temp; } + function test_draw(t) { + t.plan(5); + var map = new OpenLayers.Map({div: 'map', controls: []}); + var control = new OpenLayers.Control.Navigation(); + map.addControl(control); + t.ok(control.handlers.click instanceof OpenLayers.Handler.Click, + "click handler set in instance"); + t.ok(control.dragPan instanceof OpenLayers.Control.DragPan, + "drag pan control set in instance"); + t.ok(control.zoomBox instanceof OpenLayers.Control.ZoomBox, + "zoom box control set in instance"); + t.ok(control.handlers.wheel instanceof OpenLayers.Handler.MouseWheel, + "mousewheel handler set in instance"); + t.ok(control.pinchZoom instanceof OpenLayers.Control.PinchZoom, + "pinch zoom control set in instance"); + map.destroy(); + } + function test_Control_Navigation_destroy (t) { - t.plan(10); + t.plan(12); var temp = OpenLayers.Control.prototype.destroy; OpenLayers.Control.prototype.destroy = function() { @@ -46,6 +64,11 @@ t.ok(true, "zoomBox destroyed"); } }, + 'pinchZoom': { + 'destroy': function() { + t.ok(true, "pinchZoom destroyed"); + } + }, handlers: { 'wheel': { 'destroy': function() { @@ -66,6 +89,7 @@ t.eq(control.dragPan, null, "'dragPan' set to null"); t.eq(control.zoomBox, null, "'zoomBox' set to null"); + t.eq(control.pinchZoom, null, "'pinchZoom' set to null"); t.eq(control.handlers, null, "handlers set to null"); OpenLayers.Control.prototype.destroy = temp;