1
/* Copyright (c) 2006-2010 by OpenLayers Contributors (see authors.txt for
2
* full list of contributors). Published under the Clear BSD license.
3
* See http://svn.openlayers.org/trunk/openlayers/license.txt for the
4
* full text of the license. */
7
* @requires OpenLayers/Format/GML/Base.js
11
* Class: OpenLayers.Format.GML.v2
12
* Parses GML version 2.
15
* - <OpenLayers.Format.GML.Base>
17
OpenLayers.Format.GML.v2 = OpenLayers.Class(OpenLayers.Format.GML.Base, {
20
* Property: schemaLocation
21
* {String} Schema location for a particular minor version.
23
schemaLocation: "http://www.opengis.net/gml http://schemas.opengis.net/gml/2.1.2/feature.xsd",
26
* Constructor: OpenLayers.Format.GML.v2
27
* Create a parser for GML v2.
30
* options - {Object} An optional object whose properties will be set on
33
* Valid options properties:
34
* featureType - {String} Local (without prefix) feature typeName (required).
35
* featureNS - {String} Feature namespace (required).
36
* geometryName - {String} Geometry element name.
38
initialize: function(options) {
39
OpenLayers.Format.GML.Base.prototype.initialize.apply(this, [options]);
44
* Contains public functions, grouped by namespace prefix, that will
45
* be applied when a namespaced node is found matching the function
46
* name. The function will be applied in the scope of this parser
47
* with two arguments: the node being read and a context object passed
51
"gml": OpenLayers.Util.applyDefaults({
52
"outerBoundaryIs": function(node, container) {
54
this.readChildNodes(node, obj);
55
container.outer = obj.components[0];
57
"innerBoundaryIs": function(node, container) {
59
this.readChildNodes(node, obj);
60
container.inner.push(obj.components[0]);
62
"Box": function(node, container) {
64
this.readChildNodes(node, obj);
65
if(!container.components) {
66
container.components = [];
68
var min = obj.points[0];
69
var max = obj.points[1];
70
container.components.push(
71
new OpenLayers.Bounds(min.x, min.y, max.x, max.y)
74
}, OpenLayers.Format.GML.Base.prototype.readers["gml"]),
75
"feature": OpenLayers.Format.GML.Base.prototype.readers["feature"],
76
"wfs": OpenLayers.Format.GML.Base.prototype.readers["wfs"]
83
* features - {Array(<OpenLayers.Feature.Vector>) | OpenLayers.Feature.Vector}
84
* An array of features or a single feature.
87
* {String} Given an array of features, a doc with a gml:featureMembers
88
* element will be returned. Given a single feature, a doc with a
89
* gml:featureMember element will be returned.
91
write: function(features) {
93
if(features instanceof Array) {
94
// GML2 only has abstract feature collections
95
// wfs provides a feature collection from a well-known schema
96
name = "wfs:FeatureCollection";
98
name = "gml:featureMember";
100
var root = this.writeNode(name, features);
102
root, this.namespaces["xsi"],
103
"xsi:schemaLocation", this.schemaLocation
106
return OpenLayers.Format.XML.prototype.write.apply(this, [root]);
111
* As a compliment to the readers property, this structure contains public
112
* writing functions grouped by namespace alias and named like the
113
* node names they produce.
116
"gml": OpenLayers.Util.applyDefaults({
117
"Point": function(geometry) {
118
var node = this.createElementNSPlus("gml:Point");
119
this.writeNode("coordinates", [geometry], node);
122
"coordinates": function(points) {
123
var numPoints = points.length;
124
var parts = new Array(numPoints);
126
for(var i=0; i<numPoints; ++i) {
129
parts[i] = point.x + "," + point.y;
131
parts[i] = point.y + "," + point.x;
133
if(point.z != undefined) { // allow null or undefined
134
parts[i] += "," + point.z;
137
return this.createElementNSPlus("gml:coordinates", {
139
decimal: ".", cs: ",", ts: " "
141
value: (numPoints == 1) ? parts[0] : parts.join(" ")
144
"LineString": function(geometry) {
145
var node = this.createElementNSPlus("gml:LineString");
146
this.writeNode("coordinates", geometry.components, node);
149
"Polygon": function(geometry) {
150
var node = this.createElementNSPlus("gml:Polygon");
151
this.writeNode("outerBoundaryIs", geometry.components[0], node);
152
for(var i=1; i<geometry.components.length; ++i) {
154
"innerBoundaryIs", geometry.components[i], node
159
"outerBoundaryIs": function(ring) {
160
var node = this.createElementNSPlus("gml:outerBoundaryIs");
161
this.writeNode("LinearRing", ring, node);
164
"innerBoundaryIs": function(ring) {
165
var node = this.createElementNSPlus("gml:innerBoundaryIs");
166
this.writeNode("LinearRing", ring, node);
169
"LinearRing": function(ring) {
170
var node = this.createElementNSPlus("gml:LinearRing");
171
this.writeNode("coordinates", ring.components, node);
174
"Box": function(bounds) {
175
var node = this.createElementNSPlus("gml:Box");
176
this.writeNode("coordinates", [
177
{x: bounds.left, y: bounds.bottom},
178
{x: bounds.right, y: bounds.top}
180
// srsName attribute is optional for gml:Box
182
node.setAttribute("srsName", this.srsName);
186
}, OpenLayers.Format.GML.Base.prototype.writers["gml"]),
187
"feature": OpenLayers.Format.GML.Base.prototype.writers["feature"],
188
"wfs": OpenLayers.Format.GML.Base.prototype.writers["wfs"]
191
CLASS_NAME: "OpenLayers.Format.GML.v2"