From 958544f2a72208d8ca36b4410ab20a3363edf9b4 Mon Sep 17 00:00:00 2001 From: ahocevar Date: Mon, 11 Jun 2012 19:07:17 +0200 Subject: [PATCH 1/2] New zoomOnClick option for ZoomBox control. This change also finally adds tests for the ZoomBox control. --- lib/OpenLayers/Control/ZoomBox.js | 12 ++++++-- tests/Control/ZoomBox.html | 51 +++++++++++++++++++++++++++++++ tests/list-tests.html | 1 + 3 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 tests/Control/ZoomBox.html diff --git a/lib/OpenLayers/Control/ZoomBox.js b/lib/OpenLayers/Control/ZoomBox.js index 8f407adb25..58da952c9d 100644 --- a/lib/OpenLayers/Control/ZoomBox.js +++ b/lib/OpenLayers/Control/ZoomBox.js @@ -41,9 +41,17 @@ OpenLayers.Control.ZoomBox = OpenLayers.Class(OpenLayers.Control, { /** * APIProperty: alwaysZoom - * {Boolean} Always zoom in/out, when box drawed + * {Boolean} Always zoom in/out when box drawn, even if the zoom level does + * not change. */ alwaysZoom: false, + + /** + * APIProperty: zoomOnClick + * {Boolean} Should we zoom when no box was dragged, i.e. the user only + * clicked? Default is true. + */ + zoomOnClick: true, /** * Method: draw @@ -93,7 +101,7 @@ OpenLayers.Control.ZoomBox = OpenLayers.Class(OpenLayers.Control, { if (lastZoom == this.map.getZoom() && this.alwaysZoom == true){ this.map.zoomTo(lastZoom + (this.out ? -1 : 1)); } - } else { // it's a pixel + } else if (this.zoomOnClick) { // it's a pixel if (!this.out) { this.map.setCenter(this.map.getLonLatFromPixel(position), this.map.getZoom() + 1); diff --git a/tests/Control/ZoomBox.html b/tests/Control/ZoomBox.html new file mode 100644 index 0000000000..9ee3fde886 --- /dev/null +++ b/tests/Control/ZoomBox.html @@ -0,0 +1,51 @@ + + + + + + + +
+
in
out + + diff --git a/tests/list-tests.html b/tests/list-tests.html index 14ccf78ed0..c883ed34d7 100644 --- a/tests/list-tests.html +++ b/tests/list-tests.html @@ -49,6 +49,7 @@
  • Control/PanPanel.html
  • Control/SLDSelect.html
  • Control/Zoom.html
  • +
  • Control/ZoomBox.html
  • Events.html
  • Events/buttonclick.html
  • Extras.html
  • From 8ad7ad326affd2b3fa9eeb9c067a82ecd2dbbaf3 Mon Sep 17 00:00:00 2001 From: ahocevar Date: Mon, 11 Jun 2012 19:22:05 +0200 Subject: [PATCH 2/2] Review comments from @bartvde. --- tests/Control/ZoomBox.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/Control/ZoomBox.html b/tests/Control/ZoomBox.html index 9ee3fde886..2e037192e5 100644 --- a/tests/Control/ZoomBox.html +++ b/tests/Control/ZoomBox.html @@ -40,12 +40,13 @@ control.zoomBox(new OpenLayers.Bounds(128, 64, 256, 128)); t.eq(map.getCenter().toShortString(), "-45, 22.5", "centered to box center"); t.eq(map.getZoom(), 3, "zoomed to box extent"); + + map.destroy(); }
    -
    in
    out