Format.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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/BaseTypes/Class.js
  7. * @requires OpenLayers/Util.js
  8. */
  9. /**
  10. * Class: OpenLayers.Format
  11. * Base class for format reading/writing a variety of formats. Subclasses
  12. * of OpenLayers.Format are expected to have read and write methods.
  13. */
  14. OpenLayers.Format = OpenLayers.Class({
  15. /**
  16. * Property: options
  17. * {Object} A reference to options passed to the constructor.
  18. */
  19. options: null,
  20. /**
  21. * APIProperty: externalProjection
  22. * {<OpenLayers.Projection>} When passed a externalProjection and
  23. * internalProjection, the format will reproject the geometries it
  24. * reads or writes. The externalProjection is the projection used by
  25. * the content which is passed into read or which comes out of write.
  26. * In order to reproject, a projection transformation function for the
  27. * specified projections must be available. This support may be
  28. * provided via proj4js or via a custom transformation function. See
  29. * {<OpenLayers.Projection.addTransform>} for more information on
  30. * custom transformations.
  31. */
  32. externalProjection: null,
  33. /**
  34. * APIProperty: internalProjection
  35. * {<OpenLayers.Projection>} When passed a externalProjection and
  36. * internalProjection, the format will reproject the geometries it
  37. * reads or writes. The internalProjection is the projection used by
  38. * the geometries which are returned by read or which are passed into
  39. * write. In order to reproject, a projection transformation function
  40. * for the specified projections must be available. This support may be
  41. * provided via proj4js or via a custom transformation function. See
  42. * {<OpenLayers.Projection.addTransform>} for more information on
  43. * custom transformations.
  44. */
  45. internalProjection: null,
  46. /**
  47. * APIProperty: data
  48. * {Object} When <keepData> is true, this is the parsed string sent to
  49. * <read>.
  50. */
  51. data: null,
  52. /**
  53. * APIProperty: keepData
  54. * {Object} Maintain a reference (<data>) to the most recently read data.
  55. * Default is false.
  56. */
  57. keepData: false,
  58. /**
  59. * Constructor: OpenLayers.Format
  60. * Instances of this class are not useful. See one of the subclasses.
  61. *
  62. * Parameters:
  63. * options - {Object} An optional object with properties to set on the
  64. * format
  65. *
  66. * Valid options:
  67. * keepData - {Boolean} If true, upon <read>, the data property will be
  68. * set to the parsed object (e.g. the json or xml object).
  69. *
  70. * Returns:
  71. * An instance of OpenLayers.Format
  72. */
  73. initialize: function(options) {
  74. OpenLayers.Util.extend(this, options);
  75. this.options = options;
  76. },
  77. /**
  78. * APIMethod: destroy
  79. * Clean up.
  80. */
  81. destroy: function() {
  82. },
  83. /**
  84. * Method: read
  85. * Read data from a string, and return an object whose type depends on the
  86. * subclass.
  87. *
  88. * Parameters:
  89. * data - {string} Data to read/parse.
  90. *
  91. * Returns:
  92. * Depends on the subclass
  93. */
  94. read: function(data) {
  95. throw new Error('Read not implemented.');
  96. },
  97. /**
  98. * Method: write
  99. * Accept an object, and return a string.
  100. *
  101. * Parameters:
  102. * object - {Object} Object to be serialized
  103. *
  104. * Returns:
  105. * {String} A string representation of the object.
  106. */
  107. write: function(object) {
  108. throw new Error('Write not implemented.');
  109. },
  110. CLASS_NAME: "OpenLayers.Format"
  111. });