1
|
/*
|
2
|
License: LGPL as per: http://www.gnu.org/copyleft/lesser.html
|
3
|
$Id: GeoRSS.js 3882 2008-02-27 15:41:33Z gjvoosten $
|
4
|
*/
|
5
|
|
6
|
// Ensure this object's dependancies are loaded.
|
7
|
mapbuilder.loadScript(baseDir+"/model/ModelBase.js");
|
8
|
|
9
|
/**
|
10
|
* Stores a GML Feature or FeatureCollection as defined by the
|
11
|
* Open Geospatial Consortium (http://www.opengeospatial.org/).
|
12
|
*
|
13
|
* WARNING: This model is only to be used if you do not want to embed the GeoRSS feed
|
14
|
* in the context doc. See also MAP-271
|
15
|
* @deprecated
|
16
|
* @constructor
|
17
|
* @base ModelBase
|
18
|
* @author Cameron Shorter
|
19
|
* @requires Sarissa
|
20
|
* @param modelNode The model's XML object node from the configuration document.
|
21
|
* @param parent The parent model for the object.
|
22
|
*/
|
23
|
function GeoRSS(modelNode, parent) {
|
24
|
// Inherit the ModelBase functions and parameters
|
25
|
ModelBase.apply(this, new Array(modelNode, parent));
|
26
|
|
27
|
/** init
|
28
|
* @param objRef Pointer to this object.
|
29
|
*/
|
30
|
this.initItems = function(objRef) {
|
31
|
var items = objRef.doc.selectNodes("rdf:RDF/rss:item");
|
32
|
if( items.length == 0 ) {
|
33
|
items = objRef.doc.selectNodes("atom:feed/atom:entry");
|
34
|
}
|
35
|
|
36
|
for (var i=0; i<items.length; ++i) {
|
37
|
var item = items[i];
|
38
|
item.setAttribute("divid", "RSS_Item_"+mbIds.getId());
|
39
|
}
|
40
|
}
|
41
|
// OBE this.addFirstListener("loadModel",this.initItems,this);
|
42
|
|
43
|
/**
|
44
|
* Returns the list of nodes selected by the nodeSelectpath
|
45
|
* @return list of nodes selected
|
46
|
*/
|
47
|
this.getFeatureNodes = function() {
|
48
|
return this.doc.selectNodes(this.nodeSelectXpath);
|
49
|
}
|
50
|
|
51
|
/**
|
52
|
* Returns a label for a node in the feature list
|
53
|
* @param featureNode the feature node to selectfrom
|
54
|
* @return a label for this feature
|
55
|
*/
|
56
|
this.getFeatureName = function(featureNode) {
|
57
|
var labelNode = featureNode.selectSingleNode("rss:title");
|
58
|
if( labelNode == null )
|
59
|
labelNode = featureNode.selectSingleNode("atom:title");
|
60
|
return labelNode?getNodeValue(labelNode):mbGetMessage("noRssTitle");
|
61
|
}
|
62
|
|
63
|
/**
|
64
|
* Returns an ID value for a node in the feature list
|
65
|
* @param featureNode the feature node to selectfrom
|
66
|
* @return ID for this feature
|
67
|
*/
|
68
|
this.getFeatureId = function(featureNode) {
|
69
|
var id = featureNode.getAttribute("divid")
|
70
|
if( id )
|
71
|
return id;
|
72
|
|
73
|
return "no_id";
|
74
|
}
|
75
|
|
76
|
/**
|
77
|
* Returns a point geometry for the feature
|
78
|
* @param featureNode the feature node to select from
|
79
|
* @return the geometric point for the node
|
80
|
*/
|
81
|
this.getFeaturePoint = function(featureNode) {
|
82
|
if (featureNode.selectSingleNode("geo:long")) {
|
83
|
var pointX = getNodeValue(featureNode.selectSingleNode("geo:long"));
|
84
|
var pointY = getNodeValue(featureNode.selectSingleNode("geo:lat"));
|
85
|
return new Array(pointX, pointY);
|
86
|
} else {
|
87
|
var pos = featureNode.selectSingleNode("georss:where/gml:Point/gml:pos")
|
88
|
if( pos != null ) {
|
89
|
var coordstr = getNodeValue(pos);
|
90
|
//alert("coords:"+coordstr );
|
91
|
var coords = coordstr.split(" ")
|
92
|
var pointX = coords[0]
|
93
|
var pointY = coords[1]
|
94
|
return new Array(pointX, pointY);
|
95
|
} else {
|
96
|
return new Array(0,0); //or some other error to return?
|
97
|
}
|
98
|
}
|
99
|
}
|
100
|
|
101
|
/**
|
102
|
* Returns the geometry for the feature
|
103
|
* @param featureNode the feature node to select from
|
104
|
* @return the geometric point for the node
|
105
|
*/
|
106
|
this.getFeatureGeometry = function(featureNode) {
|
107
|
if (featureNode.selectSingleNode("geo:long")) {
|
108
|
var pointX = getNodeValue(featureNode.selectSingleNode("geo:long"));
|
109
|
var pointY = getNodeValue(featureNode.selectSingleNode("geo:lat"));
|
110
|
return "POINT " + pointX + "," + pointY;
|
111
|
}
|
112
|
|
113
|
var pos = featureNode.selectSingleNode("georss:where/gml:Point/gml:pos")
|
114
|
if( pos != null ) {
|
115
|
var coordstr = getNodeValue(pos);
|
116
|
return "POINT " + coordstr;
|
117
|
}
|
118
|
|
119
|
var posList = featureNode.selectSingleNode("georss:where/gml:LineString/gml:posList")
|
120
|
if( posList != null ) { //WARNING: could overflow so get all nodes
|
121
|
var children = posList.childNodes;
|
122
|
var count = children.length;
|
123
|
var text="";
|
124
|
for( var i=0; i<count; i++ ) {
|
125
|
text += children[i].nodeValue;
|
126
|
}
|
127
|
//alert("count:"+ count + " length:"+text.length)
|
128
|
|
129
|
return "LINESTRING " + text;
|
130
|
}
|
131
|
|
132
|
var posList = featureNode.selectSingleNode("georss:where/gml:Polygon/gml:exterior/gml:LinearRing")
|
133
|
if( posList != null ) {
|
134
|
var coordstr = getNodeValue(posList);
|
135
|
return "POLYGON " + coordstr;
|
136
|
}
|
137
|
|
138
|
alert(mbGetMessage("invalidGmlGeom"));
|
139
|
return null
|
140
|
}
|
141
|
|
142
|
/**
|
143
|
* Get the GML Node out of the RSS feed
|
144
|
*/
|
145
|
this.getFeatureGml = function(featureNode) {
|
146
|
var where = featureNode.selectSingleNode("georss:where")
|
147
|
if( where != null ) {
|
148
|
var gml = where.firstChild;
|
149
|
return gml;
|
150
|
} else {
|
151
|
return null;
|
152
|
}
|
153
|
}
|
154
|
|
155
|
|
156
|
/**
|
157
|
* Returns a specific icon for that entry
|
158
|
* @param featureNode the feature node to select from
|
159
|
* @return the geometric point for the node
|
160
|
*/
|
161
|
this.getFeatureIcon = function( featureNode ) {
|
162
|
if( featureNode == null )
|
163
|
return null;
|
164
|
|
165
|
// look for an icon tag
|
166
|
var icon = featureNode.selectSingleNode("atom:icon");
|
167
|
if (icon != undefined) {
|
168
|
return getNodeValue(icon);
|
169
|
} else {
|
170
|
return null;
|
171
|
}
|
172
|
}
|
173
|
}
|
174
|
|