Format.js 3.9 KB

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