OWSContext.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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/Format/Context.js
  7. */
  8. /**
  9. * Class: OpenLayers.Format.OWSContext
  10. * Read and write OWS Context documents. OWS Context documents are a
  11. * preliminary OGC (Open Geospatial Consortium) standard for storing the
  12. * state of a web mapping application. In a way it is the successor to
  13. * Web Map Context (WMC), since it is more generic and more types of layers
  14. * can be stored. Also, nesting of layers is supported since version 0.3.1.
  15. * For more information see: http://www.ogcnetwork.net/context
  16. *
  17. * Inherits from:
  18. * - <OpenLayers.Format.Context>
  19. */
  20. OpenLayers.Format.OWSContext = OpenLayers.Class(OpenLayers.Format.Context,{
  21. /**
  22. * APIProperty: defaultVersion
  23. * {String} Version number to assume if none found. Default is "0.3.1".
  24. */
  25. defaultVersion: "0.3.1",
  26. /**
  27. * Constructor: OpenLayers.Format.OWSContext
  28. * Create a new parser for OWS Context documents.
  29. *
  30. * Parameters:
  31. * options - {Object} An optional object whose properties will be set on
  32. * this instance.
  33. */
  34. /**
  35. * Method: getVersion
  36. * Returns the version to use. Subclasses can override this function
  37. * if a different version detection is needed.
  38. *
  39. * Parameters:
  40. * root - {DOMElement}
  41. * options - {Object} Optional configuration object.
  42. *
  43. * Returns:
  44. * {String} The version to use.
  45. */
  46. getVersion: function(root, options) {
  47. var version = OpenLayers.Format.XML.VersionedOGC.prototype.getVersion.apply(
  48. this, arguments);
  49. // 0.3.1 is backwards compatible with 0.3.0
  50. if (version === "0.3.0") {
  51. version = this.defaultVersion;
  52. }
  53. return version;
  54. },
  55. /**
  56. * Method: toContext
  57. * Create a context object free from layer given a map or a
  58. * context object.
  59. *
  60. * Parameters:
  61. * obj - {<OpenLayers.Map> | Object} The map or context.
  62. *
  63. * Returns:
  64. * {Object} A context object.
  65. */
  66. toContext: function(obj) {
  67. var context = {};
  68. if(obj.CLASS_NAME == "OpenLayers.Map") {
  69. context.bounds = obj.getExtent();
  70. context.maxExtent = obj.maxExtent;
  71. context.projection = obj.projection;
  72. context.size = obj.getSize();
  73. context.layers = obj.layers;
  74. }
  75. return context;
  76. },
  77. CLASS_NAME: "OpenLayers.Format.OWSContext"
  78. });