v1_1.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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/WMSDescribeLayer.js
  7. * @requires OpenLayers/Format/OGCExceptionReport.js
  8. */
  9. /**
  10. * Class: OpenLayers.Format.WMSDescribeLayer.v1_1_1
  11. * Read SLD WMS DescribeLayer response for WMS 1.1.X
  12. * WMS 1.1.X is tightly coupled to SLD 1.0.0
  13. *
  14. * Example DescribeLayer request:
  15. * http://demo.opengeo.org/geoserver/wms?request=DescribeLayer&version=1.1.1&layers=topp:states
  16. *
  17. * Inherits from:
  18. * - <OpenLayers.Format.WMSDescribeLayer>
  19. */
  20. OpenLayers.Format.WMSDescribeLayer.v1_1_1 = OpenLayers.Class(
  21. OpenLayers.Format.WMSDescribeLayer, {
  22. /**
  23. * Constructor: OpenLayers.Format.WMSDescribeLayer
  24. * Create a new parser for WMS DescribeLayer responses.
  25. *
  26. * Parameters:
  27. * options - {Object} An optional object whose properties will be set on
  28. * this instance.
  29. */
  30. initialize: function(options) {
  31. OpenLayers.Format.WMSDescribeLayer.prototype.initialize.apply(this,
  32. [options]);
  33. },
  34. /**
  35. * APIMethod: read
  36. * Read DescribeLayer data from a string, and return the response.
  37. * The OGC defines 2 formats which are allowed for output,
  38. * so we need to parse these 2 types for version 1.1.X
  39. *
  40. * Parameters:
  41. * data - {String} or {DOMElement} data to read/parse.
  42. *
  43. * Returns:
  44. * {Object} Object with a layerDescriptions property, which holds an Array
  45. * of {<LayerDescription>} objects which have:
  46. * - {String} owsType: WFS/WCS
  47. * - {String} owsURL: the online resource
  48. * - {String} typeName: the name of the typename on the owsType service
  49. * - {String} layerName: the name of the WMS layer we did a lookup for
  50. */
  51. read: function(data) {
  52. if(typeof data == "string") {
  53. data = OpenLayers.Format.XML.prototype.read.apply(this, [data]);
  54. }
  55. var root = data.documentElement;
  56. var children = root.childNodes;
  57. var describelayer = {layerDescriptions: []};
  58. var childNode, nodeName;
  59. for(var i=0; i<children.length; ++i) {
  60. childNode = children[i];
  61. nodeName = childNode.nodeName;
  62. if (nodeName == 'LayerDescription') {
  63. var layerName = childNode.getAttribute('name');
  64. var owsType = '';
  65. var owsURL = '';
  66. var typeName = '';
  67. // check for owsType and owsURL attributes
  68. if (childNode.getAttribute('owsType')) {
  69. owsType = childNode.getAttribute('owsType');
  70. owsURL = childNode.getAttribute('owsURL');
  71. } else {
  72. // look for wfs or wcs attribute
  73. if (childNode.getAttribute('wfs') != '') {
  74. owsType = 'WFS';
  75. owsURL = childNode.getAttribute('wfs');
  76. } else if (childNode.getAttribute('wcs') != '') {
  77. owsType = 'WCS';
  78. owsURL = childNode.getAttribute('wcs');
  79. }
  80. }
  81. // look for Query child
  82. var query = childNode.getElementsByTagName('Query');
  83. if(query.length > 0) {
  84. typeName = query[0].getAttribute('typeName');
  85. if (!typeName) {
  86. // because of Ionic bug
  87. typeName = query[0].getAttribute('typename');
  88. }
  89. }
  90. var layerDescription = {
  91. layerName: layerName, owsType: owsType,
  92. owsURL: owsURL, typeName: typeName
  93. };
  94. describelayer.layerDescriptions.push(layerDescription);
  95. //TODO do this in deprecated.js instead:
  96. // array style index for backwards compatibility
  97. describelayer.length = describelayer.layerDescriptions.length;
  98. describelayer[describelayer.length - 1] = layerDescription;
  99. } else if (nodeName == 'ServiceException') {
  100. // an exception must have occurred, so parse it
  101. var parser = new OpenLayers.Format.OGCExceptionReport();
  102. return {
  103. error: parser.read(data)
  104. };
  105. }
  106. }
  107. return describelayer;
  108. },
  109. CLASS_NAME: "OpenLayers.Format.WMSDescribeLayer.v1_1_1"
  110. });
  111. // Version alias - workaround for http://trac.osgeo.org/mapserver/ticket/2257
  112. OpenLayers.Format.WMSDescribeLayer.v1_1_0 =
  113. OpenLayers.Format.WMSDescribeLayer.v1_1_1;