Project

General

Profile

1
/*
2
License: LGPL as per: http://www.gnu.org/copyleft/lesser.html
3
$Id$
4
*/
5

    
6
/**
7
 * Stores a GML Feature or FeatureCollection as defined by the
8
 * Open GIS Conortium http://opengis.org.
9
 *
10
 * @constructor
11
 * @base ModelBase
12
 * @author Cameron Shorter
13
 * @requires Sarissa
14
 * @param modelNode The model's XML object node from the configuration document.
15
 * @param parent    The parent model for the object.
16
  */
17
function GeoRSS(modelNode, parent) {
18
  // Inherit the ModelBase functions and parameters
19
  ModelBase.apply(this, new Array(modelNode, parent));
20

    
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.
24
   * @param objRef Pointer to this object.
25
   */
26
  this.initItems = function(objRef) {
27
    var items = objRef.doc.selectNodes("rdf:RDF/rss:item");
28
    if( items.length == 0 ) {
29
      items = objRef.doc.selectNodes("atom:feed/atom:entry");
30
    }
31
    //alert(Sarissa.serialize(objRef.doc) );
32
    //alert( "items:"+items.length );
33
    
34
    for (var i=0; i<items.length; ++i) {
35
      var item = items[i];
36
      item.setAttribute("id", "RSS_Item_"+mbIds.getId());
37
      //convert to GML?
38
    }
39
  }
40
  this.addFirstListener("loadModel",this.initItems,this);
41

    
42
  /**
43
   * Returns the list of nodes selected by the nodeSelectpath
44
   * @return list of nodes selected 
45
   */
46
  this.getFeatureNodes = function() {
47
    return this.doc.selectNodes(this.nodeSelectXpath);
48
  }
49

    
50
  /**
51
   * Returns a label for a node in the feature list
52
   * @param featureNode the feature node to selectfrom
53
   * @return a label for this feature
54
   */
55
  this.getFeatureName = function(featureNode) {
56
    var labelNode = featureNode.selectSingleNode("rss:title");
57
    if( labelNode == null )
58
      labelNode = featureNode.selectSingleNode("atom:title");
59
    return labelNode?labelNode.firstChild.nodeValue:"No RSS title";
60
  }
61

    
62
  /**
63
   * Returns an ID value for a node in the feature list
64
   * @param featureNode the feature node to selectfrom
65
   * @return ID for this feature
66
   */
67
  this.getFeatureId = function(featureNode) {
68
    var id = featureNode.getAttribute("id")
69
    if( id )
70
      return id;
71
      
72
    id = featureNode.getAttribute("atom:id")
73
    if( id )
74
      return id;
75
      
76
    return "no_id";
77
  }
78

    
79
  /**
80
   * Returns a point geometry for the feature
81
   * @param featureNode the feature node to select from
82
   * @return the geometric point for the node
83
   */
84
  this.getFeaturePoint = function(featureNode) {
85
    if (featureNode.selectSingleNode("geo:long")) {
86
      var pointX = featureNode.selectSingleNode("geo:long").firstChild.nodeValue;
87
      var pointY = featureNode.selectSingleNode("geo:lat").firstChild.nodeValue;
88
      return new Array(pointX, pointY);
89
    } else {
90
       var pos = featureNode.selectSingleNode("georss:where/gml:Point/gml:pos")
91
       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);
98
       } else {
99
         return new Array(0,0);  //or some other error to return?
100
       }
101
    }
102
  }
103
 
104
  /**
105
  * Returns a specific icon for that entry
106
  * @param featureNode the feature node to select from
107
  * @return the geometric point for the node
108
  */
109
  this.getFeatureIcon = function( featureNode ) {
110
    if( featureNode == null )
111
      return null;
112
      
113
    // look for an icon tag
114
    var icon = featureNode.selectSingleNode("atom:icon");
115
    if (icon != undefined) {
116
      return icon.firstChild.nodeValue;
117
    } else {
118
      return null;
119
    }
120
  }
121

    
122
}
123

    
(6-6/18)