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 FeatureCollection(modelNode, parent) {
18
  // Inherit the ModelBase functions and parameters
19
  ModelBase.apply(this, new Array(modelNode, parent));
20

    
21
  // Namespace to use when doing Xpath queries, usually set in config file.
22
  if (!this.namespace){
23
    this.namespace = "xmlns:gml='http://www.opengis.net/gml' xmlns:wfs='http://www.opengis.net/wfs'";
24
  }
25

    
26
  /**
27
   * convert coordinates in the GML document to the SRS of the map container, 
28
   * if required.  The coordinate values are replaced in the GML document.
29
   * @param objRef Pointer to this object.
30
   */
31
  this.convertCoords = function(objRef) {
32
    if( objRef.doc && objRef.containerModel && objRef.containerModel.doc ) {
33
	  var coordNodes = objRef.doc.selectNodes("//gml:coordinates");
34
	  if (coordNodes.length>0 && objRef.containerModel) {
35
	    var srsNode = coordNodes[0].selectSingleNode("ancestor-or-self::*/@srsName");
36
	    if ( srsNode.nodeValue.toUpperCase() != objRef.containerModel.getSRS().toUpperCase() ) {
37
	      var sourceProj = new Proj(srsNode.nodeValue);
38
	      objRef.setParam("modelStatus","converting coordinates");
39
	      var containerProj = new Proj(objRef.containerModel.getSRS());
40
	      for (var i=0; i<coordNodes.length; ++i) {
41
	        var coords = coordNodes[i].firstChild.nodeValue;
42
	        var coordsArray = coords.split(' ');
43
	        var newCoords = '';
44
	        for (var j=0; j<coordsArray.length; ++j) {
45
	          var xy = coordsArray[j].split(',');
46
	          if (xy.length==2) {
47
	            var llTemp = sourceProj.Inverse(xy);
48
	            xy = containerProj.Forward(llTemp);
49
	            newCoords += xy.join(',') + ' ';
50
	          }
51
	        }
52
	        coordNodes[i].firstChild.nodeValue=newCoords;
53
	      }
54
	    }
55
      }
56
    }
57
  }
58
  this.addFirstListener("loadModel",this.convertCoords,this);
59
  if( this.containerModel ) this.containerModel.addListener("loadModel",this.convertCoords,this);
60

    
61
  /**
62
   * Change a feature's visibility.
63
   * @param featureName The name of the feature to set the hidden value for
64
   * @param hidden, 1=hidden, 0=not hidden.
65
   */
66
  this.setHidden=function(featureName, hidden){
67
    this.hidden = hidden;
68
    this.callListeners("hidden", featureName);
69
  }
70

    
71
  /**
72
   * Geta feature's visibility.
73
   * @param featureName The name of the feature to set the hidden value for
74
   * @return hidden value, true=hidden, false=not hidden.
75
   */
76
  this.getHidden=function(layerName){
77
    return this.hidden;
78
  }
79
  this.hidden = false;
80

    
81
  /**
82
   * Returns the list of nodes selected by the nodeSelectpath.  These nodes
83
   * will be the individual feature memebers from the collection.
84
   * @return list of nodes selected 
85
   */
86
  this.getFeatureNodes = function() {
87
    return this.doc.selectNodes(this.nodeSelectXpath);
88
  }
89

    
90
  /**
91
   * Returns a label for a node in the feature list
92
   * @param featureNode the feature node to selectfrom
93
   * @return a label for this feature
94
   */
95
  this.getFeatureName = function(featureNode) {
96
    var labelNode = featureNode.selectSingleNode("topp:CITY_NAME");   //TBD: set this dynamically
97
    return labelNode?labelNode.firstChild.nodeValue:"No RSS title";
98
  }
99

    
100
  /**
101
   * Returns an ID value for a node in the feature list
102
   * @param featureNode the feature node to selectfrom
103
   * @return ID for this feature
104
   */
105
  this.getFeatureId = function(featureNode) {
106
    return featureNode.getAttribute("fid")?featureNode.getAttribute("fid"):"no_id";
107
  }
108

    
109
  /**
110
   * Returns a point geometry for the feature
111
   * @param featureNode the feature node to select from
112
   * @return the geometric point for the node
113
   */
114
  this.getFeaturePoint = function(featureNode) {
115
	 var coordSelectXpath = "topp:the_geom/gml:MultiPoint/gml:pointMember/gml:Point/gml:coordinates";//TBD: set this dynamically
116
    var coords = featureNode.selectSingleNode(coordSelectXpath);
117
    if (coords) {
118
      var point = coords.firstChild.nodeValue.split(',');
119
      return point
120
    } else {
121
      return new Array(0,0);  //or some other error to return?
122
    }
123
  }
124

    
125

    
126
}
127

    
(4-4/18)