Revision 4307
Added by ben leinfelder over 15 years ago
FeatureCollection.js | ||
---|---|---|
1 | 1 |
/* |
2 | 2 |
License: LGPL as per: http://www.gnu.org/copyleft/lesser.html |
3 |
$Id$ |
|
3 |
$Id: FeatureCollection.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 |
* |
10 | 13 |
* @constructor |
11 | 14 |
* @base ModelBase |
... | ... | |
18 | 21 |
// Inherit the ModelBase functions and parameters |
19 | 22 |
ModelBase.apply(this, new Array(modelNode, parent)); |
20 | 23 |
|
24 |
this.featureTagName = this.getProperty("mb:featureTagName", "topp:CITY_NAME"); |
|
25 |
this.coordsTagName = this.getProperty("mb:coordsTagName", "//gml:coordinates"); |
|
26 |
this.nodeSelectXpath = this.getProperty("mb:nodeSelectXpath"); |
|
27 |
this.coordSelectXpath = this.getProperty("mb:coordSelectXpath", "topp:the_geom/gml:MultiPoint/gml:pointMember/gml:Point/gml:coordinates"); |
|
28 |
|
|
21 | 29 |
// 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 |
} |
|
30 |
//if (!this.namespace){
|
|
31 |
// this.namespace = "xmlns:gml='http://www.opengis.net/gml' xmlns:wfs='http://www.opengis.net/wfs'";
|
|
32 |
//}
|
|
25 | 33 |
|
26 | 34 |
/** |
27 | 35 |
* convert coordinates in the GML document to the SRS of the map container, |
... | ... | |
29 | 37 |
* @param objRef Pointer to this object. |
30 | 38 |
*/ |
31 | 39 |
this.convertCoords = function(objRef) { |
40 |
|
|
32 | 41 |
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 |
} |
|
42 |
var coordNodes = objRef.doc.selectNodes( objRef.coordsTagName );
|
|
43 |
if (coordNodes.length>0 && objRef.containerModel) {
|
|
44 |
var srsNode = coordNodes[0].selectSingleNode("ancestor-or-self::*/@srsName");
|
|
45 |
if( srsNode && (srsNode.nodeValue.toUpperCase() != objRef.containerModel.getSRS().toUpperCase()) ) {
|
|
46 |
var sourceProj = new OpenLayers.Projection(srsNode.nodeValue);
|
|
47 |
objRef.setParam("modelStatus",mbGetMessage("convertingCoords"));
|
|
48 |
var containerProj = new OpenLayers.Projection(objRef.containerModel.getSRS());
|
|
49 |
for (var i=0; i<coordNodes.length; ++i) {
|
|
50 |
var coords = getNodeValue(coordNodes[i]);
|
|
51 |
var coordsArray = coords.split(' ');
|
|
52 |
var newCoords = '';
|
|
53 |
for (var j=0; j<coordsArray.length; ++j) {
|
|
54 |
var xy = coordsArray[j].split(',');
|
|
55 |
if (xy.length==2) {
|
|
56 |
var pt=new OpenLayers.Geometry.Point(xy[0],xy[1]);
|
|
57 |
pt.transform(sourceProj,containerProj);
|
|
58 |
newCoords += pt.x + ',' + pt.y + ' ';
|
|
59 |
}
|
|
60 |
}
|
|
61 |
coordNodes[i].firstChild.nodeValue=newCoords;
|
|
62 |
}
|
|
63 |
}
|
|
55 | 64 |
} |
56 | 65 |
} |
57 | 66 |
} |
67 |
|
|
68 |
/** |
|
69 |
* Called when the OWSContext gets loaded |
|
70 |
*/ |
|
71 |
this.loadWfsRequests = function(objRef) { |
|
72 |
//alert( "FeatureCollection loadModel:"+(new XMLSerializer()).serializeToString(objRef.containerModel.doc)) |
|
73 |
// we need to retrieve all the features |
|
74 |
if( objRef.containerModel.doc != null) { |
|
75 |
//alert( "FeatureCollection loadModel:"+(new XMLSerializer()).serializeToString(objRef.containerModel.doc)) |
|
76 |
var featureTypes = objRef.containerModel.doc.selectNodes("/wmc:OWSContext/wmc:ResourceList/wmc:FeatureType"); |
|
77 |
if( featureTypes.length > 0 ) { |
|
78 |
for( var i=0; i<featureTypes.length; i++) { |
|
79 |
var httpPayload = new Object(); |
|
80 |
|
|
81 |
var wfsFeature = featureTypes[i] |
|
82 |
//alert( "feature:"+ (new XMLSerializer()).serializeToString(wfsFeature) ) |
|
83 |
|
|
84 |
var server = wfsFeature.selectSingleNode("wmc:Server") |
|
85 |
//alert( "server:"+ (new XMLSerializer()).serializeToString(server) ) |
|
86 |
var onlineResource = server.selectSingleNode("wmc:OnlineResource") |
|
87 |
//alert( "onlineResource:"+ (new XMLSerializer()).serializeToString(onlineResource) ) |
|
88 |
httpPayload.method = onlineResource.getAttribute("method") |
|
89 |
httpPayload.url = onlineResource.getAttribute("xlink:href") |
|
90 |
//alert( "server:"+ httpPayload.method + " " + httpPayload.url ) |
|
91 |
|
|
92 |
var query = wfsFeature.selectSingleNode("wfs:GetFeature") |
|
93 |
//alert( "query2:"+ (new XMLSerializer()).serializeToString( query )) |
|
94 |
httpPayload.postData = (new XMLSerializer()).serializeToString( query ) |
|
95 |
|
|
96 |
// This does not work on IE for some reaso |
|
97 |
// wfsFeature.model = objRef; |
|
98 |
objRef.wfsFeature = wfsFeature |
|
99 |
objRef.newRequest(objRef,httpPayload); |
|
100 |
|
|
101 |
//objRef.containerModel.setParam('addLayer', wfsFeature); |
|
102 |
//var sld = wfsFeature.selectSingleNode("wmc:StyleList") |
|
103 |
} |
|
104 |
} |
|
105 |
} |
|
106 |
} |
|
107 |
|
|
58 | 108 |
this.addFirstListener("loadModel",this.convertCoords,this); |
59 |
if( this.containerModel ) this.containerModel.addListener("loadModel",this.convertCoords,this); |
|
109 |
|
|
110 |
if( this.containerModel ) this.containerModel.addListener("loadModel",this.loadWfsRequests,this); |
|
60 | 111 |
|
61 | 112 |
/** |
62 | 113 |
* Change a feature's visibility. |
... | ... | |
80 | 131 |
|
81 | 132 |
/** |
82 | 133 |
* Returns the list of nodes selected by the nodeSelectpath. These nodes |
83 |
* will be the individual feature memebers from the collection.
|
|
134 |
* will be the individual feature members from the collection. |
|
84 | 135 |
* @return list of nodes selected |
85 | 136 |
*/ |
86 | 137 |
this.getFeatureNodes = function() { |
... | ... | |
93 | 144 |
* @return a label for this feature |
94 | 145 |
*/ |
95 | 146 |
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";
|
|
147 |
var labelNode = featureNode.selectSingleNode(this.featureTagName); //TBD: set this dynamically
|
|
148 |
return labelNode?getNodeValue(labelNode):mbGetMessage("noRssTitle");
|
|
98 | 149 |
} |
99 | 150 |
|
100 | 151 |
/** |
... | ... | |
112 | 163 |
* @return the geometric point for the node |
113 | 164 |
*/ |
114 | 165 |
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); |
|
166 |
var coords = featureNode.selectSingleNode(this.coordSelectXpath); |
|
117 | 167 |
if (coords) { |
118 |
var point = coords.firstChild.nodeValue.split(',');
|
|
168 |
var point = getNodeValue(coords).split(',');
|
|
119 | 169 |
return point |
120 | 170 |
} else { |
121 | 171 |
return new Array(0,0); //or some other error to return? |
122 | 172 |
} |
123 | 173 |
} |
124 |
|
|
125 |
|
|
174 |
|
|
175 |
/** |
|
176 |
* Returns a GML geometry for the feature |
|
177 |
* @param featureNode the feature node to select from |
|
178 |
* @return the GML for the node |
|
179 |
*/ |
|
180 |
this.getFeatureGeometry = function(featureNode) { |
|
181 |
var geometryTag = featureNode.selectSingleNode(this.coordsTagName); |
|
182 |
if( geometryTag != null ) |
|
183 |
return geometryTag.firstChild; |
|
184 |
else { |
|
185 |
alert(mbGetMessage("invalidGeom", (new XMLSerializer()).serializeToString(featureNode))); |
|
186 |
} |
|
187 |
} |
|
126 | 188 |
} |
127 |
|
Also available in: Unified diff
upgrade to MapBuilder 1.5rc2 - includes support for Firefox 3 compatibility (yes, it is also EOLed)