When set to true, this allow pan-dragging while outside the map. Thanks vmx for the initial patches. r=vmx, bartvde (closes #39) git-svn-id: http://svn.openlayers.org/trunk/openlayers@9791 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
94 lines
2.3 KiB
JavaScript
94 lines
2.3 KiB
JavaScript
/* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
|
|
* license. See http://svn.openlayers.org/trunk/openlayers/license.txt for the
|
|
* full text of the license. */
|
|
|
|
/**
|
|
* @requires OpenLayers/Control.js
|
|
* @requires OpenLayers/Handler/Drag.js
|
|
*/
|
|
|
|
/**
|
|
* Class: OpenLayers.Control.DragPan
|
|
* The DragPan control pans the map with a drag of the mouse.
|
|
*
|
|
* Inherits from:
|
|
* - <OpenLayers.Control>
|
|
*/
|
|
OpenLayers.Control.DragPan = OpenLayers.Class(OpenLayers.Control, {
|
|
|
|
/**
|
|
* Property: type
|
|
* {OpenLayers.Control.TYPES}
|
|
*/
|
|
type: OpenLayers.Control.TYPE_TOOL,
|
|
|
|
/**
|
|
* Property: panned
|
|
* {Boolean} The map moved.
|
|
*/
|
|
panned: false,
|
|
|
|
/**
|
|
* Property: interval
|
|
* {Integer} The number of milliseconds that should ellapse before
|
|
* panning the map again. Set this to increase dragging performance.
|
|
* Defaults to 25 milliseconds.
|
|
*/
|
|
interval: 25,
|
|
|
|
/**
|
|
* APIProperty: documentDrag
|
|
* {Boolean} If set to true, mouse dragging will continue even if the
|
|
* mouse cursor leaves the map viewport. Default is false.
|
|
*/
|
|
documentDrag: false,
|
|
|
|
/**
|
|
* Method: draw
|
|
* Creates a Drag handler, using <panMap> and
|
|
* <panMapDone> as callbacks.
|
|
*/
|
|
draw: function() {
|
|
this.handler = new OpenLayers.Handler.Drag(this, {
|
|
"move": this.panMap,
|
|
"done": this.panMapDone
|
|
}, {
|
|
interval: this.interval,
|
|
documentDrag: this.documentDrag
|
|
}
|
|
);
|
|
},
|
|
|
|
/**
|
|
* Method: panMap
|
|
*
|
|
* Parameters:
|
|
* xy - {<OpenLayers.Pixel>} Pixel of the mouse position
|
|
*/
|
|
panMap: function(xy) {
|
|
this.panned = true;
|
|
this.map.pan(
|
|
this.handler.last.x - xy.x,
|
|
this.handler.last.y - xy.y,
|
|
{dragging: this.handler.dragging, animate: false}
|
|
);
|
|
},
|
|
|
|
/**
|
|
* 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"
|
|
});
|