Added versioned GML Parser, on behalf of mr. tschaub. review=ahocevar. (Pullup #1639)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@8007 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
1 parent
44ac8154c7
commit
7a5b401604
11 files changed
+2478
-67
No files matched your search
@@ -52,24 +52,38 @@
|
||||
var in_options = {
|
||||
'internalProjection': map.baseLayer.projection,
|
||||
'externalProjection': new OpenLayers.Projection(OpenLayers.Util.getElement("inproj").value)
|
||||
}
|
||||
};
|
||||
var out_options = {
|
||||
'internalProjection': map.baseLayer.projection,
|
||||
'externalProjection': new OpenLayers.Projection(OpenLayers.Util.getElement("outproj").value)
|
||||
}
|
||||
};
|
||||
var gmlOptions = {
|
||||
featureType: "feature",
|
||||
featureNS: "http://example.com/feature"
|
||||
};
|
||||
var gmlOptionsIn = OpenLayers.Util.extend(
|
||||
OpenLayers.Util.extend({}, gmlOptions),
|
||||
in_options
|
||||
);
|
||||
var gmlOptionsOut = OpenLayers.Util.extend(
|
||||
OpenLayers.Util.extend({}, gmlOptions),
|
||||
out_options
|
||||
);
|
||||
formats = {
|
||||
'in': {
|
||||
wkt: new OpenLayers.Format.WKT(in_options),
|
||||
geojson: new OpenLayers.Format.GeoJSON(in_options),
|
||||
georss: new OpenLayers.Format.GeoRSS(in_options),
|
||||
gml: new OpenLayers.Format.GML(in_options),
|
||||
gml2: new OpenLayers.Format.GML.v2(gmlOptionsIn),
|
||||
gml3: new OpenLayers.Format.GML.v3(gmlOptionsIn),
|
||||
kml: new OpenLayers.Format.KML(in_options)
|
||||
},
|
||||
'out': {
|
||||
wkt: new OpenLayers.Format.WKT(out_options),
|
||||
geojson: new OpenLayers.Format.GeoJSON(out_options),
|
||||
georss: new OpenLayers.Format.GeoRSS(out_options),
|
||||
gml: new OpenLayers.Format.GML(out_options),
|
||||
gml2: new OpenLayers.Format.GML.v2(gmlOptionsOut),
|
||||
gml3: new OpenLayers.Format.GML.v3(gmlOptionsOut),
|
||||
kml: new OpenLayers.Format.KML(out_options)
|
||||
}
|
||||
};
|
||||
@@ -169,7 +183,8 @@
|
||||
<option value="geojson" selected="selected">GeoJSON</option>
|
||||
<option value="kml">KML</option>
|
||||
<option value="georss">GeoRSS</option>
|
||||
<option value="gml">GML</option>
|
||||
<option value="gml2">GML (v2)</option>
|
||||
<option value="gml3">GML (v3)</option>
|
||||
<option value="wkt">Well-Known Text (WKT)</option>
|
||||
</select>
|
||||
|
||||
|
||||
@@ -206,6 +206,9 @@
|
||||
"OpenLayers/Format.js",
|
||||
"OpenLayers/Format/XML.js",
|
||||
"OpenLayers/Format/GML.js",
|
||||
"OpenLayers/Format/GML/Base.js",
|
||||
"OpenLayers/Format/GML/v2.js",
|
||||
"OpenLayers/Format/GML/v3.js",
|
||||
"OpenLayers/Format/KML.js",
|
||||
"OpenLayers/Format/GeoRSS.js",
|
||||
"OpenLayers/Format/WFS.js",
|
||||
|
||||
@@ -0,0 +1,525 @@
|
||||
/* 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/XMl.js
|
||||
*/
|
||||
|
||||
/**
|
||||
* Eventually, this will require the OpenLayers.Format.GML. For now, since
|
||||
* this parser can be included in a lib without the old GML parser, we
|
||||
* declare the namespace if it doesn't exist.
|
||||
*/
|
||||
if(!OpenLayers.Format.GML) {
|
||||
OpenLayers.Format.GML = {};
|
||||
}
|
||||
|
||||
/**
|
||||
* Class: OpenLayers.Format.GML.Base
|
||||
* Superclass for GML parsers.
|
||||
*
|
||||
* Inherits from:
|
||||
* - <OpenLayers.Format.XML>
|
||||
*/
|
||||
OpenLayers.Format.GML.Base = OpenLayers.Class(OpenLayers.Format.XML, {
|
||||
|
||||
/**
|
||||
* Property: namespaces
|
||||
* {Object} Mapping of namespace aliases to namespace URIs.
|
||||
*/
|
||||
namespaces: {
|
||||
gml: "http://www.opengis.net/gml",
|
||||
xlink: "http://www.w3.org/1999/xlink",
|
||||
xsi: "http://www.w3.org/2001/XMLSchema-instance",
|
||||
wfs: "http://www.opengis.net/wfs" // this is a convenience for reading wfs:FeatureCollection
|
||||
},
|
||||
|
||||
/**
|
||||
* Property: defaultPrefix
|
||||
*/
|
||||
defaultPrefix: "gml",
|
||||
|
||||
/**
|
||||
* Property: schemaLocation
|
||||
* {String} Schema location for a particular minor version.
|
||||
*/
|
||||
schemaLocation: null,
|
||||
|
||||
/**
|
||||
* APIProperty: featureType
|
||||
* {String} The local (without prefix) feature typeName.
|
||||
*/
|
||||
featureType: null,
|
||||
|
||||
/**
|
||||
* APIProperty: featureNS
|
||||
* {String} The feature namespace. Must be set in the options at
|
||||
* construction.
|
||||
*/
|
||||
featureNS: null,
|
||||
|
||||
/**
|
||||
* APIProperty: geometry
|
||||
* {String} Name of geometry element. Defaults to "geometry".
|
||||
*/
|
||||
geometryName: "geometry",
|
||||
|
||||
/**
|
||||
* APIProperty: extractAttributes
|
||||
* {Boolean} Extract attributes from GML. Default is true.
|
||||
*/
|
||||
extractAttributes: true,
|
||||
|
||||
/**
|
||||
* APIProperty: srsName
|
||||
* {String} URI for spatial reference system. This is optional for
|
||||
* single part geometries and mandatory for collections and multis.
|
||||
* If set, the srsName attribute will be written for all geometries.
|
||||
* Default is null.
|
||||
*/
|
||||
srsName: null,
|
||||
|
||||
/**
|
||||
* APIProperty: xy
|
||||
* {Boolean} Order of the GML coordinate true:(x,y) or false:(y,x)
|
||||
* Changing is not recommended, a new Format should be instantiated.
|
||||
*/
|
||||
xy: true,
|
||||
|
||||
/**
|
||||
* Property: regExes
|
||||
* Compiled regular expressions for manipulating strings.
|
||||
*/
|
||||
regExes: {
|
||||
trimSpace: (/^\s*|\s*$/g),
|
||||
removeSpace: (/\s*/g),
|
||||
splitSpace: (/\s+/),
|
||||
trimComma: (/\s*,\s*/g)
|
||||
},
|
||||
|
||||
/**
|
||||
* Constructor: OpenLayers.Format.GML.Base
|
||||
* Instances of this class are not created directly. Use the
|
||||
* <OpenLayers.Format.GML.v2> or <OpenLayers.Format.GML.v3> constructor
|
||||
* instead.
|
||||
*
|
||||
* 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.XML.prototype.initialize.apply(this, [options]);
|
||||
this.setNamespace("feature", options.featureNS);
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: read
|
||||
*
|
||||
* Parameters:
|
||||
* data - {DOMElement} A gml:featureMember element, a gml:featureMembers
|
||||
* element, or an element containing either of the above at any level.
|
||||
*
|
||||
* Returns:
|
||||
* {Array(<OpenLayers.Feature.Vector>)} An array of features.
|
||||
*/
|
||||
read: function(data) {
|
||||
if(typeof data == "string") {
|
||||
data = OpenLayers.Format.XML.prototype.read.apply(this, [data]);
|
||||
}
|
||||
if(data && data.nodeType == 9) {
|
||||
data = data.documentElement;
|
||||
}
|
||||
var features = [];
|
||||
this.readNode(data, {features: features});
|
||||
if(features.length == 0) {
|
||||
// look for gml:featureMember elements
|
||||
var elements = this.getElementsByTagNameNS(
|
||||
data, this.namespaces.gml, "featureMember"
|
||||
);
|
||||
if(elements.length) {
|
||||
for(var i=0, len=elements.length; i<len; ++i) {
|
||||
this.readNode(elements[i], {features: features});
|
||||
}
|
||||
} else {
|
||||
// look for gml:featureMembers elements (this is v3, but does no harm here)
|
||||
var elements = this.getElementsByTagNameNS(
|
||||
data, this.namespaces.gml, "featureMembers"
|
||||
);
|
||||
if(elements.length) {
|
||||
// there can be only one
|
||||
this.readNode(elements[0], {features: features});
|
||||
}
|
||||
}
|
||||
}
|
||||
return features;
|
||||
},
|
||||
|
||||
/**
|
||||
* 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": {
|
||||
"featureMember": function(node, obj) {
|
||||
this.readChildNodes(node, obj);
|
||||
},
|
||||
"featureMembers": function(node, obj) {
|
||||
this.readChildNodes(node, obj);
|
||||
},
|
||||
"Point": function(node, container) {
|
||||
var obj = {points: []};
|
||||
this.readChildNodes(node, obj);
|
||||
if(!container.components) {
|
||||
container.components = [];
|
||||
}
|
||||
container.components.push(obj.points[0]);
|
||||
},
|
||||
"coordinates": function(node, obj) {
|
||||
var str = this.concatChildValues(node).replace(
|
||||
this.regExes.trimSpace, ""
|
||||
);
|
||||
str = str.replace(this.regExes.trimComma, ",");
|
||||
var pointList = str.split(this.regExes.splitSpace);
|
||||
var coords;
|
||||
var numPoints = pointList.length;
|
||||
var points = new Array(numPoints);
|
||||
for(var i=0; i<numPoints; ++i) {
|
||||
coords = pointList[i].split(",");
|
||||
if (this.xy) {
|
||||
points[i] = new OpenLayers.Geometry.Point(
|
||||
coords[0], coords[1], coords[2]
|
||||
);
|
||||
} else {
|
||||
points[i] = new OpenLayers.Geometry.Point(
|
||||
coords[1], coords[0], coords[2]
|
||||
);
|
||||
}
|
||||
}
|
||||
obj.points = points;
|
||||
},
|
||||
"coord": function(node, obj) {
|
||||
var coord = {};
|
||||
this.readChildNodes(node, coord);
|
||||
if(!obj.points) {
|
||||
obj.points = [];
|
||||
}
|
||||
obj.points.push(new OpenLayers.Geometry.Point(
|
||||
coord.x, coord.y, coord.z
|
||||
));
|
||||
},
|
||||
"X": function(node, coord) {
|
||||
coord.x = this.getChildValue(node);
|
||||
},
|
||||
"Y": function(node, coord) {
|
||||
coord.y = this.getChildValue(node);
|
||||
},
|
||||
"Z": function(node, coord) {
|
||||
coord.z = this.getChildValue(node);
|
||||
},
|
||||
"MultiPoint": function(node, container) {
|
||||
var obj = {components: []};
|
||||
this.readChildNodes(node, obj);
|
||||
container.components = [
|
||||
new OpenLayers.Geometry.MultiPoint(obj.components)
|
||||
];
|
||||
},
|
||||
"pointMember": function(node, obj) {
|
||||
this.readChildNodes(node, obj);
|
||||
},
|
||||
"LineString": function(node, container) {
|
||||
var obj = {};
|
||||
this.readChildNodes(node, obj);
|
||||
if(!container.components) {
|
||||
container.components = [];
|
||||
}
|
||||
container.components.push(
|
||||
new OpenLayers.Geometry.LineString(obj.points)
|
||||
);
|
||||
},
|
||||
"MultiLineString": function(node, container) {
|
||||
var obj = {components: []};
|
||||
this.readChildNodes(node, obj);
|
||||
container.components = [
|
||||
new OpenLayers.Geometry.MultiLineString(obj.components)
|
||||
];
|
||||
},
|
||||
"lineStringMember": function(node, obj) {
|
||||
this.readChildNodes(node, obj);
|
||||
},
|
||||
"Polygon": function(node, container) {
|
||||
var obj = {outer: null, inner: []};
|
||||
this.readChildNodes(node, obj);
|
||||
obj.inner.unshift(obj.outer);
|
||||
if(!container.components) {
|
||||
container.components = [];
|
||||
}
|
||||
container.components.push(
|
||||
new OpenLayers.Geometry.Polygon(obj.inner)
|
||||
);
|
||||
},
|
||||
"LinearRing": function(node, obj) {
|
||||
var container = {};
|
||||
this.readChildNodes(node, container);
|
||||
obj.components = [new OpenLayers.Geometry.LinearRing(
|
||||
container.points
|
||||
)];
|
||||
},
|
||||
"MultiPolygon": function(node, container) {
|
||||
var obj = {components: []};
|
||||
this.readChildNodes(node, obj);
|
||||
container.components = [
|
||||
new OpenLayers.Geometry.MultiPolygon(obj.components)
|
||||
];
|
||||
},
|
||||
"polygonMember": function(node, obj) {
|
||||
this.readChildNodes(node, obj);
|
||||
},
|
||||
"GeometryCollection": function(node, container) {
|
||||
var obj = {components: []};
|
||||
this.readChildNodes(node, obj);
|
||||
container.components = [
|
||||
new OpenLayers.Geometry.Collection(obj.components)
|
||||
];
|
||||
},
|
||||
"geometryMember": function(node, obj) {
|
||||
this.readChildNodes(node, obj);
|
||||
}
|
||||
},
|
||||
"feature": {
|
||||
"*": function(node, obj) {
|
||||
// The node can either be named like the featureType, or it
|
||||
// can be a child of the feature:featureType. Children can be
|
||||
// geometry or attributes.
|
||||
var name;
|
||||
var local = node.localName || node.nodeName.split(":").pop();
|
||||
if(local == this.featureType) {
|
||||
name = "_typeName";
|
||||
} else {
|
||||
// Assume attribute elements have one child node and that the child
|
||||
// is a text node. Otherwise assume it is a geometry node.
|
||||
if(node.childNodes.length == 1 && node.firstChild.nodeType == 3) {
|
||||
if(this.extractAttributes) {
|
||||
name = "_attribute";
|
||||
}
|
||||
} else {
|
||||
name = "_geometry";
|
||||
}
|
||||
}
|
||||
if(name) {
|
||||
this.readers.feature[name].apply(this, [node, obj]);
|
||||
}
|
||||
},
|
||||
"_typeName": function(node, obj) {
|
||||
var container = {components: [], attributes: {}};
|
||||
this.readChildNodes(node, container);
|
||||
var feature = new OpenLayers.Feature.Vector(
|
||||
container.components[0], container.attributes
|
||||
);
|
||||
var fid = node.getAttribute("fid") ||
|
||||
this.getAttributeNS(node, this.namespaces["gml"], "id");
|
||||
if(fid) {
|
||||
feature.fid = fid;
|
||||
}
|
||||
if(this.internalProjection && this.externalProjection &&
|
||||
feature.geometry) {
|
||||
feature.geometry.transform(
|
||||
this.externalProjection, this.internalProjection
|
||||
);
|
||||
}
|
||||
obj.features.push(feature);
|
||||
},
|
||||
"_geometry": function(node, obj) {
|
||||
this.readChildNodes(node, obj);
|
||||
},
|
||||
"_attribute": function(node, obj) {
|
||||
var local = node.localName || node.nodeName.split(":").pop();
|
||||
var value = this.getChildValue(node);
|
||||
obj.attributes[local] = value;
|
||||
}
|
||||
},
|
||||
"wfs": {
|
||||
"FeatureCollection": function(node, obj) {
|
||||
this.readChildNodes(node, obj);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: write
|
||||
*
|
||||
* Parameters:
|
||||
* features - {Array(<OpenLayers.Feature.Vector>) | 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": {
|
||||
"featureMember": function(feature) {
|
||||
var node = this.createElementNSPlus("gml:featureMember");
|
||||
this.writeNode("feature:_typeName", feature, node);
|
||||
return node;
|
||||
},
|
||||
"MultiPoint": function(geometry) {
|
||||
var node = this.createElementNSPlus("gml:MultiPoint");
|
||||
for(var i=0; i<geometry.components.length; ++i) {
|
||||
this.writeNode("pointMember", geometry.components[i], node);
|
||||
}
|
||||
return node;
|
||||
},
|
||||
"pointMember": function(geometry) {
|
||||
var node = this.createElementNSPlus("gml:pointMember");
|
||||
this.writeNode("Point", geometry, node);
|
||||
return node;
|
||||
},
|
||||
"MultiLineString": function(geometry) {
|
||||
var node = this.createElementNSPlus("gml:MultiLineString");
|
||||
for(var i=0; i<geometry.components.length; ++i) {
|
||||
this.writeNode("lineStringMember", geometry.components[i], node);
|
||||
}
|
||||
return node;
|
||||
},
|
||||
"lineStringMember": function(geometry) {
|
||||
var node = this.createElementNSPlus("gml:lineStringMember");
|
||||
this.writeNode("LineString", geometry, node);
|
||||
return node;
|
||||
},
|
||||
"MultiPolygon": function(geometry) {
|
||||
var node = this.createElementNSPlus("gml:MultiPolygon");
|
||||
for(var i=0; i<geometry.components.length; ++i) {
|
||||
this.writeNode(
|
||||
"polygonMember", geometry.components[i], node
|
||||
);
|
||||
}
|
||||
return node;
|
||||
},
|
||||
"polygonMember": function(geometry) {
|
||||
var node = this.createElementNSPlus("gml:polygonMember");
|
||||
this.writeNode("Polygon", geometry, node);
|
||||
return node;
|
||||
},
|
||||
"GeometryCollection": function(geometry) {
|
||||
var node = this.createElementNSPlus("gml:GeometryCollection");
|
||||
for(var i=0, len=geometry.components.length; i<len; ++i) {
|
||||
this.writeNode("geometryMember", geometry.components[i], node);
|
||||
}
|
||||
return node;
|
||||
},
|
||||
"geometryMember": function(geometry) {
|
||||
var node = this.createElementNSPlus("gml:geometryMember");
|
||||
var child = this.writeNode("feature:_geometry", geometry);
|
||||
node.appendChild(child.firstChild);
|
||||
return node;
|
||||
}
|
||||
},
|
||||
"feature": {
|
||||
"_typeName": function(feature) {
|
||||
var node = this.createElementNSPlus("feature:" + this.featureType, {
|
||||
attributes: {fid: feature.fid}
|
||||
});
|
||||
if(feature.geometry) {
|
||||
this.writeNode("feature:_geometry", feature.geometry, node);
|
||||
}
|
||||
for(var name in feature.attributes) {
|
||||
var value = feature.attributes[name];
|
||||
if(value != null) {
|
||||
this.writeNode(
|
||||
"feature:_attribute",
|
||||
{name: name, value: value}, node
|
||||
)
|
||||
}
|
||||
}
|
||||
return node;
|
||||
},
|
||||
"_geometry": function(geometry) {
|
||||
if(this.externalProjection && this.internalProjection) {
|
||||
geometry = geometry.clone().transform(
|
||||
this.internalProjection, this.externalProjection
|
||||
);
|
||||
}
|
||||
var node = this.createElementNSPlus(
|
||||
"feature:" + this.geometryName
|
||||
);
|
||||
var type = this.geometryTypes[geometry.CLASS_NAME];
|
||||
var child = this.writeNode("gml:" + type, geometry, node);
|
||||
if(this.srsName) {
|
||||
child.setAttribute("srsName", this.srsName);
|
||||
}
|
||||
return node;
|
||||
},
|
||||
"_attribute": function(obj) {
|
||||
return this.createElementNSPlus("feature:" + obj.name, {
|
||||
value: obj.value
|
||||
});
|
||||
}
|
||||
},
|
||||
"wfs": {
|
||||
"FeatureCollection": function(features) {
|
||||
/**
|
||||
* This is only here because GML2 only describes abstract
|
||||
* feature collections. Typically, you would not be using
|
||||
* the GML format to write wfs elements. This just provides
|
||||
* some way to write out lists of features. GML3 defines the
|
||||
* featureMembers element, so that is used by default instead.
|
||||
*/
|
||||
var node = this.createElementNSPlus("wfs:FeatureCollection");
|
||||
for(var i=0, len=features.length; i<len; ++i) {
|
||||
this.writeNode("gml:featureMember", features[i], node);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Property: geometryTypes
|
||||
* {Object} Maps OpenLayers geometry class names to GML element names.
|
||||
*/
|
||||
geometryTypes: {
|
||||
"OpenLayers.Geometry.Point": "Point",
|
||||
"OpenLayers.Geometry.MultiPoint": "MultiPoint",
|
||||
"OpenLayers.Geometry.LineString": "LineString",
|
||||
"OpenLayers.Geometry.MultiLineString": "MultiLineString",
|
||||
"OpenLayers.Geometry.Polygon": "Polygon",
|
||||
"OpenLayers.Geometry.MultiPolygon": "MultiPolygon",
|
||||
"OpenLayers.Geometry.Collection": "GeometryCollection"
|
||||
},
|
||||
|
||||
CLASS_NAME: "OpenLayers.Format.GML.Base"
|
||||
|
||||
});
|
||||
@@ -0,0 +1,192 @@
|
||||
/* 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.v2
|
||||
* Parses GML version 2.
|
||||
*
|
||||
* Inherits from:
|
||||
* - <OpenLayers.Format.GML.Base>
|
||||
*/
|
||||
OpenLayers.Format.GML.v2 = OpenLayers.Class(OpenLayers.Format.GML.Base, {
|
||||
|
||||
/**
|
||||
* Property: schemaLocation
|
||||
* {String} Schema location for a particular minor version.
|
||||
*/
|
||||
schemaLocation: "http://www.opengis.net/gml http://schemas.opengis.net/gml/2.1.2/feature.xsd",
|
||||
|
||||
/**
|
||||
* Constructor: OpenLayers.Format.GML.v2
|
||||
* Create a parser for GML v2.
|
||||
*
|
||||
* 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({
|
||||
"outerBoundaryIs": function(node, container) {
|
||||
var obj = {};
|
||||
this.readChildNodes(node, obj);
|
||||
container.outer = obj.components[0];
|
||||
},
|
||||
"innerBoundaryIs": function(node, container) {
|
||||
var obj = {};
|
||||
this.readChildNodes(node, obj);
|
||||
container.inner.push(obj.components[0]);
|
||||
},
|
||||
"Box": function(node, container) {
|
||||
var obj = {};
|
||||
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)
|
||||
);
|
||||
}
|
||||
}, 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>) | 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) {
|
||||
// GML2 only has abstract feature collections
|
||||
// wfs provides a feature collection from a well-known schema
|
||||
name = "wfs:FeatureCollection";
|
||||
} else {
|
||||
name = "gml:featureMember";
|
||||
}
|
||||
var root = this.writeNode(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({
|
||||
"Point": function(geometry) {
|
||||
var node = this.createElementNSPlus("gml:Point");
|
||||
this.writeNode("coordinates", [geometry], node);
|
||||
return node;
|
||||
},
|
||||
"coordinates": function(points) {
|
||||
var numPoints = points.length;
|
||||
var parts = new Array(numPoints);
|
||||
var point;
|
||||
for(var i=0; i<numPoints; ++i) {
|
||||
point = points[i];
|
||||
if(this.xy) {
|
||||
parts[i] = point.x + "," + point.y;
|
||||
} else {
|
||||
parts[i] = point.y + "," + point.x;
|
||||
}
|
||||
if(point.z != undefined) { // allow null or undefined
|
||||
parts[i] += "," + point.z;
|
||||
}
|
||||
}
|
||||
return this.createElementNSPlus("gml:coordinates", {
|
||||
attributes: {
|
||||
decimal: ".", cs: ",", ts: " "
|
||||
},
|
||||
value: (numPoints == 1) ? parts[0] : parts.join(" ")
|
||||
});
|
||||
},
|
||||
"LineString": function(geometry) {
|
||||
var node = this.createElementNSPlus("gml:LineString");
|
||||
this.writeNode("coordinates", geometry.components, node);
|
||||
return node;
|
||||
},
|
||||
"Polygon": function(geometry) {
|
||||
var node = this.createElementNSPlus("gml:Polygon");
|
||||
this.writeNode("outerBoundaryIs", geometry.components[0], node);
|
||||
for(var i=1; i<geometry.components.length; ++i) {
|
||||
this.writeNode(
|
||||
"innerBoundaryIs", geometry.components[i], node
|
||||
);
|
||||
}
|
||||
return node;
|
||||
},
|
||||
"outerBoundaryIs": function(ring) {
|
||||
var node = this.createElementNSPlus("gml:outerBoundaryIs");
|
||||
this.writeNode("LinearRing", ring, node);
|
||||
return node;
|
||||
},
|
||||
"innerBoundaryIs": function(ring) {
|
||||
var node = this.createElementNSPlus("gml:innerBoundaryIs");
|
||||
this.writeNode("LinearRing", ring, node);
|
||||
return node;
|
||||
},
|
||||
"LinearRing": function(ring) {
|
||||
var node = this.createElementNSPlus("gml:LinearRing");
|
||||
this.writeNode("coordinates", ring.components, node);
|
||||
return node;
|
||||
},
|
||||
"Box": function(bounds) {
|
||||
var node = this.createElementNSPlus("gml:Box");
|
||||
this.writeNode("coordinates", [
|
||||
{x: bounds.left, y: bounds.bottom},
|
||||
{x: bounds.right, y: bounds.top}
|
||||
], node);
|
||||
// srsName attribute is optional for gml:Box
|
||||
if(this.srsName) {
|
||||
node.setAttribute("srsName", this.srsName);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
}, OpenLayers.Format.GML.Base.prototype.writers["gml"]),
|
||||
"feature": OpenLayers.Format.GML.Base.prototype.writers["feature"],
|
||||
"wfs": OpenLayers.Format.GML.Base.prototype.writers["wfs"]
|
||||
},
|
||||
|
||||
CLASS_NAME: "OpenLayers.Format.GML.v2"
|
||||
|
||||
});
|
||||
@@ -0,0 +1,287 @@
|
||||
/* 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.Base>
|
||||
*/
|
||||
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<len; i += dim) {
|
||||
x = coords[i];
|
||||
y = coords[i+1];
|
||||
z = (dim == 2) ? undefined : coords[i+2];
|
||||
if (this.xy) {
|
||||
points[i/dim] = new OpenLayers.Geometry.Point(x, y, z);
|
||||
} else {
|
||||
points[i/dim] = new OpenLayers.Geometry.Point(y, x, z);
|
||||
}
|
||||
}
|
||||
obj.points = points;
|
||||
},
|
||||
"exterior": function(node, container) {
|
||||
var obj = {};
|
||||
this.readChildNodes(node, obj);
|
||||
container.outer = obj.components[0];
|
||||
},
|
||||
"interior": function(node, container) {
|
||||
var obj = {};
|
||||
this.readChildNodes(node, obj);
|
||||
container.inner.push(obj.components[0]);
|
||||
},
|
||||
"MultiSurface": function(node, container) {
|
||||
var obj = {components: []};
|
||||
this.readChildNodes(node, obj);
|
||||
if(obj.components.length > 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>) | 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<len; ++i) {
|
||||
this.writeNode("feature:_typeName", features[i], node);
|
||||
}
|
||||
return node;
|
||||
},
|
||||
"Point": function(geometry) {
|
||||
var node = this.createElementNSPlus("gml:Point");
|
||||
this.writeNode("pos", geometry, node);
|
||||
return node;
|
||||
},
|
||||
"pos": function(point) {
|
||||
// only 2d for simple features profile
|
||||
var pos = (this.xy) ?
|
||||
(point.x + " " + point.y) : (point.y + " " + point.x);
|
||||
return this.createElementNSPlus("gml:pos", {
|
||||
value: pos
|
||||
});
|
||||
},
|
||||
"LineString": function(geometry) {
|
||||
var node = this.createElementNSPlus("gml:LineString");
|
||||
this.writeNode("posList", geometry.components, node);
|
||||
return node;
|
||||
},
|
||||
"posList": function(points) {
|
||||
// only 2d for simple features profile
|
||||
var len = points.length;
|
||||
var parts = new Array(len);
|
||||
var point;
|
||||
for(var i=0; i<len; ++i) {
|
||||
point = points[i];
|
||||
if(this.xy) {
|
||||
parts[i] = point.x + " " + point.y;
|
||||
} else {
|
||||
parts[i] = point.y + " " + point.x;
|
||||
}
|
||||
}
|
||||
return this.createElementNSPlus("gml:posList", {
|
||||
value: parts.join(" ")
|
||||
});
|
||||
},
|
||||
"Polygon": function(geometry) {
|
||||
var node = this.createElementNSPlus("gml:Polygon");
|
||||
this.writeNode("exterior", geometry.components[0], node);
|
||||
for(var i=1, len=geometry.components.length; i<len; ++i) {
|
||||
this.writeNode(
|
||||
"interior", geometry.components[i], node
|
||||
);
|
||||
}
|
||||
return node;
|
||||
},
|
||||
"exterior": function(ring) {
|
||||
var node = this.createElementNSPlus("gml:exterior");
|
||||
this.writeNode("LinearRing", ring, node);
|
||||
return node;
|
||||
},
|
||||
"interior": function(ring) {
|
||||
var node = this.createElementNSPlus("gml:interior");
|
||||
this.writeNode("LinearRing", ring, node);
|
||||
return node;
|
||||
},
|
||||
"LinearRing": function(ring) {
|
||||
var node = this.createElementNSPlus("gml:LinearRing");
|
||||
this.writeNode("posList", ring.components, node);
|
||||
return node;
|
||||
},
|
||||
"Envelope": function(bounds) {
|
||||
var node = this.createElementNSPlus("gml:Envelope");
|
||||
this.writeNode("lowerCorner", bounds, node);
|
||||
this.writeNode("upperCorner", bounds, node);
|
||||
// srsName attribute is required for gml:Envelope
|
||||
if(this.srsName) {
|
||||
node.setAttribute("srsName", this.srsName);
|
||||
}
|
||||
return node;
|
||||
},
|
||||
"lowerCorner": function(bounds) {
|
||||
var node = this.createElementNSPlus("gml:lowerCorner");
|
||||
this.writeNode("pos", {x: bounds.left, y: bounds.bottom}, node);
|
||||
return node;
|
||||
},
|
||||
"upperCorner": function(bounds) {
|
||||
var node = this.createElementNSPlus("gml:upperCorner");
|
||||
this.writeNode("pos", {x: bounds.right, y: bounds.top}, node);
|
||||
return node;
|
||||
}
|
||||
}, OpenLayers.Format.GML.Base.prototype.writers["gml"]),
|
||||
"feature": OpenLayers.Format.GML.Base.prototype.writers["feature"],
|
||||
"wfs": OpenLayers.Format.GML.Base.prototype.writers["wfs"]
|
||||
},
|
||||
|
||||
CLASS_NAME: "OpenLayers.Format.GML.v3"
|
||||
|
||||
});
|
||||
@@ -22,15 +22,24 @@ OpenLayers.Format.XML = OpenLayers.Class(OpenLayers.Format, {
|
||||
/**
|
||||
* Property: namespaces
|
||||
* {Object} Mapping of namespace aliases to namespace URIs. Properties
|
||||
* of this object should not be set individually.
|
||||
* of this object should not be set individually. Read-only. All
|
||||
* XML subclasses should have their own namespaces object. Use
|
||||
* <setNamespace> to add or set a namespace alias after construction.
|
||||
*/
|
||||
namespaces: {},
|
||||
namespaces: null,
|
||||
|
||||
/**
|
||||
* Property: defaultNamespace
|
||||
* Property: namespaceAlias
|
||||
* {Object} Mapping of namespace URI to namespace alias. This object
|
||||
* is read-only. Use <setNamespace> to add or set a namespace alias.
|
||||
*/
|
||||
namespaceAlias: null,
|
||||
|
||||
/**
|
||||
* Property: defaultPrefix
|
||||
* {String} The default namespace alias for creating element nodes.
|
||||
*/
|
||||
defaultNamespace: null,
|
||||
defaultPrefix: null,
|
||||
|
||||
/**
|
||||
* Property: readers
|
||||
@@ -75,6 +84,12 @@ OpenLayers.Format.XML = OpenLayers.Class(OpenLayers.Format, {
|
||||
this.xmldom = new ActiveXObject("Microsoft.XMLDOM");
|
||||
}
|
||||
OpenLayers.Format.prototype.initialize.apply(this, [options]);
|
||||
// clone the namespace object and set all namespace aliases
|
||||
this.namespaces = OpenLayers.Util.extend({}, this.namespaces);
|
||||
this.namespaceAlias = {};
|
||||
for(var alias in this.namespaces) {
|
||||
this.namespaceAlias[this.namespaces[alias]] = alias;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -85,6 +100,19 @@ OpenLayers.Format.XML = OpenLayers.Class(OpenLayers.Format, {
|
||||
this.xmldom = null;
|
||||
OpenLayers.Format.prototype.destroy.apply(this, arguments);
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: setNamespace
|
||||
* Set a namespace alias and URI for the format.
|
||||
*
|
||||
* Parameters:
|
||||
* alias - {String} The namespace alias (prefix).
|
||||
* uri - {String} The namespace URI.
|
||||
*/
|
||||
setNamespace: function(alias, uri) {
|
||||
this.namespaces[alias] = uri;
|
||||
this.namespaceAlias[uri] = alias;
|
||||
},
|
||||
|
||||
/**
|
||||
* APIMethod: read
|
||||
@@ -329,11 +357,12 @@ OpenLayers.Format.XML = OpenLayers.Class(OpenLayers.Format, {
|
||||
* {String} The value of the first child of the given node.
|
||||
*/
|
||||
getChildValue: function(node, def) {
|
||||
var value;
|
||||
if (node && node.firstChild && node.firstChild.nodeValue) {
|
||||
value = node.firstChild.nodeValue;
|
||||
} else {
|
||||
value = (def != undefined) ? def : "";
|
||||
var value = def || "";
|
||||
if(node) {
|
||||
var child = node.firstChild;
|
||||
if(child) {
|
||||
value = child.nodeValue || value;
|
||||
}
|
||||
}
|
||||
return value;
|
||||
},
|
||||
@@ -424,29 +453,6 @@ OpenLayers.Format.XML = OpenLayers.Class(OpenLayers.Format, {
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: getNamespacePrefix
|
||||
* Get the namespace prefix for a given uri from the <namespaces> object.
|
||||
*
|
||||
* Returns:
|
||||
* {String} A namespace prefix or null if none found.
|
||||
*/
|
||||
getNamespacePrefix: function(uri) {
|
||||
var prefix = null;
|
||||
if(uri == null) {
|
||||
prefix = this.defaultPrefix;
|
||||
} else {
|
||||
var prefix = null;
|
||||
for(var p in this.namespaces) {
|
||||
if(this.namespaces[p] == uri) {
|
||||
prefix = p;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return prefix;
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: createElementNSPlus
|
||||
* Shorthand for creating namespaced elements with optional attributes and
|
||||
@@ -534,10 +540,9 @@ OpenLayers.Format.XML = OpenLayers.Class(OpenLayers.Format, {
|
||||
if(!obj) {
|
||||
obj = {};
|
||||
}
|
||||
var prefix = this.getNamespacePrefix(node.namespaceURI);
|
||||
var local = node.nodeName.split(":").pop();
|
||||
var group = this.readers[prefix];
|
||||
var group = this.readers[this.namespaceAlias[node.namespaceURI]];
|
||||
if(group) {
|
||||
var local = node.localName || node.nodeName.split(":").pop();
|
||||
var reader = group[local] || group["*"];
|
||||
if(reader) {
|
||||
reader.apply(this, [node, obj]);
|
||||
@@ -564,7 +569,7 @@ OpenLayers.Format.XML = OpenLayers.Class(OpenLayers.Format, {
|
||||
}
|
||||
var children = node.childNodes;
|
||||
var child;
|
||||
for(var i=0; i<children.length; ++i) {
|
||||
for(var i=0, len=children.length; i<len; ++i) {
|
||||
child = children[i];
|
||||
if(child.nodeType == 1) {
|
||||
this.readNode(child, obj);
|
||||
@@ -601,7 +606,7 @@ OpenLayers.Format.XML = OpenLayers.Class(OpenLayers.Format, {
|
||||
local = name.substring(split + 1);
|
||||
} else {
|
||||
if(parent) {
|
||||
prefix = this.getNamespacePrefix(parent.namespaceURI);
|
||||
prefix = this.namespaceAlias[parent.namespaceURI];
|
||||
} else {
|
||||
prefix = this.defaultPrefix;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,222 @@
|
||||
var xml = new OpenLayers.Format.XML();
|
||||
function readXML(file) {
|
||||
return xml.read(document.getElementById(file).firstChild.nodeValue);
|
||||
}
|
||||
|
||||
var cases = {
|
||||
|
||||
"v2/point-coord.xml": new OpenLayers.Geometry.Point(1, 2),
|
||||
|
||||
"v2/point-coordinates.xml": new OpenLayers.Geometry.Point(1, 2),
|
||||
|
||||
"v2/linestring-coord.xml": new OpenLayers.Geometry.LineString([
|
||||
new OpenLayers.Geometry.Point(1, 2),
|
||||
new OpenLayers.Geometry.Point(3, 4)
|
||||
]),
|
||||
|
||||
"v2/linestring-coordinates.xml": new OpenLayers.Geometry.LineString([
|
||||
new OpenLayers.Geometry.Point(1, 2),
|
||||
new OpenLayers.Geometry.Point(3, 4)
|
||||
]),
|
||||
|
||||
"v2/linearring-coord.xml": new OpenLayers.Geometry.LinearRing([
|
||||
new OpenLayers.Geometry.Point(1, 2),
|
||||
new OpenLayers.Geometry.Point(3, 4),
|
||||
new OpenLayers.Geometry.Point(5, 6),
|
||||
new OpenLayers.Geometry.Point(1, 2)
|
||||
]),
|
||||
|
||||
"v2/linearring-coordinates.xml": new OpenLayers.Geometry.LinearRing([
|
||||
new OpenLayers.Geometry.Point(1, 2),
|
||||
new OpenLayers.Geometry.Point(3, 4),
|
||||
new OpenLayers.Geometry.Point(5, 6),
|
||||
new OpenLayers.Geometry.Point(1, 2)
|
||||
]),
|
||||
|
||||
"v2/polygon-coord.xml": new OpenLayers.Geometry.Polygon([
|
||||
new OpenLayers.Geometry.LinearRing([
|
||||
new OpenLayers.Geometry.Point(1, 2),
|
||||
new OpenLayers.Geometry.Point(3, 4),
|
||||
new OpenLayers.Geometry.Point(5, 6),
|
||||
new OpenLayers.Geometry.Point(1, 2)
|
||||
]),
|
||||
new OpenLayers.Geometry.LinearRing([
|
||||
new OpenLayers.Geometry.Point(2, 3),
|
||||
new OpenLayers.Geometry.Point(4, 5),
|
||||
new OpenLayers.Geometry.Point(6, 7),
|
||||
new OpenLayers.Geometry.Point(2, 3)
|
||||
]),
|
||||
new OpenLayers.Geometry.LinearRing([
|
||||
new OpenLayers.Geometry.Point(3, 4),
|
||||
new OpenLayers.Geometry.Point(5, 6),
|
||||
new OpenLayers.Geometry.Point(7, 8),
|
||||
new OpenLayers.Geometry.Point(3, 4)
|
||||
])
|
||||
]),
|
||||
|
||||
"v2/polygon-coordinates.xml": new OpenLayers.Geometry.Polygon([
|
||||
new OpenLayers.Geometry.LinearRing([
|
||||
new OpenLayers.Geometry.Point(1, 2),
|
||||
new OpenLayers.Geometry.Point(3, 4),
|
||||
new OpenLayers.Geometry.Point(5, 6),
|
||||
new OpenLayers.Geometry.Point(1, 2)
|
||||
]),
|
||||
new OpenLayers.Geometry.LinearRing([
|
||||
new OpenLayers.Geometry.Point(2, 3),
|
||||
new OpenLayers.Geometry.Point(4, 5),
|
||||
new OpenLayers.Geometry.Point(6, 7),
|
||||
new OpenLayers.Geometry.Point(2, 3)
|
||||
]),
|
||||
new OpenLayers.Geometry.LinearRing([
|
||||
new OpenLayers.Geometry.Point(3, 4),
|
||||
new OpenLayers.Geometry.Point(5, 6),
|
||||
new OpenLayers.Geometry.Point(7, 8),
|
||||
new OpenLayers.Geometry.Point(3, 4)
|
||||
])
|
||||
]),
|
||||
|
||||
"v2/multipoint-coord.xml": new OpenLayers.Geometry.MultiPoint([
|
||||
new OpenLayers.Geometry.Point(1, 2),
|
||||
new OpenLayers.Geometry.Point(2, 3),
|
||||
new OpenLayers.Geometry.Point(3, 4)
|
||||
]),
|
||||
|
||||
"v2/multipoint-coordinates.xml": new OpenLayers.Geometry.MultiPoint([
|
||||
new OpenLayers.Geometry.Point(1, 2),
|
||||
new OpenLayers.Geometry.Point(2, 3),
|
||||
new OpenLayers.Geometry.Point(3, 4)
|
||||
]),
|
||||
|
||||
"v2/multilinestring-coord.xml": new OpenLayers.Geometry.MultiLineString([
|
||||
new OpenLayers.Geometry.LineString([
|
||||
new OpenLayers.Geometry.Point(1, 2),
|
||||
new OpenLayers.Geometry.Point(2, 3)
|
||||
]),
|
||||
new OpenLayers.Geometry.LineString([
|
||||
new OpenLayers.Geometry.Point(3, 4),
|
||||
new OpenLayers.Geometry.Point(4, 5)
|
||||
])
|
||||
]),
|
||||
|
||||
"v2/multilinestring-coordinates.xml": new OpenLayers.Geometry.MultiLineString([
|
||||
new OpenLayers.Geometry.LineString([
|
||||
new OpenLayers.Geometry.Point(1, 2),
|
||||
new OpenLayers.Geometry.Point(2, 3)
|
||||
]),
|
||||
new OpenLayers.Geometry.LineString([
|
||||
new OpenLayers.Geometry.Point(3, 4),
|
||||
new OpenLayers.Geometry.Point(4, 5)
|
||||
])
|
||||
]),
|
||||
|
||||
"v2/multipolygon-coord.xml": new OpenLayers.Geometry.MultiPolygon([
|
||||
new OpenLayers.Geometry.Polygon([
|
||||
new OpenLayers.Geometry.LinearRing([
|
||||
new OpenLayers.Geometry.Point(1, 2),
|
||||
new OpenLayers.Geometry.Point(3, 4),
|
||||
new OpenLayers.Geometry.Point(5, 6),
|
||||
new OpenLayers.Geometry.Point(1, 2)
|
||||
]),
|
||||
new OpenLayers.Geometry.LinearRing([
|
||||
new OpenLayers.Geometry.Point(2, 3),
|
||||
new OpenLayers.Geometry.Point(4, 5),
|
||||
new OpenLayers.Geometry.Point(6, 7),
|
||||
new OpenLayers.Geometry.Point(2, 3)
|
||||
]),
|
||||
new OpenLayers.Geometry.LinearRing([
|
||||
new OpenLayers.Geometry.Point(3, 4),
|
||||
new OpenLayers.Geometry.Point(5, 6),
|
||||
new OpenLayers.Geometry.Point(7, 8),
|
||||
new OpenLayers.Geometry.Point(3, 4)
|
||||
])
|
||||
]),
|
||||
new OpenLayers.Geometry.Polygon([
|
||||
new OpenLayers.Geometry.LinearRing([
|
||||
new OpenLayers.Geometry.Point(1, 2),
|
||||
new OpenLayers.Geometry.Point(3, 4),
|
||||
new OpenLayers.Geometry.Point(5, 6),
|
||||
new OpenLayers.Geometry.Point(1, 2)
|
||||
])
|
||||
])
|
||||
]),
|
||||
|
||||
"v2/multipolygon-coordinates.xml": new OpenLayers.Geometry.MultiPolygon([
|
||||
new OpenLayers.Geometry.Polygon([
|
||||
new OpenLayers.Geometry.LinearRing([
|
||||
new OpenLayers.Geometry.Point(1, 2),
|
||||
new OpenLayers.Geometry.Point(3, 4),
|
||||
new OpenLayers.Geometry.Point(5, 6),
|
||||
new OpenLayers.Geometry.Point(1, 2)
|
||||
]),
|
||||
new OpenLayers.Geometry.LinearRing([
|
||||
new OpenLayers.Geometry.Point(2, 3),
|
||||
new OpenLayers.Geometry.Point(4, 5),
|
||||
new OpenLayers.Geometry.Point(6, 7),
|
||||
new OpenLayers.Geometry.Point(2, 3)
|
||||
]),
|
||||
new OpenLayers.Geometry.LinearRing([
|
||||
new OpenLayers.Geometry.Point(3, 4),
|
||||
new OpenLayers.Geometry.Point(5, 6),
|
||||
new OpenLayers.Geometry.Point(7, 8),
|
||||
new OpenLayers.Geometry.Point(3, 4)
|
||||
])
|
||||
]),
|
||||
new OpenLayers.Geometry.Polygon([
|
||||
new OpenLayers.Geometry.LinearRing([
|
||||
new OpenLayers.Geometry.Point(1, 2),
|
||||
new OpenLayers.Geometry.Point(3, 4),
|
||||
new OpenLayers.Geometry.Point(5, 6),
|
||||
new OpenLayers.Geometry.Point(1, 2)
|
||||
])
|
||||
])
|
||||
]),
|
||||
|
||||
"v2/geometrycollection-coordinates.xml": new OpenLayers.Geometry.Collection([
|
||||
new OpenLayers.Geometry.Point(1, 2),
|
||||
new OpenLayers.Geometry.LineString([
|
||||
new OpenLayers.Geometry.Point(1, 2),
|
||||
new OpenLayers.Geometry.Point(3, 4)
|
||||
]),
|
||||
new OpenLayers.Geometry.Polygon([
|
||||
new OpenLayers.Geometry.LinearRing([
|
||||
new OpenLayers.Geometry.Point(1, 2),
|
||||
new OpenLayers.Geometry.Point(3, 4),
|
||||
new OpenLayers.Geometry.Point(5, 6),
|
||||
new OpenLayers.Geometry.Point(1, 2)
|
||||
]),
|
||||
new OpenLayers.Geometry.LinearRing([
|
||||
new OpenLayers.Geometry.Point(2, 3),
|
||||
new OpenLayers.Geometry.Point(4, 5),
|
||||
new OpenLayers.Geometry.Point(6, 7),
|
||||
new OpenLayers.Geometry.Point(2, 3)
|
||||
]),
|
||||
new OpenLayers.Geometry.LinearRing([
|
||||
new OpenLayers.Geometry.Point(3, 4),
|
||||
new OpenLayers.Geometry.Point(5, 6),
|
||||
new OpenLayers.Geometry.Point(7, 8),
|
||||
new OpenLayers.Geometry.Point(3, 4)
|
||||
])
|
||||
])
|
||||
]),
|
||||
|
||||
"v2/box-coord.xml": new OpenLayers.Bounds(1, 2, 3, 4),
|
||||
|
||||
"v2/box-coordinates.xml": new OpenLayers.Bounds(1, 2, 3, 4)
|
||||
|
||||
};
|
||||
|
||||
// cases for v3 use the same geometries
|
||||
OpenLayers.Util.extend(cases, {
|
||||
"v3/point.xml": cases["v2/point-coordinates.xml"],
|
||||
"v3/linestring.xml": cases["v2/linestring-coordinates.xml"],
|
||||
"v3/polygon.xml": cases["v2/polygon-coordinates.xml"],
|
||||
"v3/multipoint-singular.xml": cases["v2/multipoint-coordinates.xml"],
|
||||
"v3/multipoint-plural.xml": cases["v2/multipoint-coordinates.xml"],
|
||||
"v3/multilinestring-singular.xml": cases["v2/multilinestring-coordinates.xml"],
|
||||
"v3/multilinestring-plural.xml": cases["v2/multilinestring-coordinates.xml"],
|
||||
"v3/multipolygon-singular.xml": cases["v2/multipolygon-coordinates.xml"],
|
||||
"v3/multipolygon-plural.xml": cases["v2/multipolygon-coordinates.xml"],
|
||||
"v3/multisurface-singular.xml": cases["v2/multipolygon-coordinates.xml"],
|
||||
"v3/multisurface-plural.xml": cases["v2/multipolygon-coordinates.xml"],
|
||||
"v3/envelope.xml": cases["v2/box-coordinates.xml"]
|
||||
});
|
||||
@@ -0,0 +1,605 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<script src="../../../lib/OpenLayers.js"></script>
|
||||
<script src="cases.js"></script>
|
||||
<script type="text/javascript">
|
||||
|
||||
function test_readNode_geometry(t) {
|
||||
var files = [
|
||||
"v2/point-coord.xml", "v2/point-coordinates.xml",
|
||||
"v2/linestring-coord.xml", "v2/linestring-coordinates.xml",
|
||||
"v2/polygon-coord.xml", "v2/polygon-coordinates.xml",
|
||||
"v2/multipoint-coord.xml", "v2/multipoint-coordinates.xml",
|
||||
"v2/multilinestring-coord.xml", "v2/multilinestring-coordinates.xml",
|
||||
"v2/multipolygon-coord.xml", "v2/multipolygon-coordinates.xml",
|
||||
"v2/geometrycollection-coordinates.xml"
|
||||
];
|
||||
|
||||
var len = files.length;
|
||||
t.plan(len);
|
||||
|
||||
var format = new OpenLayers.Format.GML.v2({
|
||||
featureType: "feature",
|
||||
featureNS: "http://example.com/feature"
|
||||
});
|
||||
var file, doc, expect, out;
|
||||
for(var i=0; i<len; ++i) {
|
||||
file = files[i];
|
||||
expect = cases[file];
|
||||
if(expect) {
|
||||
doc = readXML(file);
|
||||
if(doc && doc.documentElement) {
|
||||
out = format.readNode(doc.documentElement);
|
||||
if(out.components && out.components.length == 1) {
|
||||
t.geom_eq(out.components[0], expect, "[" + file + "] geometry read");
|
||||
} else {
|
||||
t.fail("[" + file + "] gml parsing");
|
||||
}
|
||||
} else {
|
||||
t.fail("[" + file + "] xml parsing");
|
||||
}
|
||||
} else {
|
||||
t.fail("[" + file + "] case not found");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function test_readNode_bounds(t) {
|
||||
var files = ["v2/box-coord.xml", "v2/box-coordinates.xml"];
|
||||
|
||||
var len = files.length;
|
||||
t.plan(len);
|
||||
|
||||
var file, doc, expect, got;
|
||||
var format = new OpenLayers.Format.GML.v2({
|
||||
featureType: "feature",
|
||||
featureNS: "http://example.com/feature"
|
||||
});
|
||||
for(var i=0; i<len; ++i) {
|
||||
file = files[i];
|
||||
expect = cases[file];
|
||||
if(expect) {
|
||||
doc = readXML(file);
|
||||
if(doc && doc.documentElement) {
|
||||
out = format.readNode(doc.documentElement);
|
||||
if(out.components && out.components.length == 1) {
|
||||
got = out.components[0];
|
||||
if(got instanceof OpenLayers.Bounds) {
|
||||
t.ok(out.components[0].equals(expect), "[" + file + "] bounds read")
|
||||
} else {
|
||||
t.fail("[" + file + "] expected a bounds, got " + got);
|
||||
}
|
||||
} else {
|
||||
t.fail("[" + file + "] gml parsing");
|
||||
}
|
||||
} else {
|
||||
t.fail("[" + file + "] xml parsing");
|
||||
}
|
||||
} else {
|
||||
t.fail("[" + file + "] case not found");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function test_writeNode_geometry(t) {
|
||||
// we only care to write the 'coordinates' variant of GML 2
|
||||
var files = [
|
||||
"v2/point-coordinates.xml",
|
||||
"v2/linestring-coordinates.xml",
|
||||
"v2/polygon-coordinates.xml",
|
||||
"v2/multipoint-coordinates.xml",
|
||||
"v2/multilinestring-coordinates.xml",
|
||||
"v2/multipolygon-coordinates.xml",
|
||||
"v2/geometrycollection-coordinates.xml"
|
||||
];
|
||||
|
||||
var len = files.length;
|
||||
t.plan(len);
|
||||
|
||||
var format = new OpenLayers.Format.GML.v2({
|
||||
featureType: "feature",
|
||||
featureNS: "http://example.com/feature",
|
||||
srsName: "foo" // GML geometry collections require srsName, we only write if provided
|
||||
});
|
||||
var file, geom, doc, node;
|
||||
for(var i=0; i<len; ++i) {
|
||||
file = files[i];
|
||||
geom = cases[file];
|
||||
if(geom) {
|
||||
doc = readXML(file);
|
||||
if(doc && doc.documentElement) {
|
||||
node = format.writeNode("feature:_geometry", geom);
|
||||
t.xml_eq(node.firstChild, doc.documentElement, "[" + file + "] geometry written");
|
||||
} else {
|
||||
t.fail("[" + file + "] xml parsing");
|
||||
}
|
||||
} else {
|
||||
t.fail("[" + file + "] case not found");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function test_writeNode_bounds(t) {
|
||||
// we only care to write the 'coordinates' variant of GML 2
|
||||
var files = [
|
||||
"v2/box-coordinates.xml"
|
||||
];
|
||||
|
||||
var len = files.length;
|
||||
t.plan(len);
|
||||
|
||||
var format = new OpenLayers.Format.GML.v2({
|
||||
featureType: "feature",
|
||||
featureNS: "http://example.com/feature",
|
||||
srsName: "foo" // GML box does not require srsName, we only write if provided
|
||||
});
|
||||
var file, bounds, doc, node;
|
||||
for(var i=0; i<len; ++i) {
|
||||
file = files[i];
|
||||
bounds = cases[file];
|
||||
if(bounds) {
|
||||
doc = readXML(file);
|
||||
if(doc && doc.documentElement) {
|
||||
node = format.writeNode("gml:Box", bounds);
|
||||
t.xml_eq(node, doc.documentElement, "[" + file + "] bounds written");
|
||||
} else {
|
||||
t.fail("[" + file + "] xml parsing");
|
||||
}
|
||||
} else {
|
||||
t.fail("[" + file + "] case not found");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function test_read(t) {
|
||||
t.plan(8);
|
||||
var doc = readXML("v2/topp-states.xml");
|
||||
var format = new OpenLayers.Format.GML.v2({
|
||||
featureType: "states",
|
||||
featureNS: "http://www.openplans.org/topp",
|
||||
geometryName: "the_geom"
|
||||
});
|
||||
var features = format.read(doc.documentElement);
|
||||
|
||||
t.eq(features.length, 3, "read 3 features");
|
||||
var feature = features[0];
|
||||
t.eq(feature.fid, "states.1", "read fid");
|
||||
t.eq(feature.geometry.CLASS_NAME, "OpenLayers.Geometry.MultiPolygon",
|
||||
"read multipolygon geometry");
|
||||
var attributes = feature.attributes;
|
||||
t.eq(attributes["STATE_NAME"], "Illinois", "read STATE_NAME");
|
||||
t.eq(attributes["STATE_FIPS"], "17", "read STATE_FIPS");
|
||||
t.eq(attributes["SUB_REGION"], "E N Cen", "read SUB_REGION");
|
||||
t.eq(attributes["STATE_ABBR"], "IL", "read STATE_ABBR");
|
||||
t.eq(attributes["LAND_KM"], "143986.61", "read LAND_KM");
|
||||
}
|
||||
|
||||
function test_write(t) {
|
||||
t.plan(1);
|
||||
var doc = readXML("v2/topp-states.xml");
|
||||
var format = new OpenLayers.Format.GML.v2({
|
||||
featureType: "states",
|
||||
featureNS: "http://www.openplans.org/topp",
|
||||
geometryName: "the_geom",
|
||||
schemaLocation: "http://www.openplans.org/topp http://sigma.openplans.org:80/geoserver/wfs?service=WFS&version=1.0.0&request=DescribeFeatureType&typeName=topp:states http://www.opengis.net/wfs http://sigma.openplans.org:80/geoserver/schemas/wfs/1.0.0/WFS-basic.xsd",
|
||||
srsName: "http://www.opengis.net/gml/srs/epsg.xml#4326"
|
||||
});
|
||||
var features = format.read(doc.documentElement);
|
||||
|
||||
var got = format.write(features);
|
||||
t.xml_eq(got, doc.documentElement, "wfs:FeatureCollection round trip");
|
||||
|
||||
}
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="v2/point-coord.xml"><!--
|
||||
<gml:Point xmlns:gml="http://www.opengis.net/gml" srsName="foo">
|
||||
<gml:coord>
|
||||
<gml:X>1</gml:X>
|
||||
<gml:Y>2</gml:Y>
|
||||
</gml:coord>
|
||||
</gml:Point>
|
||||
--></div>
|
||||
<div id="v2/point-coordinates.xml"><!--
|
||||
<gml:Point xmlns:gml="http://www.opengis.net/gml" srsName="foo">
|
||||
<gml:coordinates decimal="." cs="," ts=" ">1,2</gml:coordinates>
|
||||
</gml:Point>
|
||||
--></div>
|
||||
<div id="v2/linestring-coord.xml"><!--
|
||||
<gml:LineString xmlns:gml="http://www.opengis.net/gml" srsName="foo">
|
||||
<gml:coord>
|
||||
<gml:X>1</gml:X>
|
||||
<gml:Y>2</gml:Y>
|
||||
</gml:coord>
|
||||
<gml:coord>
|
||||
<gml:X>3</gml:X>
|
||||
<gml:Y>4</gml:Y>
|
||||
</gml:coord>
|
||||
</gml:LineString>
|
||||
--></div>
|
||||
<div id="v2/linestring-coordinates.xml"><!--
|
||||
<gml:LineString xmlns:gml="http://www.opengis.net/gml" srsName="foo">
|
||||
<gml:coordinates decimal="." cs="," ts=" ">1,2 3,4</gml:coordinates>
|
||||
</gml:LineString>
|
||||
--></div>
|
||||
<div id="v2/polygon-coord.xml"><!--
|
||||
<gml:Polygon xmlns:gml="http://www.opengis.net/gml" srsName="foo">
|
||||
<gml:outerBoundaryIs>
|
||||
<gml:LinearRing>
|
||||
<gml:coord>
|
||||
<gml:X>1</gml:X>
|
||||
<gml:Y>2</gml:Y>
|
||||
</gml:coord>
|
||||
<gml:coord>
|
||||
<gml:X>3</gml:X>
|
||||
<gml:Y>4</gml:Y>
|
||||
</gml:coord>
|
||||
<gml:coord>
|
||||
<gml:X>5</gml:X>
|
||||
<gml:Y>6</gml:Y>
|
||||
</gml:coord>
|
||||
<gml:coord>
|
||||
<gml:X>1</gml:X>
|
||||
<gml:Y>2</gml:Y>
|
||||
</gml:coord>
|
||||
</gml:LinearRing>
|
||||
</gml:outerBoundaryIs>
|
||||
<gml:innerBoundaryIs>
|
||||
<gml:LinearRing>
|
||||
<gml:coord>
|
||||
<gml:X>2</gml:X>
|
||||
<gml:Y>3</gml:Y>
|
||||
</gml:coord>
|
||||
<gml:coord>
|
||||
<gml:X>4</gml:X>
|
||||
<gml:Y>5</gml:Y>
|
||||
</gml:coord>
|
||||
<gml:coord>
|
||||
<gml:X>6</gml:X>
|
||||
<gml:Y>7</gml:Y>
|
||||
</gml:coord>
|
||||
<gml:coord>
|
||||
<gml:X>2</gml:X>
|
||||
<gml:Y>3</gml:Y>
|
||||
</gml:coord>
|
||||
</gml:LinearRing>
|
||||
</gml:innerBoundaryIs>
|
||||
<gml:innerBoundaryIs>
|
||||
<gml:LinearRing>
|
||||
<gml:coord>
|
||||
<gml:X>3</gml:X>
|
||||
<gml:Y>4</gml:Y>
|
||||
</gml:coord>
|
||||
<gml:coord>
|
||||
<gml:X>5</gml:X>
|
||||
<gml:Y>6</gml:Y>
|
||||
</gml:coord>
|
||||
<gml:coord>
|
||||
<gml:X>7</gml:X>
|
||||
<gml:Y>8</gml:Y>
|
||||
</gml:coord>
|
||||
<gml:coord>
|
||||
<gml:X>3</gml:X>
|
||||
<gml:Y>4</gml:Y>
|
||||
</gml:coord>
|
||||
</gml:LinearRing>
|
||||
</gml:innerBoundaryIs>
|
||||
</gml:Polygon>
|
||||
--></div>
|
||||
<div id="v2/polygon-coordinates.xml"><!--
|
||||
<gml:Polygon xmlns:gml="http://www.opengis.net/gml" srsName="foo">
|
||||
<gml:outerBoundaryIs>
|
||||
<gml:LinearRing>
|
||||
<gml:coordinates decimal="." cs="," ts=" ">1,2 3,4 5,6 1,2</gml:coordinates>
|
||||
</gml:LinearRing>
|
||||
</gml:outerBoundaryIs>
|
||||
<gml:innerBoundaryIs>
|
||||
<gml:LinearRing>
|
||||
<gml:coordinates decimal="." cs="," ts=" ">2,3 4,5 6,7 2,3</gml:coordinates>
|
||||
</gml:LinearRing>
|
||||
</gml:innerBoundaryIs>
|
||||
<gml:innerBoundaryIs>
|
||||
<gml:LinearRing>
|
||||
<gml:coordinates decimal="." cs="," ts=" ">3,4 5,6 7,8 3,4</gml:coordinates>
|
||||
</gml:LinearRing>
|
||||
</gml:innerBoundaryIs>
|
||||
</gml:Polygon>
|
||||
--></div>
|
||||
<div id="v2/multipoint-coord.xml"><!--
|
||||
<gml:MultiPoint xmlns:gml="http://www.opengis.net/gml" srsName="foo">
|
||||
<gml:pointMember>
|
||||
<gml:Point>
|
||||
<gml:coord>
|
||||
<gml:X>1</gml:X>
|
||||
<gml:Y>2</gml:Y>
|
||||
</gml:coord>
|
||||
</gml:Point>
|
||||
</gml:pointMember>
|
||||
<gml:pointMember>
|
||||
<gml:Point>
|
||||
<gml:coord>
|
||||
<gml:X>2</gml:X>
|
||||
<gml:Y>3</gml:Y>
|
||||
</gml:coord>
|
||||
</gml:Point>
|
||||
</gml:pointMember>
|
||||
<gml:pointMember>
|
||||
<gml:Point>
|
||||
<gml:coord>
|
||||
<gml:X>3</gml:X>
|
||||
<gml:Y>4</gml:Y>
|
||||
</gml:coord>
|
||||
</gml:Point>
|
||||
</gml:pointMember>
|
||||
</gml:MultiPoint>
|
||||
--></div>
|
||||
<div id="v2/multipoint-coordinates.xml"><!--
|
||||
<gml:MultiPoint xmlns:gml="http://www.opengis.net/gml" srsName="foo">
|
||||
<gml:pointMember>
|
||||
<gml:Point>
|
||||
<gml:coordinates decimal="." cs="," ts=" ">1,2</gml:coordinates>
|
||||
</gml:Point>
|
||||
</gml:pointMember>
|
||||
<gml:pointMember>
|
||||
<gml:Point>
|
||||
<gml:coordinates decimal="." cs="," ts=" ">2,3</gml:coordinates>
|
||||
</gml:Point>
|
||||
</gml:pointMember>
|
||||
<gml:pointMember>
|
||||
<gml:Point>
|
||||
<gml:coordinates decimal="." cs="," ts=" ">3,4</gml:coordinates>
|
||||
</gml:Point>
|
||||
</gml:pointMember>
|
||||
</gml:MultiPoint>
|
||||
--></div>
|
||||
<div id="v2/multilinestring-coord.xml"><!--
|
||||
<gml:MultiLineString xmlns:gml="http://www.opengis.net/gml" srsName="foo">
|
||||
<gml:lineStringMember>
|
||||
<gml:LineString>
|
||||
<gml:coord>
|
||||
<gml:X>1</gml:X>
|
||||
<gml:Y>2</gml:Y>
|
||||
</gml:coord>
|
||||
<gml:coord>
|
||||
<gml:X>2</gml:X>
|
||||
<gml:Y>3</gml:Y>
|
||||
</gml:coord>
|
||||
</gml:LineString>
|
||||
</gml:lineStringMember>
|
||||
<gml:lineStringMember>
|
||||
<gml:LineString>
|
||||
<gml:coord>
|
||||
<gml:X>3</gml:X>
|
||||
<gml:Y>4</gml:Y>
|
||||
</gml:coord>
|
||||
<gml:coord>
|
||||
<gml:X>4</gml:X>
|
||||
<gml:Y>5</gml:Y>
|
||||
</gml:coord>
|
||||
</gml:LineString>
|
||||
</gml:lineStringMember>
|
||||
</gml:MultiLineString>
|
||||
--></div>
|
||||
<div id="v2/multilinestring-coordinates.xml"><!--
|
||||
<gml:MultiLineString xmlns:gml="http://www.opengis.net/gml" srsName="foo">
|
||||
<gml:lineStringMember>
|
||||
<gml:LineString>
|
||||
<gml:coordinates decimal="." cs="," ts=" ">1,2 2,3</gml:coordinates>
|
||||
</gml:LineString>
|
||||
</gml:lineStringMember>
|
||||
<gml:lineStringMember>
|
||||
<gml:LineString>
|
||||
<gml:coordinates decimal="." cs="," ts=" ">3,4 4,5</gml:coordinates>
|
||||
</gml:LineString>
|
||||
</gml:lineStringMember>
|
||||
</gml:MultiLineString>
|
||||
--></div>
|
||||
<div id="v2/multipolygon-coord.xml"><!--
|
||||
<gml:MultiPolygon xmlns:gml="http://www.opengis.net/gml" srsName="foo">
|
||||
<gml:polygonMember>
|
||||
<gml:Polygon>
|
||||
<gml:outerBoundaryIs>
|
||||
<gml:LinearRing>
|
||||
<gml:coord>
|
||||
<gml:X>1</gml:X>
|
||||
<gml:Y>2</gml:Y>
|
||||
</gml:coord>
|
||||
<gml:coord>
|
||||
<gml:X>3</gml:X>
|
||||
<gml:Y>4</gml:Y>
|
||||
</gml:coord>
|
||||
<gml:coord>
|
||||
<gml:X>5</gml:X>
|
||||
<gml:Y>6</gml:Y>
|
||||
</gml:coord>
|
||||
<gml:coord>
|
||||
<gml:X>1</gml:X>
|
||||
<gml:Y>2</gml:Y>
|
||||
</gml:coord>
|
||||
</gml:LinearRing>
|
||||
</gml:outerBoundaryIs>
|
||||
<gml:innerBoundaryIs>
|
||||
<gml:LinearRing>
|
||||
<gml:coord>
|
||||
<gml:X>2</gml:X>
|
||||
<gml:Y>3</gml:Y>
|
||||
</gml:coord>
|
||||
<gml:coord>
|
||||
<gml:X>4</gml:X>
|
||||
<gml:Y>5</gml:Y>
|
||||
</gml:coord>
|
||||
<gml:coord>
|
||||
<gml:X>6</gml:X>
|
||||
<gml:Y>7</gml:Y>
|
||||
</gml:coord>
|
||||
<gml:coord>
|
||||
<gml:X>2</gml:X>
|
||||
<gml:Y>3</gml:Y>
|
||||
</gml:coord>
|
||||
</gml:LinearRing>
|
||||
</gml:innerBoundaryIs>
|
||||
<gml:innerBoundaryIs>
|
||||
<gml:LinearRing>
|
||||
<gml:coord>
|
||||
<gml:X>3</gml:X>
|
||||
<gml:Y>4</gml:Y>
|
||||
</gml:coord>
|
||||
<gml:coord>
|
||||
<gml:X>5</gml:X>
|
||||
<gml:Y>6</gml:Y>
|
||||
</gml:coord>
|
||||
<gml:coord>
|
||||
<gml:X>7</gml:X>
|
||||
<gml:Y>8</gml:Y>
|
||||
</gml:coord>
|
||||
<gml:coord>
|
||||
<gml:X>3</gml:X>
|
||||
<gml:Y>4</gml:Y>
|
||||
</gml:coord>
|
||||
</gml:LinearRing>
|
||||
</gml:innerBoundaryIs>
|
||||
</gml:Polygon>
|
||||
</gml:polygonMember>
|
||||
<gml:polygonMember>
|
||||
<gml:Polygon>
|
||||
<gml:outerBoundaryIs>
|
||||
<gml:LinearRing>
|
||||
<gml:coord>
|
||||
<gml:X>1</gml:X>
|
||||
<gml:Y>2</gml:Y>
|
||||
</gml:coord>
|
||||
<gml:coord>
|
||||
<gml:X>3</gml:X>
|
||||
<gml:Y>4</gml:Y>
|
||||
</gml:coord>
|
||||
<gml:coord>
|
||||
<gml:X>5</gml:X>
|
||||
<gml:Y>6</gml:Y>
|
||||
</gml:coord>
|
||||
<gml:coord>
|
||||
<gml:X>1</gml:X>
|
||||
<gml:Y>2</gml:Y>
|
||||
</gml:coord>
|
||||
</gml:LinearRing>
|
||||
</gml:outerBoundaryIs>
|
||||
</gml:Polygon>
|
||||
</gml:polygonMember>
|
||||
</gml:MultiPolygon>
|
||||
--></div>
|
||||
<div id="v2/multipolygon-coordinates.xml"><!--
|
||||
<gml:MultiPolygon xmlns:gml="http://www.opengis.net/gml" srsName="foo">
|
||||
<gml:polygonMember>
|
||||
<gml:Polygon>
|
||||
<gml:outerBoundaryIs>
|
||||
<gml:LinearRing>
|
||||
<gml:coordinates decimal="." cs="," ts=" ">1,2 3,4 5,6 1,2</gml:coordinates>
|
||||
</gml:LinearRing>
|
||||
</gml:outerBoundaryIs>
|
||||
<gml:innerBoundaryIs>
|
||||
<gml:LinearRing>
|
||||
<gml:coordinates decimal="." cs="," ts=" ">2,3 4,5 6,7 2,3</gml:coordinates>
|
||||
</gml:LinearRing>
|
||||
</gml:innerBoundaryIs>
|
||||
<gml:innerBoundaryIs>
|
||||
<gml:LinearRing>
|
||||
<gml:coordinates decimal="." cs="," ts=" ">3,4 5,6 7,8 3,4</gml:coordinates>
|
||||
</gml:LinearRing>
|
||||
</gml:innerBoundaryIs>
|
||||
</gml:Polygon>
|
||||
</gml:polygonMember>
|
||||
<gml:polygonMember>
|
||||
<gml:Polygon>
|
||||
<gml:outerBoundaryIs>
|
||||
<gml:LinearRing>
|
||||
<gml:coordinates decimal="." cs="," ts=" ">1,2 3,4 5,6 1,2</gml:coordinates>
|
||||
</gml:LinearRing>
|
||||
</gml:outerBoundaryIs>
|
||||
</gml:Polygon>
|
||||
</gml:polygonMember>
|
||||
</gml:MultiPolygon>
|
||||
--></div>
|
||||
<div id="v2/geometrycollection-coordinates.xml"><!--
|
||||
<gml:GeometryCollection xmlns:gml="http://www.opengis.net/gml" srsName="foo">
|
||||
<gml:geometryMember>
|
||||
<gml:Point srsName="foo">
|
||||
<gml:coordinates decimal="." cs="," ts=" ">1,2</gml:coordinates>
|
||||
</gml:Point>
|
||||
</gml:geometryMember>
|
||||
<gml:geometryMember>
|
||||
<gml:LineString srsName="foo">
|
||||
<gml:coordinates decimal="." cs="," ts=" ">1,2 3,4</gml:coordinates>
|
||||
</gml:LineString>
|
||||
</gml:geometryMember>
|
||||
<gml:geometryMember>
|
||||
<gml:Polygon srsName="foo">
|
||||
<gml:outerBoundaryIs>
|
||||
<gml:LinearRing>
|
||||
<gml:coordinates decimal="." cs="," ts=" ">1,2 3,4 5,6 1,2</gml:coordinates>
|
||||
</gml:LinearRing>
|
||||
</gml:outerBoundaryIs>
|
||||
<gml:innerBoundaryIs>
|
||||
<gml:LinearRing>
|
||||
<gml:coordinates decimal="." cs="," ts=" ">2,3 4,5 6,7 2,3</gml:coordinates>
|
||||
</gml:LinearRing>
|
||||
</gml:innerBoundaryIs>
|
||||
<gml:innerBoundaryIs>
|
||||
<gml:LinearRing>
|
||||
<gml:coordinates decimal="." cs="," ts=" ">3,4 5,6 7,8 3,4</gml:coordinates>
|
||||
</gml:LinearRing>
|
||||
</gml:innerBoundaryIs>
|
||||
</gml:Polygon>
|
||||
</gml:geometryMember>
|
||||
</gml:GeometryCollection>
|
||||
--></div>
|
||||
<div id="v2/box-coord.xml"><!--
|
||||
<gml:Box xmlns:gml="http://www.opengis.net/gml" srsName="foo">
|
||||
<gml:coord>
|
||||
<gml:X>1</gml:X>
|
||||
<gml:Y>2</gml:Y>
|
||||
</gml:coord>
|
||||
<gml:coord>
|
||||
<gml:X>3</gml:X>
|
||||
<gml:Y>4</gml:Y>
|
||||
</gml:coord>
|
||||
</gml:Box>
|
||||
--></div>
|
||||
<div id="v2/box-coordinates.xml"><!--
|
||||
<gml:Box xmlns:gml="http://www.opengis.net/gml" srsName="foo">
|
||||
<gml:coordinates decimal="." cs="," ts=" ">1,2 3,4</gml:coordinates>
|
||||
</gml:Box>
|
||||
--></div>
|
||||
<div id="v2/linearring-coord.xml"><!--
|
||||
<gml:LinearRing xmlns:gml="http://www.opengis.net/gml" srsName="foo">
|
||||
<gml:coord>
|
||||
<gml:X>1</gml:X>
|
||||
<gml:Y>2</gml:Y>
|
||||
</gml:coord>
|
||||
<gml:coord>
|
||||
<gml:X>3</gml:X>
|
||||
<gml:Y>4</gml:Y>
|
||||
</gml:coord>
|
||||
<gml:coord>
|
||||
<gml:X>5</gml:X>
|
||||
<gml:Y>6</gml:Y>
|
||||
</gml:coord>
|
||||
<gml:coord>
|
||||
<gml:X>1</gml:X>
|
||||
<gml:Y>2</gml:Y>
|
||||
</gml:coord>
|
||||
</gml:LinearRing>
|
||||
--></div>
|
||||
<div id="v2/linearring-coordinates.xml"><!--
|
||||
<gml:LinearRing xmlns:gml="http://www.opengis.net/gml" srsName="foo">
|
||||
<gml:coordinates decimal="." cs="," ts=" ">1,2 3,4 5,6 1,2</gml:coordinates>
|
||||
</gml:LinearRing>
|
||||
--></div>
|
||||
<div id="v2/topp-states.xml"><!--
|
||||
<?xml version="1.0" encoding="UTF-8"?><wfs:FeatureCollection xmlns="http://www.opengis.net/wfs" xmlns:wfs="http://www.opengis.net/wfs" xmlns:topp="http://www.openplans.org/topp" xmlns:gml="http://www.opengis.net/gml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.openplans.org/topp http://sigma.openplans.org:80/geoserver/wfs?service=WFS&version=1.0.0&request=DescribeFeatureType&typeName=topp:states http://www.opengis.net/wfs http://sigma.openplans.org:80/geoserver/schemas/wfs/1.0.0/WFS-basic.xsd"><gml:featureMember><topp:states fid="states.1"><topp:the_geom><gml:MultiPolygon srsName="http://www.opengis.net/gml/srs/epsg.xml#4326"><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates xmlns:gml="http://www.opengis.net/gml" decimal="." cs="," ts=" ">37.51099,-88.071564 37.476273,-88.087883 37.442852,-88.311707 37.409309,-88.359177 37.420292,-88.419853 37.400757,-88.467644 37.296852,-88.511322 37.257782,-88.501427 37.205669,-88.450699 37.15691,-88.422516 37.098671,-88.45047 37.072144,-88.476799 37.06818,-88.4907 37.06477,-88.517273 37.072815,-88.559273 37.109047,-88.61422 37.13541,-88.68837 37.141182,-88.739113 37.152107,-88.746506 37.202194,-88.863289 37.218407,-88.932503 37.220036,-88.993172 37.18586,-89.065033 37.112137,-89.116821 37.093185,-89.146347 37.064236,-89.169548 37.025711,-89.174332 36.99844,-89.150246 36.988113,-89.12986 36.986771,-89.193512 37.028973,-89.210052 37.041733,-89.237679 37.087124,-89.264053 37.091244,-89.284233 37.085384,-89.303291 37.060909,-89.3097 37.027733,-89.264244 37.008686,-89.262001 36.999207,-89.282768 37.009682,-89.310982 37.049213,-89.38295 37.099083,-89.37999 37.137203,-89.423798 37.165318,-89.440521 37.224266,-89.468216 37.253731,-89.465309 37.256001,-89.489594 37.276402,-89.513885 37.304962,-89.513885 37.329441,-89.50058 37.339409,-89.468742 37.355717,-89.435738 37.411018,-89.427574 37.453186,-89.453621 37.491726,-89.494781 37.571957,-89.524971 37.615929,-89.513367 37.650375,-89.51918 37.67984,-89.513374 37.694798,-89.521523 37.706104,-89.581436 37.745453,-89.666458 37.78397,-89.675858 37.804794,-89.691055 37.840992,-89.728447 37.905064,-89.851715 37.905487,-89.861046 37.891876,-89.866814 37.875904,-89.900551 37.878044,-89.937874 37.911884,-89.978912 37.963634,-89.958229 37.969318,-90.010811 37.993206,-90.041924 38.032272,-90.119339 38.053951,-90.134712 38.088905,-90.207527 38.122169,-90.254059 38.166817,-90.289635 38.188713,-90.336716 38.234299,-90.364769 38.323559,-90.369347 38.36533,-90.358688 38.390846,-90.339607 38.427357,-90.301842 38.518688,-90.265785 38.532768,-90.26123 38.562805,-90.240944 38.610271,-90.183708 38.658772,-90.183578 38.700363,-90.20224 38.723965,-90.196571 38.773098,-90.163399 38.785484,-90.135178 38.80051,-90.121727 38.830467,-90.113121 38.853031,-90.132812 38.914509,-90.243927 38.924717,-90.278931 38.924908,-90.31974 38.96233,-90.413071 38.959179,-90.469841 38.891609,-90.530426 38.871326,-90.570328 38.880795,-90.627213 38.935253,-90.668877 39.037792,-90.70607 39.058178,-90.707588 39.0937,-90.690399 39.144211,-90.716736 39.195873,-90.718193 39.224747,-90.732338 39.24781,-90.738083 39.296803,-90.779343 39.350452,-90.850494 39.400585,-90.947891 39.444412,-91.036339 39.473984,-91.064384 39.528927,-91.093613 39.552593,-91.156189 39.600021,-91.203247 39.685917,-91.317665 39.72464,-91.367088 39.761272,-91.373421 39.803772,-91.381714 39.863049,-91.449188 39.885242,-91.450989 39.901829,-91.434052 39.921837,-91.430389 39.946064,-91.447243 40.005753,-91.487289 40.066711,-91.504005 40.134544,-91.516129 40.200459,-91.506546 40.251377,-91.498932 40.309624,-91.486694 40.371902,-91.448593 40.386875,-91.418816 40.392361,-91.385757 40.402988,-91.372757 40.44725,-91.385399 40.503654,-91.374794 40.528496,-91.382103 40.547993,-91.412872 40.572971,-91.411118 40.603439,-91.37561 40.639545,-91.262062 40.643818,-91.214912 40.656311,-91.162498 40.682148,-91.129158 40.705402,-91.119987 40.761547,-91.092751 40.833729,-91.088905 40.879585,-91.04921 40.923927,-90.983276 40.950504,-90.960709 41.070362,-90.954651 41.104359,-90.957787 41.144371,-90.990341 41.165825,-91.018257 41.176258,-91.05632 41.231522,-91.101524 41.267818,-91.102348 41.334896,-91.07328 41.401379,-91.055786 41.423508,-91.027489 41.431084,-91.000694 41.421234,-90.949654 41.444622,-90.844139 41.449821,-90.7799 41.450062,-90.708214 41.462318,-90.658791 41.509586,-90.6007 41.52597,-90.54084 41.527546,-90.454994 41.543579,-90.434967 41.567272,-90.423004 41.586849,-90.348366 41.602798,-90.339348 41.64909,-90.341133 41.722736,-90.326027 41.756466,-90.304886 41.781738,-90.25531 41.806137,-90.195839 41.930775,-90.154518 41.983963,-90.14267 42.033428,-90.150536 42.061043,-90.168098 42.103745,-90.166649 42.120502,-90.176086 42.122688,-90.191574 42.159721,-90.230934 42.197319,-90.323601 42.210209,-90.367729 42.242645,-90.407173 42.263924,-90.417984 42.340633,-90.427681 42.360073,-90.441597 42.388783,-90.491043 42.421837,-90.563583 42.4605Line truncated
|
||||
--></div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,551 @@
|
||||
<html>
|
||||
<head>
|
||||
<script src="../../../lib/OpenLayers.js"></script>
|
||||
<script src="cases.js"></script>
|
||||
<script type="text/javascript">
|
||||
|
||||
function test_readNode_geometry(t) {
|
||||
var files = [
|
||||
"v2/point-coord.xml", "v2/point-coordinates.xml",
|
||||
"v2/linestring-coord.xml", "v2/linestring-coordinates.xml",
|
||||
"v2/multipoint-coord.xml", "v2/multipoint-coordinates.xml",
|
||||
"v2/multilinestring-coord.xml", "v2/multilinestring-coordinates.xml",
|
||||
"v3/point.xml", "v3/linestring.xml", "v3/polygon.xml",
|
||||
"v3/multipoint-singular.xml", "v3/multipoint-plural.xml",
|
||||
"v3/multilinestring-singular.xml", "v3/multilinestring-plural.xml",
|
||||
"v3/multipolygon-singular.xml", "v3/multipolygon-plural.xml",
|
||||
"v3/multisurface-singular.xml", "v3/multisurface-plural.xml"
|
||||
];
|
||||
|
||||
var len = files.length;
|
||||
t.plan(len);
|
||||
|
||||
var format = new OpenLayers.Format.GML.v3({
|
||||
featureType: "feature",
|
||||
featureNS: "http://example.com/feature"
|
||||
});
|
||||
var file, doc, expect, out;
|
||||
for(var i=0; i<len; ++i) {
|
||||
file = files[i];
|
||||
expect = cases[file];
|
||||
if(expect) {
|
||||
doc = readXML(file);
|
||||
if(doc && doc.documentElement) {
|
||||
out = format.readNode(doc.documentElement);
|
||||
if(out.components && out.components.length == 1) {
|
||||
t.geom_eq(out.components[0], expect, "[" + file + "] geometry read");
|
||||
} else {
|
||||
t.fail("[" + file + "] gml parsing");
|
||||
}
|
||||
} else {
|
||||
t.fail("[" + file + "] xml parsing");
|
||||
}
|
||||
} else {
|
||||
t.fail("[" + file + "] case not found");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function test_readNode_bounds(t) {
|
||||
var files = ["v3/envelope.xml"];
|
||||
|
||||
var len = files.length;
|
||||
t.plan(len);
|
||||
|
||||
var file, doc, expect, got;
|
||||
var format = new OpenLayers.Format.GML.v3({
|
||||
featureType: "feature",
|
||||
featureNS: "http://example.com/feature"
|
||||
});
|
||||
for(var i=0; i<len; ++i) {
|
||||
file = files[i];
|
||||
expect = cases[file];
|
||||
if(expect) {
|
||||
doc = readXML(file);
|
||||
if(doc && doc.documentElement) {
|
||||
out = format.readNode(doc.documentElement);
|
||||
if(out.components && out.components.length == 1) {
|
||||
got = out.components[0];
|
||||
if(got instanceof OpenLayers.Bounds) {
|
||||
t.ok(out.components[0].equals(expect), "[" + file + "] bounds read")
|
||||
} else {
|
||||
t.fail("[" + file + "] expected a bounds, got " + got);
|
||||
}
|
||||
} else {
|
||||
t.fail("[" + file + "] gml parsing");
|
||||
}
|
||||
} else {
|
||||
t.fail("[" + file + "] xml parsing");
|
||||
}
|
||||
} else {
|
||||
t.fail("[" + file + "] case not found");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function test_writeNode_geometry(t) {
|
||||
// we only care to write the 'pos' and 'posList' variants of GML 3 - conforming with simple features profile
|
||||
var files = [
|
||||
"v3/point.xml",
|
||||
"v3/linestring.xml",
|
||||
"v3/polygon.xml",
|
||||
"v3/multipoint-singular.xml",
|
||||
"v3/multilinestring-singular.xml",
|
||||
"v3/multipolygon-singular.xml"
|
||||
];
|
||||
|
||||
var len = files.length;
|
||||
t.plan(len);
|
||||
|
||||
var format = new OpenLayers.Format.GML.v3({
|
||||
featureType: "feature",
|
||||
featureNS: "http://example.com/feature",
|
||||
srsName: "foo" // GML geometry collections require srsName, we only write if provided
|
||||
});
|
||||
var file, geom, doc, node;
|
||||
for(var i=0; i<len; ++i) {
|
||||
file = files[i];
|
||||
geom = cases[file];
|
||||
if(geom) {
|
||||
doc = readXML(file);
|
||||
if(doc && doc.documentElement) {
|
||||
node = format.writeNode("feature:_geometry", geom);
|
||||
t.xml_eq(node.firstChild, doc.documentElement, "[" + file + "] geometry written");
|
||||
} else {
|
||||
t.fail("[" + file + "] xml parsing");
|
||||
}
|
||||
} else {
|
||||
t.fail("[" + file + "] case not found");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function test_writeNode_bounds(t) {
|
||||
// we only care to write the 'coordinates' variant of GML 2
|
||||
var files = [
|
||||
"v3/envelope.xml"
|
||||
];
|
||||
|
||||
var len = files.length;
|
||||
t.plan(len);
|
||||
|
||||
var format = new OpenLayers.Format.GML.v3({
|
||||
featureType: "feature",
|
||||
featureNS: "http://example.com/feature",
|
||||
srsName: "foo" // GML envelopes require srsName, we only write if provided
|
||||
});
|
||||
var file, bounds, doc, node;
|
||||
for(var i=0; i<len; ++i) {
|
||||
file = files[i];
|
||||
bounds = cases[file];
|
||||
if(bounds) {
|
||||
doc = readXML(file);
|
||||
if(doc && doc.documentElement) {
|
||||
node = format.writeNode("gml:Envelope", bounds);
|
||||
t.xml_eq(node, doc.documentElement, "[" + file + "] bounds written");
|
||||
} else {
|
||||
t.fail("[" + file + "] xml parsing");
|
||||
}
|
||||
} else {
|
||||
t.fail("[" + file + "] case not found");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function test_read(t) {
|
||||
t.plan(8);
|
||||
var doc = readXML("v3/topp-states-wfs.xml");
|
||||
var format = new OpenLayers.Format.GML.v3({
|
||||
featureType: "states",
|
||||
featureNS: "http://www.openplans.org/topp",
|
||||
geometryName: "the_geom"
|
||||
});
|
||||
var features = format.read(doc.documentElement);
|
||||
|
||||
t.eq(features.length, 3, "read 3 features");
|
||||
var feature = features[0];
|
||||
t.eq(feature.fid, "states.1", "read fid");
|
||||
t.eq(feature.geometry.CLASS_NAME, "OpenLayers.Geometry.MultiPolygon",
|
||||
"read multipolygon geometry");
|
||||
var attributes = feature.attributes;
|
||||
t.eq(attributes["STATE_NAME"], "Illinois", "read STATE_NAME");
|
||||
t.eq(attributes["STATE_FIPS"], "17", "read STATE_FIPS");
|
||||
t.eq(attributes["SUB_REGION"], "E N Cen", "read SUB_REGION");
|
||||
t.eq(attributes["STATE_ABBR"], "IL", "read STATE_ABBR");
|
||||
t.eq(attributes["LAND_KM"], "143986.61", "read LAND_KM");
|
||||
}
|
||||
|
||||
function test_write(t) {
|
||||
t.plan(1);
|
||||
var doc = readXML("v3/topp-states-gml.xml");
|
||||
var format = new OpenLayers.Format.GML.v3({
|
||||
featureType: "states",
|
||||
featureNS: "http://www.openplans.org/topp",
|
||||
geometryName: "the_geom",
|
||||
srsName: "urn:x-ogc:def:crs:EPSG:4326",
|
||||
schemaLocation: "http://www.openplans.org/topp http://sigma.openplans.org:80/geoserver/wfs?service=WFS&version=1.1.0&request=DescribeFeatureType&typeName=topp:states http://www.opengis.net/gml http://schemas.opengis.net/gml/3.2.1/gml.xsd"
|
||||
});
|
||||
var features = format.read(doc.documentElement);
|
||||
|
||||
var got = format.write(features);
|
||||
t.xml_eq(got, doc.documentElement, "gml:featureMembers round trip");
|
||||
}
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="v3/envelope.xml"><!--
|
||||
<gml:Envelope xmlns:gml="http://www.opengis.net/gml" srsName="foo">
|
||||
<gml:lowerCorner><gml:pos>1 2</gml:pos></gml:lowerCorner>
|
||||
<gml:upperCorner><gml:pos>3 4</gml:pos></gml:upperCorner>
|
||||
</gml:Envelope>
|
||||
--></div>
|
||||
<div id="v3/linearring.xml"><!--
|
||||
<gml:LinearRing xmlns:gml="http://www.opengis.net/gml" srsName="foo">
|
||||
<gml:posList>1 2 3 4 5 6 1 2</gml:posList>
|
||||
</gml:LinearRing>
|
||||
--></div>
|
||||
<div id="v3/linestring.xml"><!--
|
||||
<gml:LineString xmlns:gml="http://www.opengis.net/gml" srsName="foo">
|
||||
<gml:posList>1 2 3 4</gml:posList>
|
||||
</gml:LineString>
|
||||
--></div>
|
||||
<div id="v3/multilinestring-plural.xml"><!--
|
||||
<gml:MultiLineString xmlns:gml="http://www.opengis.net/gml" srsName="foo">
|
||||
<gml:lineStringMembers>
|
||||
<gml:LineString>
|
||||
<gml:posList>1 2 2 3</gml:posList>
|
||||
</gml:LineString>
|
||||
<gml:LineString>
|
||||
<gml:posList>3 4 4 5</gml:posList>
|
||||
</gml:LineString>
|
||||
</gml:lineStringMembers>
|
||||
</gml:MultiLineString>
|
||||
--></div>
|
||||
<div id="v3/multilinestring-singular.xml"><!--
|
||||
<gml:MultiLineString xmlns:gml="http://www.opengis.net/gml" srsName="foo">
|
||||
<gml:lineStringMember>
|
||||
<gml:LineString>
|
||||
<gml:posList>1 2 2 3</gml:posList>
|
||||
</gml:LineString>
|
||||
</gml:lineStringMember>
|
||||
<gml:lineStringMember>
|
||||
<gml:LineString>
|
||||
<gml:posList>3 4 4 5</gml:posList>
|
||||
</gml:LineString>
|
||||
</gml:lineStringMember>
|
||||
</gml:MultiLineString>
|
||||
--></div>
|
||||
<div id="v3/multipoint-plural.xml"><!--
|
||||
<gml:MultiPoint xmlns:gml="http://www.opengis.net/gml" srsName="foo">
|
||||
<gml:pointMembers>
|
||||
<gml:Point>
|
||||
<gml:pos>1 2</gml:pos>
|
||||
</gml:Point>
|
||||
<gml:Point>
|
||||
<gml:pos>2 3</gml:pos>
|
||||
</gml:Point>
|
||||
<gml:Point>
|
||||
<gml:pos>3 4</gml:pos>
|
||||
</gml:Point>
|
||||
</gml:pointMembers>
|
||||
</gml:MultiPoint>
|
||||
--></div>
|
||||
<div id="v3/multipoint-singular.xml"><!--
|
||||
<gml:MultiPoint xmlns:gml="http://www.opengis.net/gml" srsName="foo">
|
||||
<gml:pointMember>
|
||||
<gml:Point>
|
||||
<gml:pos>1 2</gml:pos>
|
||||
</gml:Point>
|
||||
</gml:pointMember>
|
||||
<gml:pointMember>
|
||||
<gml:Point>
|
||||
<gml:pos>2 3</gml:pos>
|
||||
</gml:Point>
|
||||
</gml:pointMember>
|
||||
<gml:pointMember>
|
||||
<gml:Point>
|
||||
<gml:pos>3 4</gml:pos>
|
||||
</gml:Point>
|
||||
</gml:pointMember>
|
||||
</gml:MultiPoint>
|
||||
--></div>
|
||||
<div id="v3/multipolygon-plural.xml"><!--
|
||||
<gml:MultiPolygon xmlns:gml="http://www.opengis.net/gml" srsName="foo">
|
||||
<gml:polygonMembers>
|
||||
<gml:Polygon>
|
||||
<gml:exterior>
|
||||
<gml:LinearRing>
|
||||
<gml:posList>1 2 3 4 5 6 1 2</gml:posList>
|
||||
</gml:LinearRing>
|
||||
</gml:exterior>
|
||||
<gml:interior>
|
||||
<gml:LinearRing>
|
||||
<gml:posList>2 3 4 5 6 7 2 3</gml:posList>
|
||||
</gml:LinearRing>
|
||||
</gml:interior>
|
||||
<gml:interior>
|
||||
<gml:LinearRing>
|
||||
<gml:posList>3 4 5 6 7 8 3 4</gml:posList>
|
||||
</gml:LinearRing>
|
||||
</gml:interior>
|
||||
</gml:Polygon>
|
||||
<gml:Polygon>
|
||||
<gml:exterior>
|
||||
<gml:LinearRing>
|
||||
<gml:posList>1 2 3 4 5 6 1 2</gml:posList>
|
||||
</gml:LinearRing>
|
||||
</gml:exterior>
|
||||
</gml:Polygon>
|
||||
</gml:polygonMembers>
|
||||
</gml:MultiPolygon>
|
||||
--></div>
|
||||
<div id="v3/multipolygon-singular.xml"><!--
|
||||
<gml:MultiPolygon xmlns:gml="http://www.opengis.net/gml" srsName="foo">
|
||||
<gml:polygonMember>
|
||||
<gml:Polygon>
|
||||
<gml:exterior>
|
||||
<gml:LinearRing>
|
||||
<gml:posList>1 2 3 4 5 6 1 2</gml:posList>
|
||||
</gml:LinearRing>
|
||||
</gml:exterior>
|
||||
<gml:interior>
|
||||
<gml:LinearRing>
|
||||
<gml:posList>2 3 4 5 6 7 2 3</gml:posList>
|
||||
</gml:LinearRing>
|
||||
</gml:interior>
|
||||
<gml:interior>
|
||||
<gml:LinearRing>
|
||||
<gml:posList>3 4 5 6 7 8 3 4</gml:posList>
|
||||
</gml:LinearRing>
|
||||
</gml:interior>
|
||||
</gml:Polygon>
|
||||
</gml:polygonMember>
|
||||
<gml:polygonMember>
|
||||
<gml:Polygon>
|
||||
<gml:exterior>
|
||||
<gml:LinearRing>
|
||||
<gml:posList>1 2 3 4 5 6 1 2</gml:posList>
|
||||
</gml:LinearRing>
|
||||
</gml:exterior>
|
||||
</gml:Polygon>
|
||||
</gml:polygonMember>
|
||||
</gml:MultiPolygon>
|
||||
--></div>
|
||||
<div id="v3/multisurface-plural.xml"><!--
|
||||
<gml:MultiSurface xmlns:gml="http://www.opengis.net/gml" srsName="foo">
|
||||
<gml:surfaceMembers>
|
||||
<gml:Polygon>
|
||||
<gml:exterior>
|
||||
<gml:LinearRing>
|
||||
<gml:posList>1 2 3 4 5 6 1 2</gml:posList>
|
||||
</gml:LinearRing>
|
||||
</gml:exterior>
|
||||
<gml:interior>
|
||||
<gml:LinearRing>
|
||||
<gml:posList>2 3 4 5 6 7 2 3</gml:posList>
|
||||
</gml:LinearRing>
|
||||
</gml:interior>
|
||||
<gml:interior>
|
||||
<gml:LinearRing>
|
||||
<gml:posList>3 4 5 6 7 8 3 4</gml:posList>
|
||||
</gml:LinearRing>
|
||||
</gml:interior>
|
||||
</gml:Polygon>
|
||||
<gml:Polygon>
|
||||
<gml:exterior>
|
||||
<gml:LinearRing>
|
||||
<gml:posList>1 2 3 4 5 6 1 2</gml:posList>
|
||||
</gml:LinearRing>
|
||||
</gml:exterior>
|
||||
</gml:Polygon>
|
||||
</gml:surfaceMembers>
|
||||
</gml:MultiSurface>
|
||||
--></div>
|
||||
<div id="v3/multisurface-singular.xml"><!--
|
||||
<gml:MultiSurface xmlns:gml="http://www.opengis.net/gml" srsName="foo">
|
||||
<gml:surfaceMember>
|
||||
<gml:Polygon>
|
||||
<gml:exterior>
|
||||
<gml:LinearRing>
|
||||
<gml:posList>1 2 3 4 5 6 1 2</gml:posList>
|
||||
</gml:LinearRing>
|
||||
</gml:exterior>
|
||||
<gml:interior>
|
||||
<gml:LinearRing>
|
||||
<gml:posList>2 3 4 5 6 7 2 3</gml:posList>
|
||||
</gml:LinearRing>
|
||||
</gml:interior>
|
||||
<gml:interior>
|
||||
<gml:LinearRing>
|
||||
<gml:posList>3 4 5 6 7 8 3 4</gml:posList>
|
||||
</gml:LinearRing>
|
||||
</gml:interior>
|
||||
</gml:Polygon>
|
||||
</gml:surfaceMember>
|
||||
<gml:surfaceMember>
|
||||
<gml:Polygon>
|
||||
<gml:exterior>
|
||||
<gml:LinearRing>
|
||||
<gml:posList>1 2 3 4 5 6 1 2</gml:posList>
|
||||
</gml:LinearRing>
|
||||
</gml:exterior>
|
||||
</gml:Polygon>
|
||||
</gml:surfaceMember>
|
||||
</gml:MultiSurface>
|
||||
--></div>
|
||||
<div id="v3/point.xml"><!--
|
||||
<gml:Point xmlns:gml="http://www.opengis.net/gml" srsName="foo">
|
||||
<gml:pos>1 2</gml:pos>
|
||||
</gml:Point>
|
||||
--></div>
|
||||
<div id="v3/polygon.xml"><!--
|
||||
<gml:Polygon xmlns:gml="http://www.opengis.net/gml" srsName="foo">
|
||||
<gml:exterior>
|
||||
<gml:LinearRing>
|
||||
<gml:posList>1 2 3 4 5 6 1 2</gml:posList>
|
||||
</gml:LinearRing>
|
||||
</gml:exterior>
|
||||
<gml:interior>
|
||||
<gml:LinearRing>
|
||||
<gml:posList>2 3 4 5 6 7 2 3</gml:posList>
|
||||
</gml:LinearRing>
|
||||
</gml:interior>
|
||||
<gml:interior>
|
||||
<gml:LinearRing>
|
||||
<gml:posList>3 4 5 6 7 8 3 4</gml:posList>
|
||||
</gml:LinearRing>
|
||||
</gml:interior>
|
||||
</gml:Polygon>
|
||||
--></div>
|
||||
<div id="v3/topp-states-gml.xml"><!--
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<gml:featureMembers xsi:schemaLocation="http://www.openplans.org/topp http://sigma.openplans.org:80/geoserver/wfs?service=WFS&version=1.1.0&request=DescribeFeatureType&typeName=topp:states http://www.opengis.net/gml http://schemas.opengis.net/gml/3.2.1/gml.xsd" xmlns:topp="http://www.openplans.org/topp" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:gml="http://www.opengis.net/gml"><topp:states fid="states.1"><topp:the_geom><gml:MultiPolygon srsName="urn:x-ogc:def:crs:EPSG:4326"><gml:polygonMember><gml:Polygon><gml:exterior><gml:LinearRing><gml:posList>37.511 -88.071 37.476 -88.087 37.442 -88.311 37.409 -88.359 37.421 -88.419 37.401 -88.467 37.296 -88.511 37.257 -88.501 37.205 -88.451 37.156 -88.422 37.098 -88.451 37.072 -88.476 37.068 -88.491 37.064 -88.517 37.072 -88.559 37.109 -88.614 37.135 -88.688 37.141 -88.739 37.152 -88.746 37.202 -88.863 37.218 -88.932 37.221 -88.993 37.185 -89.065 37.112 -89.116 37.093 -89.146 37.064 -89.169 37.025 -89.174 36.998 -89.151 36.988 -89.129 36.986 -89.193 37.028 -89.211 37.041 -89.237 37.087 -89.264 37.091 -89.284 37.085 -89.303 37.061 -89.309 37.027 -89.264 37.008 -89.262 36.999 -89.282 37.009 -89.311 37.049 -89.382 37.099 -89.379 37.137 -89.423 37.165 -89.441 37.224 -89.468 37.253 -89.465 37.256 -89.489 37.276 -89.513 37.304 -89.513 37.329 -89.501 37.339 -89.468 37.355 -89.435 37.411 -89.427 37.453 -89.453 37.491 -89.494 37.571 -89.524 37.615 -89.513 37.651 -89.519 37.679 -89.513 37.694 -89.521 37.706 -89.581 37.745 -89.666 37.783 -89.675 37.804 -89.691 37.841 -89.728 37.905 -89.851 37.905 -89.861 37.891 -89.866 37.875 -89.901 37.878 -89.937 37.911 -89.978 37.963 -89.958 37.969 -90.011 37.993 -90.041 38.032 -90.119 38.053 -90.134 38.088 -90.207 38.122 -90.254 38.166 -90.289 38.188 -90.336 38.234 -90.364 38.323 -90.369 38.365 -90.358 38.391 -90.339 38.427 -90.301 38.518 -90.265 38.532 -90.261 38.562 -90.241 38.611 -90.183 38.658 -90.183 38.701 -90.202 38.723 -90.196 38.773 -90.163 38.785 -90.135 38.801 -90.121 38.831 -90.113 38.853 -90.132 38.914 -90.243 38.924 -90.278 38.924 -90.319 38.962 -90.413 38.959 -90.469 38.891 -90.531 38.871 -90.571 38.881 -90.627 38.935 -90.668 39.037 -90.706 39.058 -90.707 39.093 -90.691 39.144 -90.716 39.195 -90.718 39.224 -90.732 39.247 -90.738 39.296 -90.779 39.351 -90.851 39.401 -90.947 39.444 -91.036 39.473 -91.064 39.528 -91.093 39.552 -91.156 39.601 -91.203 39.685 -91.317 39.724 -91.367 39.761 -91.373 39.803 -91.381 39.863 -91.449 39.885 -91.451 39.901 -91.434 39.921 -91.431 39.946 -91.447 40.005 -91.487 40.066 -91.504 40.134 -91.516 40.201 -91.506 40.251 -91.498 40.309 -91.486 40.371 -91.448 40.386 -91.418 40.392 -91.385 40.402 -91.372 40.447 -91.385 40.503 -91.374 40.528 -91.382 40.547 -91.412 40.572 -91.411 40.603 -91.375 40.639 -91.262 40.643 -91.214 40.656 -91.162 40.682 -91.129 40.705 -91.119 40.761 -91.092 40.833 -91.088 40.879 -91.049 40.923 -90.983 40.951 -90.961 41.071 -90.954 41.104 -90.957 41.144 -90.991 41.165 -91.018 41.176 -91.056 41.231 -91.101 41.267 -91.102 41.334 -91.073 41.401 -91.055 41.423 -91.027 41.431 -91.001 41.421 -90.949 41.444 -90.844 41.449 -90.779 41.451 -90.708 41.462 -90.658 41.509 -90.601 41.525 -90.541 41.527 -90.454 41.543 -90.434 41.567 -90.423 41.586 -90.348 41.602 -90.339 41.649 -90.341 41.722 -90.326 41.756 -90.304 41.781 -90.255 41.806 -90.195 41.931 -90.154 41.983 -90.142 42.033 -90.151 42.061 -90.168 42.103 -90.166 42.121 -90.176 42.122 -90.191 42.159 -90.231 42.197 -90.323 42.211 -90.367 42.242 -90.407 42.263 -90.417 42.341 -90.427 42.361 -90.441 42.388 -90.491 42.421 -90.563 42.461 -90.605 42.475 -90.648 42.494 -90.651 42.509 -90.638 42.508 -90.419 42.504 -89.923 42.503 -89.834 42.497 -89.401 42.497 -89.359 42.491 -88.939 42.491 -88.764 42.489 -88.706 42.491 -88.297 42.489 -88.194 42.489 -87.797 42.314 -87.836 42.156 -87.761 42.059 -87.671 41.847 -87.612 41.723 -87.529 41.469 -87.532 41.301 -87.532 41.173 -87.531 41.009 -87.532 40.745 -87.532 40.494 -87.537 40.483 -87.535 40.166 -87.535 39.887 -87.535 39.609 -87.535 39.477 -87.538 39.351 -87.541 39.338 -87.597 39.307 -87.625 39.297 -87.611 39.281 -87.615 39.258 -87.606 39.248 -87.584 39.208 -87.588 39.198 -87.594 39.196 -87.607 39.168 -87.644 39.146 -87.671 39.131 -87.659 39.113 -87.662 39.103 -87.631 39.088 -87.631 39.084 -87.612 39.062 -87.585 38.995 -87.581 38.994 -87.591 38.977 -87.547 38.963 -87.533 38.931 -87.531 38.904 -87.539 38.869 -87.559 38.857 -87.551 38.795 -87.507 38.776 -87.519 38.769 -87.508 38.736 -87.508 38.685 -87.543 38.672 -87.588 38.642 -87.625 38.622 -87.628 38.599 -87.619 38.593 -87.641 38.573 -87.652 38.547 -87.672 38.515 -87.651 38.501 -87.653 38.504 -87.679 38.481 -87.692 38.466 -87.756 38.457 -87.758 38.445 -87.738 38.417 -87.748 38.378 -87.784 38.352 -87.834 38.286 -87.851 38.285 -87.863 38.316 -87.874 38.315 -87.883 38.301 -87.888 38.281 -87.914 38.302 -87.913 38.304 -87.925 38.241 -87.981 38.234 -87.986 38.201 -87.977 38.171 -87.932 38.157 -87.931 38.136 -87.951 38.131 -87.973 38.10Line truncated
|
||||
--></div>
|
||||
<div id="v3/topp-states-wfs.xml"><!--
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<wfs:FeatureCollection numberOfFeatures="3" timeStamp="2008-09-12T00:24:21.013-04:00" xsi:schemaLocation="http://www.openplans.org/topp http://sigma.openplans.org:80/geoserver/wfs?service=WFS&version=1.1.0&request=DescribeFeatureType&typeName=topp:states http://www.opengis.net/wfs http://sigma.openplans.org:80/geoserver/schemas/wfs/1.1.0/wfs.xsd" xmlns:ogc="http://www.opengis.net/ogc" xmlns:opengeo="http://open-geo.com" xmlns:tiger="http://www.census.gov" xmlns:wfs="http://www.opengis.net/wfs" xmlns:topp="http://www.openplans.org/topp" xmlns:seb="http://seb.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ows="http://www.opengis.net/ows" xmlns:gml="http://www.opengis.net/gml" xmlns:xlink="http://www.w3.org/1999/xlink"><gml:featureMembers><topp:states gml:id="states.1"><gml:boundedBy><gml:Envelope srsName="urn:x-ogc:def:crs:EPSG:4326"><gml:lowerCorner>36.986 -91.516</gml:lowerCorner><gml:upperCorner>42.509 -87.507</gml:upperCorner></gml:Envelope></gml:boundedBy><topp:the_geom><gml:MultiSurface srsName="urn:x-ogc:def:crs:EPSG:4326"><gml:surfaceMember><gml:Polygon><gml:exterior><gml:LinearRing><gml:posList>37.511 -88.071 37.476 -88.087 37.442 -88.311 37.409 -88.359 37.421 -88.419 37.401 -88.467 37.296 -88.511 37.257 -88.501 37.205 -88.451 37.156 -88.422 37.098 -88.451 37.072 -88.476 37.068 -88.491 37.064 -88.517 37.072 -88.559 37.109 -88.614 37.135 -88.688 37.141 -88.739 37.152 -88.746 37.202 -88.863 37.218 -88.932 37.221 -88.993 37.185 -89.065 37.112 -89.116 37.093 -89.146 37.064 -89.169 37.025 -89.174 36.998 -89.151 36.988 -89.129 36.986 -89.193 37.028 -89.211 37.041 -89.237 37.087 -89.264 37.091 -89.284 37.085 -89.303 37.061 -89.309 37.027 -89.264 37.008 -89.262 36.999 -89.282 37.009 -89.311 37.049 -89.382 37.099 -89.379 37.137 -89.423 37.165 -89.441 37.224 -89.468 37.253 -89.465 37.256 -89.489 37.276 -89.513 37.304 -89.513 37.329 -89.501 37.339 -89.468 37.355 -89.435 37.411 -89.427 37.453 -89.453 37.491 -89.494 37.571 -89.524 37.615 -89.513 37.651 -89.519 37.679 -89.513 37.694 -89.521 37.706 -89.581 37.745 -89.666 37.783 -89.675 37.804 -89.691 37.841 -89.728 37.905 -89.851 37.905 -89.861 37.891 -89.866 37.875 -89.901 37.878 -89.937 37.911 -89.978 37.963 -89.958 37.969 -90.011 37.993 -90.041 38.032 -90.119 38.053 -90.134 38.088 -90.207 38.122 -90.254 38.166 -90.289 38.188 -90.336 38.234 -90.364 38.323 -90.369 38.365 -90.358 38.391 -90.339 38.427 -90.301 38.518 -90.265 38.532 -90.261 38.562 -90.241 38.611 -90.183 38.658 -90.183 38.701 -90.202 38.723 -90.196 38.773 -90.163 38.785 -90.135 38.801 -90.121 38.831 -90.113 38.853 -90.132 38.914 -90.243 38.924 -90.278 38.924 -90.319 38.962 -90.413 38.959 -90.469 38.891 -90.531 38.871 -90.571 38.881 -90.627 38.935 -90.668 39.037 -90.706 39.058 -90.707 39.093 -90.691 39.144 -90.716 39.195 -90.718 39.224 -90.732 39.247 -90.738 39.296 -90.779 39.351 -90.851 39.401 -90.947 39.444 -91.036 39.473 -91.064 39.528 -91.093 39.552 -91.156 39.601 -91.203 39.685 -91.317 39.724 -91.367 39.761 -91.373 39.803 -91.381 39.863 -91.449 39.885 -91.451 39.901 -91.434 39.921 -91.431 39.946 -91.447 40.005 -91.487 40.066 -91.504 40.134 -91.516 40.201 -91.506 40.251 -91.498 40.309 -91.486 40.371 -91.448 40.386 -91.418 40.392 -91.385 40.402 -91.372 40.447 -91.385 40.503 -91.374 40.528 -91.382 40.547 -91.412 40.572 -91.411 40.603 -91.375 40.639 -91.262 40.643 -91.214 40.656 -91.162 40.682 -91.129 40.705 -91.119 40.761 -91.092 40.833 -91.088 40.879 -91.049 40.923 -90.983 40.951 -90.961 41.071 -90.954 41.104 -90.957 41.144 -90.991 41.165 -91.018 41.176 -91.056 41.231 -91.101 41.267 -91.102 41.334 -91.073 41.401 -91.055 41.423 -91.027 41.431 -91.001 41.421 -90.949 41.444 -90.844 41.449 -90.779 41.451 -90.708 41.462 -90.658 41.509 -90.601 41.525 -90.541 41.527 -90.454 41.543 -90.434 41.567 -90.423 41.586 -90.348 41.602 -90.339 41.649 -90.341 41.722 -90.326 41.756 -90.304 41.781 -90.255 41.806 -90.195 41.931 -90.154 41.983 -90.142 42.033 -90.151 42.061 -90.168 42.103 -90.166 42.121 -90.176 42.122 -90.191 42.159 -90.231 42.197 -90.323 42.211 -90.367 42.242 -90.407 42.263 -90.417 42.341 -90.427 42.361 -90.441 42.388 -90.491 42.421 -90.563 42.461 -90.605 42.475 -90.648 42.494 -90.651 42.509 -90.638 42.508 -90.419 42.504 -89.923 42.503 -89.834 42.497 -89.401 42.497 -89.359 42.491 -88.939 42.491 -88.764 42.489 -88.706 42.491 -88.297 42.489 -88.194 42.489 -87.797 42.314 -87.836 42.156 -87.761 42.059 -87.671 41.847 -87.612 41.723 -87.529 41.469 -87.532 41.301 -87.532 41.173 -87.531 41.009 -87.532 40.745 -87.532 40.494 -87.537 40.483 -87.535 40.166 -87.535 39.887 -87.535 39.609 -87.535 39.477 -87.538 39.351 -87.541 39.338 -87.597 39.307 -87.625 39.297 -87.611 39.281 -87.615 39.258 -87.606 39.248 -87.584 39.208 -87.588 39.198 -87.594 39.196 -87.607 39.168 -87.644 39.146 -87.671 39.131 -87.659 39.113 -87.662 39.103 -87.631 39.088 -87.631 39.084 -87.612 39.062 -87.585 38.995 -87.581 38.994 -87.591 38.977 -87.547 38.963 -87.533 38.931 -87.531 38.904 -87.539 38.869 -87.559 38.857 -87Line truncated
|
||||
--></div>
|
||||
<div id="v2/point-coord.xml"><!--
|
||||
<gml:Point xmlns:gml="http://www.opengis.net/gml" srsName="foo">
|
||||
<gml:coord>
|
||||
<gml:X>1</gml:X>
|
||||
<gml:Y>2</gml:Y>
|
||||
</gml:coord>
|
||||
</gml:Point>
|
||||
--></div>
|
||||
<div id="v2/point-coordinates.xml"><!--
|
||||
<gml:Point xmlns:gml="http://www.opengis.net/gml" srsName="foo">
|
||||
<gml:coordinates decimal="." cs="," ts=" ">1,2</gml:coordinates>
|
||||
</gml:Point>
|
||||
--></div>
|
||||
<div id="v2/linestring-coord.xml"><!--
|
||||
<gml:LineString xmlns:gml="http://www.opengis.net/gml" srsName="foo">
|
||||
<gml:coord>
|
||||
<gml:X>1</gml:X>
|
||||
<gml:Y>2</gml:Y>
|
||||
</gml:coord>
|
||||
<gml:coord>
|
||||
<gml:X>3</gml:X>
|
||||
<gml:Y>4</gml:Y>
|
||||
</gml:coord>
|
||||
</gml:LineString>
|
||||
--></div>
|
||||
<div id="v2/linestring-coordinates.xml"><!--
|
||||
<gml:LineString xmlns:gml="http://www.opengis.net/gml" srsName="foo">
|
||||
<gml:coordinates decimal="." cs="," ts=" ">1,2 3,4</gml:coordinates>
|
||||
</gml:LineString>
|
||||
--></div>
|
||||
<div id="v2/multipoint-coord.xml"><!--
|
||||
<gml:MultiPoint xmlns:gml="http://www.opengis.net/gml" srsName="foo">
|
||||
<gml:pointMember>
|
||||
<gml:Point>
|
||||
<gml:coord>
|
||||
<gml:X>1</gml:X>
|
||||
<gml:Y>2</gml:Y>
|
||||
</gml:coord>
|
||||
</gml:Point>
|
||||
</gml:pointMember>
|
||||
<gml:pointMember>
|
||||
<gml:Point>
|
||||
<gml:coord>
|
||||
<gml:X>2</gml:X>
|
||||
<gml:Y>3</gml:Y>
|
||||
</gml:coord>
|
||||
</gml:Point>
|
||||
</gml:pointMember>
|
||||
<gml:pointMember>
|
||||
<gml:Point>
|
||||
<gml:coord>
|
||||
<gml:X>3</gml:X>
|
||||
<gml:Y>4</gml:Y>
|
||||
</gml:coord>
|
||||
</gml:Point>
|
||||
</gml:pointMember>
|
||||
</gml:MultiPoint>
|
||||
--></div>
|
||||
<div id="v2/multipoint-coordinates.xml"><!--
|
||||
<gml:MultiPoint xmlns:gml="http://www.opengis.net/gml" srsName="foo">
|
||||
<gml:pointMember>
|
||||
<gml:Point>
|
||||
<gml:coordinates decimal="." cs="," ts=" ">1,2</gml:coordinates>
|
||||
</gml:Point>
|
||||
</gml:pointMember>
|
||||
<gml:pointMember>
|
||||
<gml:Point>
|
||||
<gml:coordinates decimal="." cs="," ts=" ">2,3</gml:coordinates>
|
||||
</gml:Point>
|
||||
</gml:pointMember>
|
||||
<gml:pointMember>
|
||||
<gml:Point>
|
||||
<gml:coordinates decimal="." cs="," ts=" ">3,4</gml:coordinates>
|
||||
</gml:Point>
|
||||
</gml:pointMember>
|
||||
</gml:MultiPoint>
|
||||
--></div>
|
||||
<div id="v2/multilinestring-coord.xml"><!--
|
||||
<gml:MultiLineString xmlns:gml="http://www.opengis.net/gml" srsName="foo">
|
||||
<gml:lineStringMember>
|
||||
<gml:LineString>
|
||||
<gml:coord>
|
||||
<gml:X>1</gml:X>
|
||||
<gml:Y>2</gml:Y>
|
||||
</gml:coord>
|
||||
<gml:coord>
|
||||
<gml:X>2</gml:X>
|
||||
<gml:Y>3</gml:Y>
|
||||
</gml:coord>
|
||||
</gml:LineString>
|
||||
</gml:lineStringMember>
|
||||
<gml:lineStringMember>
|
||||
<gml:LineString>
|
||||
<gml:coord>
|
||||
<gml:X>3</gml:X>
|
||||
<gml:Y>4</gml:Y>
|
||||
</gml:coord>
|
||||
<gml:coord>
|
||||
<gml:X>4</gml:X>
|
||||
<gml:Y>5</gml:Y>
|
||||
</gml:coord>
|
||||
</gml:LineString>
|
||||
</gml:lineStringMember>
|
||||
</gml:MultiLineString>
|
||||
--></div>
|
||||
<div id="v2/multilinestring-coordinates.xml"><!--
|
||||
<gml:MultiLineString xmlns:gml="http://www.opengis.net/gml" srsName="foo">
|
||||
<gml:lineStringMember>
|
||||
<gml:LineString>
|
||||
<gml:coordinates decimal="." cs="," ts=" ">1,2 2,3</gml:coordinates>
|
||||
</gml:LineString>
|
||||
</gml:lineStringMember>
|
||||
<gml:lineStringMember>
|
||||
<gml:LineString>
|
||||
<gml:coordinates decimal="." cs="," ts=" ">3,4 4,5</gml:coordinates>
|
||||
</gml:LineString>
|
||||
</gml:lineStringMember>
|
||||
</gml:MultiLineString>
|
||||
--></div>
|
||||
</body>
|
||||
</html>
|
||||
+29
-25
@@ -291,35 +291,39 @@
|
||||
t.ok(found === false, "returns false for bad attribute");
|
||||
}
|
||||
|
||||
function test_getNamespacePrefix(t) {
|
||||
t.plan(6);
|
||||
function test_namespaces(t) {
|
||||
t.plan(2);
|
||||
|
||||
// test that getNamespacePrefix returns null with no ns defined
|
||||
var format = new OpenLayers.Format.XML();
|
||||
var got = format.getNamespacePrefix("http://example.com/foo");
|
||||
t.eq(got, null, "returns null when no namespaces are defined");
|
||||
var format = new OpenLayers.Format.XML({
|
||||
namespaces: {
|
||||
"def": "http://example.com/default",
|
||||
"foo": "http://example.com/foo",
|
||||
"bar": "http://example.com/bar"
|
||||
},
|
||||
defaultPrefix: "def"
|
||||
});
|
||||
|
||||
format.defaultPrefix = "def";
|
||||
format.namespaces = {
|
||||
"def": "http://example.com/default",
|
||||
"foo": "http://example.com/foo",
|
||||
"bar": "http://example.com/bar"
|
||||
};
|
||||
// test that prototype has not been altered
|
||||
t.eq(OpenLayers.Format.XML.prototype.namespaces, null,
|
||||
"setting namespaces at construction does not modify prototype");
|
||||
|
||||
var cases = [
|
||||
{uri: null, expect: "def"},
|
||||
{uri: "http://example.com/default", expect: "def"},
|
||||
{uri: "http://example.com/foo", expect: "foo"},
|
||||
{uri: "http://example.com/bar", expect: "bar"},
|
||||
{uri: "http://example.com/nothing", expect: null}
|
||||
];
|
||||
// test that namespaceAlias has been set
|
||||
t.eq(format.namespaceAlias["http://example.com/foo"], "foo",
|
||||
"namespaceAlias mapping has been set");
|
||||
|
||||
var test;
|
||||
for(var i=0; i<cases.length; ++i) {
|
||||
test = cases[i];
|
||||
t.eq(format.getNamespacePrefix(test.uri), test.expect,
|
||||
"uri: " + test.uri + " works");
|
||||
}
|
||||
}
|
||||
|
||||
function test_setNamespace(t) {
|
||||
t.plan(3);
|
||||
|
||||
var format = new OpenLayers.Format.XML();
|
||||
|
||||
// test that namespaces is an object
|
||||
t.ok(format.namespaces instanceof Object, "empty namespace object set");
|
||||
|
||||
format.setNamespace("foo", "http://example.com/foo");
|
||||
t.eq(format.namespaces["foo"], "http://example.com/foo", "alias -> uri mapping set");
|
||||
t.eq(format.namespaceAlias["http://example.com/foo"], "foo", "uri -> alias mapping set");
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -43,6 +43,8 @@
|
||||
<li>Format/GeoJSON.html</li>
|
||||
<li>Format/GeoRSS.html</li>
|
||||
<li>Format/GML.html</li>
|
||||
<li>Format/GML/v2.html</li>
|
||||
<li>Format/GML/v3.html</li>
|
||||
<li>Format/GPX.html</li>
|
||||
<li>Format/JSON.html</li>
|
||||
<li>Format/KML.html</li>
|
||||
|
||||
Reference in new issue
Block a user