Revision 4307
Added by ben leinfelder over 15 years ago
GeoRSS.js | ||
---|---|---|
1 | 1 |
/* |
2 | 2 |
License: LGPL as per: http://www.gnu.org/copyleft/lesser.html |
3 |
$Id$ |
|
3 |
$Id: GeoRSS.js 3882 2008-02-27 15:41:33Z gjvoosten $
|
|
4 | 4 |
*/ |
5 | 5 |
|
6 |
// Ensure this object's dependancies are loaded. |
|
7 |
mapbuilder.loadScript(baseDir+"/model/ModelBase.js"); |
|
8 |
|
|
6 | 9 |
/** |
7 | 10 |
* Stores a GML Feature or FeatureCollection as defined by the |
8 |
* Open GIS Conortium http://opengis.org.
|
|
11 |
* Open Geospatial Consortium (http://www.opengeospatial.org/).
|
|
9 | 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 |
|
10 | 16 |
* @constructor |
11 | 17 |
* @base ModelBase |
12 | 18 |
* @author Cameron Shorter |
... | ... | |
18 | 24 |
// Inherit the ModelBase functions and parameters |
19 | 25 |
ModelBase.apply(this, new Array(modelNode, parent)); |
20 | 26 |
|
21 |
/** |
|
22 |
* convert coordinates in the GML document to the SRS of the map container, |
|
23 |
* if required. The coordinate values are replaced in the GML document. |
|
27 |
/** init |
|
24 | 28 |
* @param objRef Pointer to this object. |
25 | 29 |
*/ |
26 | 30 |
this.initItems = function(objRef) { |
27 | 31 |
var items = objRef.doc.selectNodes("rdf:RDF/rss:item"); |
28 | 32 |
if( items.length == 0 ) { |
29 | 33 |
items = objRef.doc.selectNodes("atom:feed/atom:entry"); |
30 |
} |
|
31 |
//alert(Sarissa.serialize(objRef.doc) ); |
|
32 |
//alert( "items:"+items.length ); |
|
33 |
|
|
34 |
} |
|
35 |
|
|
34 | 36 |
for (var i=0; i<items.length; ++i) { |
35 | 37 |
var item = items[i]; |
36 |
item.setAttribute("id", "RSS_Item_"+mbIds.getId()); |
|
37 |
//convert to GML? |
|
38 |
item.setAttribute("divid", "RSS_Item_"+mbIds.getId()); |
|
38 | 39 |
} |
39 | 40 |
} |
40 |
this.addFirstListener("loadModel",this.initItems,this); |
|
41 |
// OBE this.addFirstListener("loadModel",this.initItems,this);
|
|
41 | 42 |
|
42 | 43 |
/** |
43 | 44 |
* Returns the list of nodes selected by the nodeSelectpath |
... | ... | |
56 | 57 |
var labelNode = featureNode.selectSingleNode("rss:title"); |
57 | 58 |
if( labelNode == null ) |
58 | 59 |
labelNode = featureNode.selectSingleNode("atom:title"); |
59 |
return labelNode?labelNode.firstChild.nodeValue:"No RSS title";
|
|
60 |
return labelNode?getNodeValue(labelNode):mbGetMessage("noRssTitle");
|
|
60 | 61 |
} |
61 | 62 |
|
62 | 63 |
/** |
... | ... | |
65 | 66 |
* @return ID for this feature |
66 | 67 |
*/ |
67 | 68 |
this.getFeatureId = function(featureNode) { |
68 |
var id = featureNode.getAttribute("id") |
|
69 |
var id = featureNode.getAttribute("divid")
|
|
69 | 70 |
if( id ) |
70 | 71 |
return id; |
71 | 72 |
|
72 |
id = featureNode.getAttribute("atom:id") |
|
73 |
if( id ) |
|
74 |
return id; |
|
75 |
|
|
76 | 73 |
return "no_id"; |
77 | 74 |
} |
78 | 75 |
|
... | ... | |
83 | 80 |
*/ |
84 | 81 |
this.getFeaturePoint = function(featureNode) { |
85 | 82 |
if (featureNode.selectSingleNode("geo:long")) { |
86 |
var pointX = featureNode.selectSingleNode("geo:long").firstChild.nodeValue;
|
|
87 |
var pointY = featureNode.selectSingleNode("geo:lat").firstChild.nodeValue;
|
|
83 |
var pointX = getNodeValue(featureNode.selectSingleNode("geo:long"));
|
|
84 |
var pointY = getNodeValue(featureNode.selectSingleNode("geo:lat"));
|
|
88 | 85 |
return new Array(pointX, pointY); |
89 | 86 |
} else { |
90 | 87 |
var pos = featureNode.selectSingleNode("georss:where/gml:Point/gml:pos") |
91 | 88 |
if( pos != null ) { |
92 |
var coordstr = pos.firstChild.nodeValue
|
|
93 |
//alert("coords:"+coordstr );
|
|
94 |
var coords = coordstr.split(" ")
|
|
95 |
var pointX = coords[0]
|
|
96 |
var pointY = coords[1]
|
|
97 |
return new Array(pointX, pointY);
|
|
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);
|
|
98 | 95 |
} else { |
99 | 96 |
return new Array(0,0); //or some other error to return? |
100 | 97 |
} |
101 | 98 |
} |
102 | 99 |
} |
103 | 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 |
|
|
104 | 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 |
/** |
|
105 | 157 |
* Returns a specific icon for that entry |
106 | 158 |
* @param featureNode the feature node to select from |
107 | 159 |
* @return the geometric point for the node |
... | ... | |
113 | 165 |
// look for an icon tag |
114 | 166 |
var icon = featureNode.selectSingleNode("atom:icon"); |
115 | 167 |
if (icon != undefined) { |
116 |
return icon.firstChild.nodeValue;
|
|
168 |
return getNodeValue(icon);
|
|
117 | 169 |
} else { |
118 | 170 |
return null; |
119 | 171 |
} |
120 | 172 |
} |
121 |
|
|
122 | 173 |
} |
123 | 174 |
|
Also available in: Unified diff
upgrade to MapBuilder 1.5rc2 - includes support for Firefox 3 compatibility (yes, it is also EOLed)