Style2.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. * @requires OpenLayers/Rule.js
  8. * @requires OpenLayers/Symbolizer/Point.js
  9. * @requires OpenLayers/Symbolizer/Line.js
  10. * @requires OpenLayers/Symbolizer/Polygon.js
  11. * @requires OpenLayers/Symbolizer/Text.js
  12. * @requires OpenLayers/Symbolizer/Raster.js
  13. */
  14. /**
  15. * Class: OpenLayers.Style2
  16. * This class represents a collection of rules for rendering features.
  17. */
  18. OpenLayers.Style2 = OpenLayers.Class({
  19. /**
  20. * Property: id
  21. * {String} A unique id for this session.
  22. */
  23. id: null,
  24. /**
  25. * APIProperty: name
  26. * {String} Style identifier.
  27. */
  28. name: null,
  29. /**
  30. * APIProperty: title
  31. * {String} Title of this style.
  32. */
  33. title: null,
  34. /**
  35. * APIProperty: description
  36. * {String} Description of this style.
  37. */
  38. description: null,
  39. /**
  40. * APIProperty: layerName
  41. * {<String>} Name of the layer that this style belongs to, usually
  42. * according to the NamedLayer attribute of an SLD document.
  43. */
  44. layerName: null,
  45. /**
  46. * APIProperty: isDefault
  47. * {Boolean}
  48. */
  49. isDefault: false,
  50. /**
  51. * APIProperty: rules
  52. * {Array(<OpenLayers.Rule>)} Collection of rendering rules.
  53. */
  54. rules: null,
  55. /**
  56. * Constructor: OpenLayers.Style2
  57. * Creates a style representing a collection of rendering rules.
  58. *
  59. * Parameters:
  60. * config - {Object} An object containing properties to be set on the
  61. * style. Any documented properties may be set at construction.
  62. *
  63. * Return:
  64. * {<OpenLayers.Style2>} A new style object.
  65. */
  66. initialize: function(config) {
  67. OpenLayers.Util.extend(this, config);
  68. this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_");
  69. },
  70. /**
  71. * APIMethod: destroy
  72. * nullify references to prevent circular references and memory leaks
  73. */
  74. destroy: function() {
  75. for (var i=0, len=this.rules.length; i<len; i++) {
  76. this.rules[i].destroy();
  77. }
  78. delete this.rules;
  79. },
  80. /**
  81. * APIMethod: clone
  82. * Clones this style.
  83. *
  84. * Returns:
  85. * {<OpenLayers.Style2>} Clone of this style.
  86. */
  87. clone: function() {
  88. var config = OpenLayers.Util.extend({}, this);
  89. // clone rules
  90. if (this.rules) {
  91. config.rules = [];
  92. for (var i=0, len=this.rules.length; i<len; ++i) {
  93. config.rules.push(this.rules[i].clone());
  94. }
  95. }
  96. return new OpenLayers.Style2(config);
  97. },
  98. CLASS_NAME: "OpenLayers.Style2"
  99. });