-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathowc_atom.js
372 lines (329 loc) · 10.4 KB
/
owc_atom.js
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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
/*
This file is part of NiMMbus system. NiMMbus is a solution for
storing geospatial resources on the MiraMon private cloud.
MiraMon is a family of GIS&RS products developed since 1994
and includes a desktop GIS, a desktop Metadata Manager, a
Web Map Browser and the NiMMbus system.
The NiMMbus JavaScript client is free software: you can redistribute
it and/or modify it under the terms of the GNU Affero General
Public License as published by the Free Software Foundation,
either version 3 of the License, or (at your option) any later version.
The NiMMbus JavaScript client is distributed in the hope that
it will be useful, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General
Public License along with the NiMMbus JavaScript Client.
If not, see https://www.gnu.org/licenses/licenses.html#AGPL.
The NiMMbus JavaScript Client can be updated from
https://github.com/grumets/NiMMbus.
Copyright 2014, 2024 Xavier Pons
Aquest codi JavaScript ha estat idea de Joan Masó Pau (joan maso at uab cat)
amb l'ajut de l'Alaitz Zabala (alaitz zabala at uab cat)
dins del grup del MiraMon. MiraMon és un projecte del
CREAF que elabora programari de Sistema d'Informació Geogràfica
i de Teledetecció per a la visualització, consulta, edició i anàlisi
de mapes ràsters i vectorials. Aquest programari inclou
aplicacions d'escriptori i també servidors i clients per Internet.
No tots aquests productes són gratuïts o de codi obert.
En particular, el client JavaScript del NiMMbus es distribueix sota
els termes de la llicència GNU Affero General Public License,
mireu https://www.gnu.org/licenses/licenses.html#AGPL.
El client JavaScript del NiMMbus es pot actualitzar des de
https://github.com/grumets/NiMMbus.
The main objective of this library is to read an XML Atom encoding for OGC OWS Context
and return the same object structure that is specified in GeoJSON encoding for OWS Context
This way implementors will be able to deal with both encodings in the same way.
This is an example of how to use it:
...
if (format=="text/xml)
owc=ParseOWSContextAtom(doc.documentElement);
else if (format=="application/json")
owc=JSON.parse(doc);
else
{
alert("unknown format");
return
}
alert("title: " + owc.properties.title);
...
Developed by Joan Masó.
*/
"use strict"
//Generic functions to access XML fragments.
/*I apply a simplified solution that I found here:
http://stackoverflow.com/questions/2207941/getelementsbytagname-problem-in-chrome-and-safari
Final solution working in IE6,7,8, FF, Opera, Chrome and Safari
point_coords = item.getElementsByTagName('georss:point')[0];
if(!point_coords || point_coords == null){
point_coords = item.getElementsByTagName('point')[0];
}
if(!point_coords || point_coords == null){
point_coords = item.getElementsByTagNameNS('http://www.georss.org/georss', 'point')[0];
}
return point_coords
*/
//OWS Context Atom reader
function ParseOWSContextAtomAuthor(author)
{
return {
name: GetValueXMLElementByName(author, "atom", "name"),
email: GetValueXMLElementByName(author, "atom", "email"),
uri: GetValueXMLElementByName(author, "atom", "uri")
}
}
function ParseOWSContextAtomAuthors(entry)
{
var i_author=0;
var authors=[];
var elems=entry.childNodes;
if (elems)
{
for (var item=0; item<elems.length; item++)
{
if (elems[item].nodeName=="author" || elems[item].nodeName=="atom:author")
{
authors[i_author]=ParseOWSContextAtomAuthor(elems.item(item));
i_author++;
}
}
}
return authors;
}
function ParseOWSContextAtomLink(link)
{
return {
href: GetValueXMLAttributeByName(link, "atom", "href"),
type: GetValueXMLAttributeByName(link, "atom", "type"),
hreflang: GetValueXMLAttributeByName(link, "atom", "hreflang"),
title: GetValueXMLAttributeByName(link, "atom", "title"),
length: GetValueXMLAttributeByName(link, "atom", "length")
};
}
function ParseOWSContextAtomLinks(entry)
{
var i_link=0;
var rel, links={};
var elems=entry.childNodes;
if (elems)
{
for (var item=0; item<elems.length; item++)
{
if (elems[item].nodeName=="link" || elems[item].nodeName=="atom:link")
{
rel=GetValueXMLAttributeByName(elems[item], "atom", "rel");
if (rel=="alternate" || rel==null)
{
if (!links.alternates)
links.alternates=[];
links.alternates[links.alternates.length]=ParseOWSContextAtomLink(elems[item]);
}
if (rel=="related")
{
if (!links.relateds)
links.relateds=[];
links.relateds[links.relateds.length]=ParseOWSContextAtomLink(elems[item]);
}
if (rel=="self")
{
if (!links.selfs)
links.selfs=[];
links.selfs[links.selfs.length]=ParseOWSContextAtomLink(elems[item]);
}
if (rel=="enclosure")
{
if (!links.enclosures)
links.enclosures=[];
links.enclosures[links.enclosures.length]=ParseOWSContextAtomLink(elems[item]);
}
if (rel=="icon")
{
if (!links.icons)
links.icons=[];
links.icons[links.icons.length]=ParseOWSContextAtomLink(elems[item]);
}
if (rel=="via")
{
if (!links.via)
links.via=ParseOWSContextAtomLink(elems[item]);
}
}
}
}
return links;
}
function ParseOWSContextGmlPos(gml_pos)
{
var coords=[];
if (gml_pos && gml_pos.childNodes[0] && gml_pos.childNodes[0].nodeValue)
{
var s=gml_pos.childNodes[0].nodeValue;
coords[1]=parseFloat(s.substring(0, s.indexOf(" ")));
coords[0]=parseFloat(s.substring(s.indexOf(" ")+1, s.length));
return coords;
}
else
return null;
}
function ParseOWSContextGmlPoint(gml_point)
{
var point={};
point.type="Point";
var elems=gml_point.childNodes;
if (elems)
{
for (var item=0; item<elems.length; item++)
{
if (elems[item].nodeName=="pos" || elems[item].nodeName=="gml:pos")
point.coordinates=ParseOWSContextGmlPos(elems.item(item));
}
}
return point;
}
function ParseOWSContextGeoRSSWhere(georss_where)
{
var elems=georss_where.childNodes;
if (elems)
{
for (var item=0; item<elems.length; item++)
{
if (elems[item].nodeName=="Point" || elems[item].nodeName=="gml:Point")
return ParseOWSContextGmlPoint(elems.item(item));
}
}
return null;
}
function ParseOWSContextAtomEntryGeoRSSPosition(entry)
{
var elems=entry.childNodes;
if (elems)
{
for (var item=0; item<elems.length; item++)
{
if (elems[item].nodeName=="where" || elems[item].nodeName=="georss:where")
return ParseOWSContextGeoRSSWhere(elems.item(item));
}
}
return null;
}
function ParseOWSContextAtomEntryGeoRSSElevation(entry)
{
var elems=entry.childNodes;
if (elems)
{
for (var item=0; item<elems.length; item++)
{
if (elems[item].nodeName=="elev" || elems[item].nodeName=="georss:elev")
{
if (elems[item].childNodes[0] && elems[item].childNodes[0].nodeValue)
return elems[item].childNodes[0].nodeValue;
}
}
}
return null;
}
function ParseOWSContextAtomCategory(category)
{
return {
term: GetValueXMLAttributeByName(category, "atom", "term"),
scheme: GetValueXMLAttributeByName(category, "atom", "scheme"),
label: GetValueXMLAttributeByName(category, "atom", "label")
}
}
function ParseOWSContextAtomCategories(entry)
{
var i_category=0;
var categories=[];
var elems=entry.childNodes;
if (elems)
{
for (var item=0; item<elems.length; item++)
{
if (elems[item].nodeName=="category" || elems[item].nodeName=="atom:category")
{
categories[i_category]=ParseOWSContextAtomCategory(elems.item(item));
i_category++;
}
}
}
return categories;
}
function ParseOWSContextAtomEntryProperties(entry)
{
return {
title: GetValueXMLElementByName(entry, "atom", "title"),
subtitle: GetValueXMLElementByName(entry, "atom", "subtitle"),
updated: GetValueXMLElementByName(entry, "atom", "updated"),
authors: ParseOWSContextAtomAuthors(entry),
publisher: GetValueXMLElementByName(entry, "atom", "publisher"),
rights: GetValueXMLElementByName(entry, "dc", "rights"),
elevation: ParseOWSContextAtomEntryGeoRSSElevation(entry),
content: GetValueXMLElementByName(entry, "atom", "content"),
links: ParseOWSContextAtomLinks(entry),
//temporalExtent
//preview
//contentByRef, offering
//contextMetadata
//active, minScaleDenominator, maxScaleDenominator, folder
categories: ParseOWSContextAtomCategories(entry),
openData: GetValueXMLElementByName(entry, "nmmb", "openData")
}
}
function ParseOWSContextAtomEntry(entry)
{
return {
id: GetValueXMLElementByName(entry, "atom", "id"),
properties: ParseOWSContextAtomEntryProperties(entry),
geometry: ParseOWSContextAtomEntryGeoRSSPosition(entry)
}
}
function ParseOWSContextAtomMainProperties(root)
{
return {
lang: GetValueXMLAttributeByName(root, "xml", "lang"),
title: GetValueXMLElementByName(root, "atom", "title"),
subtitle: GetValueXMLElementByName(root, "atom", "subtitle"),
updated: GetValueXMLElementByName(root, "atom", "updated"),
authors: ParseOWSContextAtomAuthors(root),
publisher: GetValueXMLElementByName(root, "atom", "publisher"),
creator: GetValueXMLElementByName(root, "atom", "creator"),
rights: GetValueXMLElementByName(root, "dc", "rights"),
links: ParseOWSContextAtomLinks(root),
//areaOfInterest deduir de georss where.
//timeIntervalOfInterest
//contextMetadata
//categories
/*I also include this 3 tags documented in http://www.opensearch.org/Specifications/OpenSearch/1.1/
even if they are not included in the OGC 14-055 document.*/
totalResults: GetValueXMLElementByName(root, "opensearch", "totalResults"),
startIndex: GetValueXMLElementByName(root, "opensearch", "startIndex"),
itemsPerPage: GetValueXMLElementByName(root, "opensearch", "itemsPerPage")
}
}
function ParseOWSContextAtomEntries(root)
{
var i_entry=0;
var features=[];
var elems=root.childNodes;
if (elems)
{
for (var item=0; item<elems.length; item++)
{
if (elems[item].nodeName=="entry" || elems[item].nodeName=="atom:entry")
{
features[i_entry]=ParseOWSContextAtomEntry(elems.item(item));
i_entry++;
}
}
}
return features;
}
function ParseOWSContextAtom(root)
{
return {
type: "FeatureCollection",
id: GetValueXMLElementByName(root, "atom", "id"),
properties: ParseOWSContextAtomMainProperties(root),
features: ParseOWSContextAtomEntries(root)
}
}