/* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD * license. See http://svn.openlayers.org/trunk/openlayers/license.txt for the * full text of the license. */ /** * @requires OpenLayers/Format/GML/Base.js */ /** * Class: OpenLayers.Format.GML.v3 * Parses GML version 3. * * Inherits from: * - */ OpenLayers.Format.GML.v3 = OpenLayers.Class(OpenLayers.Format.GML.Base, { /** * Property: schemaLocation * {String} Schema location for a particular minor version. The writers * conform with the Simple Features Profile for GML. */ schemaLocation: "http://www.opengis.net/gml http://schemas.opengis.net/gml/3.1.1/profiles/gmlsfProfile/1.0.0/gmlsf.xsd", /** * Constructor: OpenLayers.Format.GML.v3 * Create a parser for GML v3. * * Parameters: * options - {Object} An optional object whose properties will be set on * this instance. * * Valid options properties: * featureType - {String} Local (without prefix) feature typeName (required). * featureNS - {String} Feature namespace (required). * geometryName - {String} Geometry element name. */ initialize: function(options) { OpenLayers.Format.GML.Base.prototype.initialize.apply(this, [options]); }, /** * Property: readers * Contains public functions, grouped by namespace prefix, that will * be applied when a namespaced node is found matching the function * name. The function will be applied in the scope of this parser * with two arguments: the node being read and a context object passed * from the parent. */ readers: { "gml": OpenLayers.Util.applyDefaults({ "featureMembers": function(node, obj) { this.readChildNodes(node, obj); }, "pos": function(node, obj) { var str = this.getChildValue(node).replace( this.regExes.trimSpace, "" ); var coords = str.split(this.regExes.splitSpace); var point; if(this.xy) { point = new OpenLayers.Geometry.Point( coords[0], coords[1], coords[2] ); } else { point = new OpenLayers.Geometry.Point( coords[1], coords[0], coords[2] ); } obj.points = [point]; }, "posList": function(node, obj) { var str = this.concatChildValues(node).replace( this.regExes.trimSpace, "" ); var coords = str.split(this.regExes.splitSpace); var dim = parseInt(node.getAttribute("dimension")) || 2; var j, x, y, z; var numPoints = coords.length / dim; var points = new Array(numPoints); for(var i=0, len=coords.length; i 0) { container.components = [ new OpenLayers.Geometry.MultiPolygon(obj.components) ]; } }, "surfaceMember": function(node, obj) { this.readChildNodes(node, obj); }, "surfaceMembers": function(node, obj) { this.readChildNodes(node, obj); }, "pointMembers": function(node, obj) { this.readChildNodes(node, obj); }, "lineStringMembers": function(node, obj) { this.readChildNodes(node, obj); }, "polygonMembers": function(node, obj) { this.readChildNodes(node, obj); }, "geometryMembers": function(node, obj) { this.readChildNodes(node, obj); }, "Envelope": function(node, container) { var obj = {points: new Array(2)}; this.readChildNodes(node, obj); if(!container.components) { container.components = []; } var min = obj.points[0]; var max = obj.points[1]; container.components.push( new OpenLayers.Bounds(min.x, min.y, max.x, max.y) ); }, "lowerCorner": function(node, container) { var obj = {}; this.readChildNodes(node, obj) container.points[0] = obj.points[0]; }, "upperCorner": function(node, container) { var obj = {}; this.readChildNodes(node, obj) container.points[1] = obj.points[0]; } }, OpenLayers.Format.GML.Base.prototype.readers["gml"]), "feature": OpenLayers.Format.GML.Base.prototype.readers["feature"], "wfs": OpenLayers.Format.GML.Base.prototype.readers["wfs"] }, /** * Method: write * * Parameters: * features - {Array() | OpenLayers.Feature.Vector} * An array of features or a single feature. * * Returns: * {String} Given an array of features, a doc with a gml:featureMembers * element will be returned. Given a single feature, a doc with a * gml:featureMember element will be returned. */ write: function(features) { var name; if(features instanceof Array) { name = "featureMembers"; } else { name = "featureMember"; } var root = this.writeNode("gml:" + name, features); this.setAttributeNS( root, this.namespaces["xsi"], "xsi:schemaLocation", this.schemaLocation ); return OpenLayers.Format.XML.prototype.write.apply(this, [root]); }, /** * Property: writers * As a compliment to the readers property, this structure contains public * writing functions grouped by namespace alias and named like the * node names they produce. */ writers: { "gml": OpenLayers.Util.applyDefaults({ "featureMembers": function(features) { var node = this.createElementNSPlus("gml:featureMembers"); for(var i=0, len=features.length; i