9d0155b9a5aa402e0d4db41bb4c62714be800897.svn-base
8.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
/* Copyright (c) 2006-2011 by OpenLayers Contributors (see authors.txt for
* full list of contributors). Published under the Clear BSD license.
* See http://svn.openlayers.org/trunk/openlayers/license.txt for the
* full text of the license. */
/**
* @requires OpenLayers/Format/WMTSCapabilities.js
* @requires OpenLayers/Format/OWSCommon/v1_1_0.js
*/
/**
* Class: OpenLayers.Format.WMTSCapabilities.v1_0_0
* Read WMTS Capabilities version 1.0.0.
*
* Inherits from:
* - <OpenLayers.Format.WMTSCapabilities>
*/
OpenLayers.Format.WMTSCapabilities.v1_0_0 = OpenLayers.Class(
OpenLayers.Format.OWSCommon.v1_1_0, {
/**
* Property: version
* {String} The parser version ("1.0.0").
*/
version: "1.0.0",
/**
* Property: namespaces
* {Object} Mapping of namespace aliases to namespace URIs.
*/
namespaces: {
ows: "http://www.opengis.net/ows/1.1",
wmts: "http://www.opengis.net/wmts/1.0",
xlink: "http://www.w3.org/1999/xlink"
},
/**
* Property: yx
* {Object} Members in the yx object are used to determine if a CRS URN
* corresponds to a CRS with y,x axis order. Member names are CRS URNs
* and values are boolean. Defaults come from the
* <OpenLayers.Format.WMTSCapabilities> prototype.
*/
yx: null,
/**
* Property: defaultPrefix
* {String} The default namespace alias for creating element nodes.
*/
defaultPrefix: "wmts",
/**
* Constructor: OpenLayers.Format.WMTSCapabilities.v1_0_0
* Create a new parser for WMTS capabilities version 1.0.0.
*
* Parameters:
* options - {Object} An optional object whose properties will be set on
* this instance.
*/
initialize: function(options) {
OpenLayers.Format.XML.prototype.initialize.apply(this, [options]);
this.options = options;
var yx = OpenLayers.Util.extend(
{}, OpenLayers.Format.WMTSCapabilities.prototype.yx
);
this.yx = OpenLayers.Util.extend(yx, this.yx);
},
/**
* APIMethod: read
* Read capabilities data from a string, and return info about the WMTS.
*
* Parameters:
* data - {String} or {DOMElement} data to read/parse.
*
* Returns:
* {Object} Information about the SOS service.
*/
read: function(data) {
if(typeof data == "string") {
data = OpenLayers.Format.XML.prototype.read.apply(this, [data]);
}
if(data && data.nodeType == 9) {
data = data.documentElement;
}
var capabilities = {};
this.readNode(data, capabilities);
capabilities.version = this.version;
return capabilities;
},
/**
* Property: readers
* Contains public functions, grouped by namespace prefix, that will
* be applied when a namespaced node is found matching the function
* name. The function will be applied in the scope of this parser
* with two arguments: the node being read and a context object passed
* from the parent.
*/
readers: {
"wmts": {
"Capabilities": function(node, obj) {
this.readChildNodes(node, obj);
},
"Contents": function(node, obj) {
obj.contents = {};
obj.contents.layers = [];
obj.contents.tileMatrixSets = {};
this.readChildNodes(node, obj.contents);
},
"Layer": function(node, obj) {
var layer = {
styles: [],
formats: [],
tileMatrixSetLinks: []
};
layer.layers = [];
this.readChildNodes(node, layer);
obj.layers.push(layer);
},
"Style": function(node, obj) {
var style = {};
style.isDefault = (node.getAttribute("isDefault") === "true");
this.readChildNodes(node, style);
obj.styles.push(style);
},
"Format": function(node, obj) {
obj.formats.push(this.getChildValue(node));
},
"TileMatrixSetLink": function(node, obj) {
var tileMatrixSetLink = {};
this.readChildNodes(node, tileMatrixSetLink);
obj.tileMatrixSetLinks.push(tileMatrixSetLink);
},
"TileMatrixSet": function(node, obj) {
// node could be child of wmts:Contents or wmts:TileMatrixSetLink
// duck type wmts:Contents by looking for layers
if (obj.layers) {
// TileMatrixSet as object type in schema
var tileMatrixSet = {
matrixIds: []
};
this.readChildNodes(node, tileMatrixSet);
obj.tileMatrixSets[tileMatrixSet.identifier] = tileMatrixSet;
} else {
// TileMatrixSet as string type in schema
obj.tileMatrixSet = this.getChildValue(node);
}
},
"TileMatrix": function(node, obj) {
var tileMatrix = {
supportedCRS: obj.supportedCRS
};
this.readChildNodes(node, tileMatrix);
obj.matrixIds.push(tileMatrix);
},
"ScaleDenominator": function(node, obj) {
obj.scaleDenominator = parseFloat(this.getChildValue(node));
},
"TopLeftCorner": function(node, obj) {
var topLeftCorner = this.getChildValue(node);
var coords = topLeftCorner.split(" ");
// decide on axis order for the given CRS
var yx;
if (obj.supportedCRS) {
// extract out version from URN
var crs = obj.supportedCRS.replace(
/urn:ogc:def:crs:(\w+):.+:(\w+)$/,
"urn:ogc:def:crs:$1::$2"
);
yx = !!this.yx[crs];
}
if (yx) {
obj.topLeftCorner = new OpenLayers.LonLat(
coords[1], coords[0]
);
} else {
obj.topLeftCorner = new OpenLayers.LonLat(
coords[0], coords[1]
);
}
},
"TileWidth": function(node, obj) {
obj.tileWidth = parseInt(this.getChildValue(node));
},
"TileHeight": function(node, obj) {
obj.tileHeight = parseInt(this.getChildValue(node));
},
"MatrixWidth": function(node, obj) {
obj.matrixWidth = parseInt(this.getChildValue(node));
},
"MatrixHeight": function(node, obj) {
obj.matrixHeight = parseInt(this.getChildValue(node));
},
"ResourceURL": function(node, obj) {
obj.resourceUrl = obj.resourceUrl || {};
obj.resourceUrl[node.getAttribute("resourceType")] = {
format: node.getAttribute("format"),
template: node.getAttribute("template")
};
},
// not used for now, can be added in the future though
/*"Themes": function(node, obj) {
obj.themes = [];
this.readChildNodes(node, obj.themes);
},
"Theme": function(node, obj) {
var theme = {};
this.readChildNodes(node, theme);
obj.push(theme);
},*/
"WSDL": function(node, obj) {
obj.wsdl = {};
obj.wsdl.href = node.getAttribute("xlink:href");
// TODO: other attributes of <WSDL> element
},
"ServiceMetadataURL": function(node, obj) {
obj.serviceMetadataUrl = {};
obj.serviceMetadataUrl.href = node.getAttribute("xlink:href");
// TODO: other attributes of <ServiceMetadataURL> element
}
},
"ows": OpenLayers.Format.OWSCommon.v1_1_0.prototype.readers["ows"]
},
CLASS_NAME: "OpenLayers.Format.WMTSCapabilities.v1_0_0"
});