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