#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
This commit is contained in:
@@ -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 <OpenLayers.Control.PanMap.panMap> and
|
||||
* <OpenLayers.Control.PanMap.panMapDone> 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 - {<OpenLayers.Pixel>} Pixel of the up position
|
||||
* xy - {<OpenLayers.Pixel>} 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 <panMap>)
|
||||
* if the map has actually been moved.
|
||||
*
|
||||
* Parameters:
|
||||
* xy - {<OpenLayers.Pixel>} Pixel of the mouse position
|
||||
*/
|
||||
panMapDone: function(xy) {
|
||||
if(this.panned) {
|
||||
this.panMap(xy);
|
||||
this.panned = false;
|
||||
}
|
||||
},
|
||||
|
||||
CLASS_NAME: "OpenLayers.Control.DragPan"
|
||||
});
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<head>
|
||||
<script src="../../lib/OpenLayers.js"></script>
|
||||
<script type="text/javascript"><!--
|
||||
var map;
|
||||
var map, control, layer;
|
||||
|
||||
function init_map() {
|
||||
control = new OpenLayers.Control.DragPan();
|
||||
@@ -36,6 +36,41 @@
|
||||
t.eq(map.getCenter().lat, res * 5, "Lat is " + (res * 5) + " after drag");
|
||||
t.eq(map.getCenter().lon, res * -5, "Lon is " + (res * -5) + " after drag");
|
||||
}
|
||||
function test_Control_DragPan_click(t) {
|
||||
t.plan(1);
|
||||
var control = new OpenLayers.Control.DragPan();
|
||||
var map = new OpenLayers.Map("map", {controls:[control]});
|
||||
var layer = new OpenLayers.Layer.WMS("OpenLayers WMS",
|
||||
"http://labs.metacarta.com/wms/vmap0",
|
||||
{layers: 'basic'});
|
||||
map.addLayer(layer);
|
||||
map.zoomToMaxExtent();
|
||||
map.zoomIn();
|
||||
control.activate();
|
||||
map.setCenter = function() {
|
||||
t.ok(false, "map.setCenter should not be called here");
|
||||
};
|
||||
var xy = new OpenLayers.Pixel(0, 0);
|
||||
var down = {
|
||||
'type': 'mousedown',
|
||||
'xy': xy,
|
||||
'which': 1
|
||||
};
|
||||
var move = {
|
||||
'type': 'mousemove',
|
||||
'xy': xy,
|
||||
'which': 1
|
||||
};
|
||||
var up = {
|
||||
'type': 'mouseup',
|
||||
'xy': xy,
|
||||
'which': 1
|
||||
};
|
||||
map.events.triggerEvent('mousedown', down);
|
||||
map.events.triggerEvent('mousemove', move);
|
||||
map.events.triggerEvent('mouseup', up);
|
||||
t.ok(true, "clicking without moving the mouse does not call setCenter");
|
||||
}
|
||||
|
||||
// -->
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user