FeatureCollection.js
Summary
No overview generated for 'FeatureCollection.js'
mapbuilder.loadScript(baseDir+"/model/ModelBase.js");
function FeatureCollection(modelNode, parent) {
ModelBase.apply(this, new Array(modelNode, parent));
this.featureTagName = this.getProperty("mb:featureTagName", "topp:CITY_NAME");
this.coordsTagName = this.getProperty("mb:coordsTagName", "//gml:coordinates");
this.nodeSelectXpath = this.getProperty("mb:nodeSelectXpath");
this.coordSelectXpath = this.getProperty("mb:coordSelectXpath", "topp:the_geom/gml:MultiPoint/gml:pointMember/gml:Point/gml:coordinates");
this.convertCoords = function(objRef) {
if( objRef.doc && objRef.containerModel && objRef.containerModel.doc ) {
var coordNodes = objRef.doc.selectNodes( objRef.coordsTagName );
if (coordNodes.length>0 && objRef.containerModel) {
var srsNode = coordNodes[0].selectSingleNode("ancestor-or-self::*/@srsName");
if( srsNode && (srsNode.nodeValue.toUpperCase() != objRef.containerModel.getSRS().toUpperCase()) ) {
var sourceProj = new OpenLayers.Projection(srsNode.nodeValue);
objRef.setParam("modelStatus",mbGetMessage("convertingCoords"));
var containerProj = new OpenLayers.Projection(objRef.containerModel.getSRS());
for (var i=0; i<coordNodes.length; ++i) {
var coords = getNodeValue(coordNodes[i]);
var coordsArray = coords.split(' ');
var newCoords = '';
for (var j=0; j<coordsArray.length; ++j) {
var xy = coordsArray[j].split(',');
if (xy.length==2) {
var pt=new OpenLayers.Geometry.Point(xy[0],xy[1]);
pt.transform(sourceProj,containerProj);
newCoords += pt.x + ',' + pt.y + ' ';
}
}
coordNodes[i].firstChild.nodeValue=newCoords;
}
}
}
}
}
this.loadWfsRequests = function(objRef) {
if( objRef.containerModel.doc != null) {
var featureTypes = objRef.containerModel.doc.selectNodes("/wmc:OWSContext/wmc:ResourceList/wmc:FeatureType");
if( featureTypes.length > 0 ) {
for( var i=0; i<featureTypes.length; i++) {
var httpPayload = new Object();
var wfsFeature = featureTypes[i]
var server = wfsFeature.selectSingleNode("wmc:Server")
var onlineResource = server.selectSingleNode("wmc:OnlineResource")
httpPayload.method = onlineResource.getAttribute("method")
httpPayload.url = onlineResource.getAttribute("xlink:href")
var query = wfsFeature.selectSingleNode("wfs:GetFeature")
httpPayload.postData = (new XMLSerializer()).serializeToString( query )
objRef.wfsFeature = wfsFeature
objRef.newRequest(objRef,httpPayload);
}
}
}
}
this.addFirstListener("loadModel",this.convertCoords,this);
if( this.containerModel ) this.containerModel.addListener("loadModel",this.loadWfsRequests,this);
this.setHidden=function(featureName, hidden){
this.hidden = hidden;
this.callListeners("hidden", featureName);
}
this.getHidden=function(layerName){
return this.hidden;
}
this.hidden = false;
this.getFeatureNodes = function() {
return this.doc.selectNodes(this.nodeSelectXpath);
}
this.getFeatureName = function(featureNode) {
var labelNode = featureNode.selectSingleNode(this.featureTagName); //TBD: set this dynamically
return labelNode?getNodeValue(labelNode):mbGetMessage("noRssTitle");
}
this.getFeatureId = function(featureNode) {
return featureNode.getAttribute("fid")?featureNode.getAttribute("fid"):"no_id";
}
this.getFeaturePoint = function(featureNode) {
var coords = featureNode.selectSingleNode(this.coordSelectXpath);
if (coords) {
var point = getNodeValue(coords).split(',');
return point
} else {
return new Array(0,0); //or some other error to return?
}
}
this.getFeatureGeometry = function(featureNode) {
var geometryTag = featureNode.selectSingleNode(this.coordsTagName);
if( geometryTag != null )
return geometryTag.firstChild;
else {
alert(mbGetMessage("invalidGeom", (new XMLSerializer()).serializeToString(featureNode)));
}
}
}
Documentation generated by
JSDoc on Sun Apr 27 20:30:54 2008