diff --git a/lib/OpenLayers/Control/Pan.js b/lib/OpenLayers/Control/Pan.js index b793e83d5f..7056ad3066 100644 --- a/lib/OpenLayers/Control/Pan.js +++ b/lib/OpenLayers/Control/Pan.js @@ -20,10 +20,20 @@ OpenLayers.Control.Pan = OpenLayers.Class(OpenLayers.Control, { /** * APIProperty: slideFactor * {Integer} Number of pixels by which we'll pan the map in any direction - * on clicking the arrow buttons, defaults to 50. + * on clicking the arrow buttons, defaults to 50. If you want to pan + * by some ratio of the map dimensions, use instead. */ slideFactor: 50, + /** + * APIProperty: slideRatio + * {Number} The fraction of map width/height by which we'll pan the map + * on clicking the arrow buttons. Default is null. If set, will + * override . E.g. if slideRatio is .5, then Pan Up will + * pan up half the map height. + */ + slideRatio: null, + /** * Property: direction * {String} in {'North', 'South', 'East', 'West'} @@ -61,18 +71,24 @@ OpenLayers.Control.Pan = OpenLayers.Class(OpenLayers.Control, { */ trigger: function(){ + var getSlideFactor = OpenLayers.Function.bind(function (dim) { + return this.slideRatio ? + this.map.getSize()[dim] * this.slideRatio : + this.slideFactor; + }, this); + switch (this.direction) { case OpenLayers.Control.Pan.NORTH: - this.map.pan(0, -this.slideFactor); + this.map.pan(0, -getSlideFactor("h")); break; case OpenLayers.Control.Pan.SOUTH: - this.map.pan(0, this.slideFactor); + this.map.pan(0, getSlideFactor("h")); break; case OpenLayers.Control.Pan.WEST: - this.map.pan(-this.slideFactor, 0); + this.map.pan(-getSlideFactor("w"), 0); break; case OpenLayers.Control.Pan.EAST: - this.map.pan(this.slideFactor, 0); + this.map.pan(getSlideFactor("w"), 0); break; } }, diff --git a/lib/OpenLayers/Control/PanPanel.js b/lib/OpenLayers/Control/PanPanel.js index ef566041ff..15c7615024 100644 --- a/lib/OpenLayers/Control/PanPanel.js +++ b/lib/OpenLayers/Control/PanPanel.js @@ -33,10 +33,20 @@ OpenLayers.Control.PanPanel = OpenLayers.Class(OpenLayers.Control.Panel, { /** * APIProperty: slideFactor * {Integer} Number of pixels by which we'll pan the map in any direction - * on clicking the arrow buttons, defaults to 50. + * on clicking the arrow buttons, defaults to 50. If you want to pan + * by some ratio of the map dimensions, use instead. */ slideFactor: 50, + /** + * APIProperty: slideRatio + * {Number} The fraction of map width/height by which we'll pan the map + * on clicking the arrow buttons. Default is null. If set, will + * override . E.g. if slideRatio is .5, then Pan Up will + * pan up half the map height. + */ + slideRatio: null, + /** * Constructor: OpenLayers.Control.PanPanel * Add the four directional pan buttons. @@ -47,15 +57,15 @@ OpenLayers.Control.PanPanel = OpenLayers.Class(OpenLayers.Control.Panel, { */ initialize: function(options) { OpenLayers.Control.Panel.prototype.initialize.apply(this, [options]); + var options = { + slideFactor: this.slideFactor, + slideRatio: this.slideRatio + }; this.addControls([ - new OpenLayers.Control.Pan(OpenLayers.Control.Pan.NORTH, - {slideFactor: this.slideFactor}), - new OpenLayers.Control.Pan(OpenLayers.Control.Pan.SOUTH, - {slideFactor: this.slideFactor}), - new OpenLayers.Control.Pan(OpenLayers.Control.Pan.EAST, - {slideFactor: this.slideFactor}), - new OpenLayers.Control.Pan(OpenLayers.Control.Pan.WEST, - {slideFactor: this.slideFactor}) + new OpenLayers.Control.Pan(OpenLayers.Control.Pan.NORTH, options), + new OpenLayers.Control.Pan(OpenLayers.Control.Pan.SOUTH, options), + new OpenLayers.Control.Pan(OpenLayers.Control.Pan.EAST, options), + new OpenLayers.Control.Pan(OpenLayers.Control.Pan.WEST, options) ]); }, diff --git a/tests/Control/PanPanel.html b/tests/Control/PanPanel.html index 73baa0023e..0c643be523 100644 --- a/tests/Control/PanPanel.html +++ b/tests/Control/PanPanel.html @@ -3,7 +3,7 @@ +