From 9de274950220e33472a5524ed5a502f5304d3736 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Tue, 14 Aug 2007 15:27:59 +0000 Subject: [PATCH] #774 - dragPan only calls setCenter if the map moves - thanks for the discussion and careful review Eric! git-svn-id: http://svn.openlayers.org/trunk/openlayers@3902 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Control/DragPan.js | 32 +++++++++++++++++++++----- tests/Control/test_DragPan.html | 37 ++++++++++++++++++++++++++++++- 2 files changed, 63 insertions(+), 6 deletions(-) diff --git a/lib/OpenLayers/Control/DragPan.js b/lib/OpenLayers/Control/DragPan.js index 2698309f63..ff6386581c 100644 --- a/lib/OpenLayers/Control/DragPan.js +++ b/lib/OpenLayers/Control/DragPan.js @@ -20,31 +20,53 @@ OpenLayers.Control.DragPan = OpenLayers.Class(OpenLayers.Control, { */ type: OpenLayers.Control.TYPE_TOOL, + /** + * Property: panned + * {Boolean} The map moved. + */ + panned: false, + /** * Method: draw * Creates a Drag handler, using and * as callbacks. */ draw: function() { - this.handler = new OpenLayers.Handler.Drag( this, - {"move": this.panMap, "up": this.panMap} ); + this.handler = new OpenLayers.Handler.Drag(this, + {"move": this.panMap, "done": this.panMapDone}); }, /** * Method: panMap * * Parameters: - * xy - {} Pixel of the up position + * xy - {} Pixel of the mouse position */ - panMap: function (xy) { + panMap: function(xy) { + this.panned = true; var deltaX = this.handler.last.x - xy.x; var deltaY = this.handler.last.y - xy.y; var size = this.map.getSize(); var newXY = new OpenLayers.Pixel(size.w / 2 + deltaX, size.h / 2 + deltaY); - var newCenter = this.map.getLonLatFromViewPortPx( newXY ); + var newCenter = this.map.getLonLatFromViewPortPx( newXY ); this.map.setCenter(newCenter, null, this.handler.dragging); }, + + /** + * Method: panMapDone + * Finish the panning operation. Only call setCenter (through ) + * if the map has actually been moved. + * + * Parameters: + * xy - {} Pixel of the mouse position + */ + panMapDone: function(xy) { + if(this.panned) { + this.panMap(xy); + this.panned = false; + } + }, CLASS_NAME: "OpenLayers.Control.DragPan" }); diff --git a/tests/Control/test_DragPan.html b/tests/Control/test_DragPan.html index 7743765237..7becaf1d83 100644 --- a/tests/Control/test_DragPan.html +++ b/tests/Control/test_DragPan.html @@ -2,7 +2,7 @@