Pan.js 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for
  2. * full list of contributors). Published under the 2-clause BSD license.
  3. * See license.txt in the OpenLayers distribution or repository for the
  4. * full text of the license. */
  5. /**
  6. * @requires OpenLayers/Control/Button.js
  7. */
  8. /**
  9. * Class: OpenLayers.Control.Pan
  10. * The Pan control is a single button to pan the map in one direction. For
  11. * a more complete control see <OpenLayers.Control.PanPanel>.
  12. *
  13. * Inherits from:
  14. * - <OpenLayers.Control>
  15. */
  16. OpenLayers.Control.Pan = OpenLayers.Class(OpenLayers.Control.Button, {
  17. /**
  18. * APIProperty: slideFactor
  19. * {Integer} Number of pixels by which we'll pan the map in any direction
  20. * on clicking the arrow buttons, defaults to 50. If you want to pan
  21. * by some ratio of the map dimensions, use <slideRatio> instead.
  22. */
  23. slideFactor: 50,
  24. /**
  25. * APIProperty: slideRatio
  26. * {Number} The fraction of map width/height by which we'll pan the map
  27. * on clicking the arrow buttons. Default is null. If set, will
  28. * override <slideFactor>. E.g. if slideRatio is .5, then Pan Up will
  29. * pan up half the map height.
  30. */
  31. slideRatio: null,
  32. /**
  33. * Property: direction
  34. * {String} in {'North', 'South', 'East', 'West'}
  35. */
  36. direction: null,
  37. /**
  38. * Constructor: OpenLayers.Control.Pan
  39. * Control which handles the panning (in any of the cardinal directions)
  40. * of the map by a set px distance.
  41. *
  42. * Parameters:
  43. * direction - {String} The direction this button should pan.
  44. * options - {Object} An optional object whose properties will be used
  45. * to extend the control.
  46. */
  47. initialize: function(direction, options) {
  48. this.direction = direction;
  49. this.CLASS_NAME += this.direction;
  50. OpenLayers.Control.prototype.initialize.apply(this, [options]);
  51. },
  52. /**
  53. * Method: trigger
  54. */
  55. trigger: function(){
  56. if (this.map) {
  57. var getSlideFactor = OpenLayers.Function.bind(function (dim) {
  58. return this.slideRatio ?
  59. this.map.getSize()[dim] * this.slideRatio :
  60. this.slideFactor;
  61. }, this);
  62. switch (this.direction) {
  63. case OpenLayers.Control.Pan.NORTH:
  64. this.map.pan(0, -getSlideFactor("h"));
  65. break;
  66. case OpenLayers.Control.Pan.SOUTH:
  67. this.map.pan(0, getSlideFactor("h"));
  68. break;
  69. case OpenLayers.Control.Pan.WEST:
  70. this.map.pan(-getSlideFactor("w"), 0);
  71. break;
  72. case OpenLayers.Control.Pan.EAST:
  73. this.map.pan(getSlideFactor("w"), 0);
  74. break;
  75. }
  76. }
  77. },
  78. CLASS_NAME: "OpenLayers.Control.Pan"
  79. });
  80. OpenLayers.Control.Pan.NORTH = "North";
  81. OpenLayers.Control.Pan.SOUTH = "South";
  82. OpenLayers.Control.Pan.EAST = "East";
  83. OpenLayers.Control.Pan.WEST = "West";