Strategy.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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/BaseTypes/Class.js
  7. */
  8. /**
  9. * Class: OpenLayers.Strategy
  10. * Abstract vector layer strategy class. Not to be instantiated directly. Use
  11. * one of the strategy subclasses instead.
  12. */
  13. OpenLayers.Strategy = OpenLayers.Class({
  14. /**
  15. * Property: layer
  16. * {<OpenLayers.Layer.Vector>} The layer this strategy belongs to.
  17. */
  18. layer: null,
  19. /**
  20. * Property: options
  21. * {Object} Any options sent to the constructor.
  22. */
  23. options: null,
  24. /**
  25. * Property: active
  26. * {Boolean} The control is active.
  27. */
  28. active: null,
  29. /**
  30. * Property: autoActivate
  31. * {Boolean} The creator of the strategy can set autoActivate to false
  32. * to fully control when the protocol is activated and deactivated.
  33. * Defaults to true.
  34. */
  35. autoActivate: true,
  36. /**
  37. * Property: autoDestroy
  38. * {Boolean} The creator of the strategy can set autoDestroy to false
  39. * to fully control when the strategy is destroyed. Defaults to
  40. * true.
  41. */
  42. autoDestroy: true,
  43. /**
  44. * Constructor: OpenLayers.Strategy
  45. * Abstract class for vector strategies. Create instances of a subclass.
  46. *
  47. * Parameters:
  48. * options - {Object} Optional object whose properties will be set on the
  49. * instance.
  50. */
  51. initialize: function(options) {
  52. OpenLayers.Util.extend(this, options);
  53. this.options = options;
  54. // set the active property here, so that user cannot override it
  55. this.active = false;
  56. },
  57. /**
  58. * APIMethod: destroy
  59. * Clean up the strategy.
  60. */
  61. destroy: function() {
  62. this.deactivate();
  63. this.layer = null;
  64. this.options = null;
  65. },
  66. /**
  67. * Method: setLayer
  68. * Called to set the <layer> property.
  69. *
  70. * Parameters:
  71. * {<OpenLayers.Layer.Vector>}
  72. */
  73. setLayer: function(layer) {
  74. this.layer = layer;
  75. },
  76. /**
  77. * Method: activate
  78. * Activate the strategy. Register any listeners, do appropriate setup.
  79. *
  80. * Returns:
  81. * {Boolean} True if the strategy was successfully activated or false if
  82. * the strategy was already active.
  83. */
  84. activate: function() {
  85. if (!this.active) {
  86. this.active = true;
  87. return true;
  88. }
  89. return false;
  90. },
  91. /**
  92. * Method: deactivate
  93. * Deactivate the strategy. Unregister any listeners, do appropriate
  94. * tear-down.
  95. *
  96. * Returns:
  97. * {Boolean} True if the strategy was successfully deactivated or false if
  98. * the strategy was already inactive.
  99. */
  100. deactivate: function() {
  101. if (this.active) {
  102. this.active = false;
  103. return true;
  104. }
  105. return false;
  106. },
  107. CLASS_NAME: "OpenLayers.Strategy"
  108. });