Pan.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /* Copyright (c) 2006-2011 by OpenLayers Contributors (see authors.txt for
  2. * full list of contributors). Published under the Clear BSD license.
  3. * See http://svn.openlayers.org/trunk/openlayers/license.txt for the
  4. * full text of the license. */
  5. /**
  6. * @requires OpenLayers/Control.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, {
  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. * Property: type
  39. * {String} The type of <OpenLayers.Control> -- When added to a
  40. * <Control.Panel>, 'type' is used by the panel to determine how to
  41. * handle our events.
  42. */
  43. type: OpenLayers.Control.TYPE_BUTTON,
  44. /**
  45. * Constructor: OpenLayers.Control.Pan
  46. * Control which handles the panning (in any of the cardinal directions)
  47. * of the map by a set px distance.
  48. *
  49. * Parameters:
  50. * direction - {String} The direction this button should pan.
  51. * options - {Object} An optional object whose properties will be used
  52. * to extend the control.
  53. */
  54. initialize: function(direction, options) {
  55. this.direction = direction;
  56. this.CLASS_NAME += this.direction;
  57. OpenLayers.Control.prototype.initialize.apply(this, [options]);
  58. },
  59. /**
  60. * Method: trigger
  61. */
  62. trigger: function(){
  63. var getSlideFactor = OpenLayers.Function.bind(function (dim) {
  64. return this.slideRatio ?
  65. this.map.getSize()[dim] * this.slideRatio :
  66. this.slideFactor;
  67. }, this);
  68. switch (this.direction) {
  69. case OpenLayers.Control.Pan.NORTH:
  70. this.map.pan(0, -getSlideFactor("h"));
  71. break;
  72. case OpenLayers.Control.Pan.SOUTH:
  73. this.map.pan(0, getSlideFactor("h"));
  74. break;
  75. case OpenLayers.Control.Pan.WEST:
  76. this.map.pan(-getSlideFactor("w"), 0);
  77. break;
  78. case OpenLayers.Control.Pan.EAST:
  79. this.map.pan(getSlideFactor("w"), 0);
  80. break;
  81. }
  82. },
  83. CLASS_NAME: "OpenLayers.Control.Pan"
  84. });
  85. OpenLayers.Control.Pan.NORTH = "North";
  86. OpenLayers.Control.Pan.SOUTH = "South";
  87. OpenLayers.Control.Pan.EAST = "East";
  88. OpenLayers.Control.Pan.WEST = "West";