Changes to GML 2 and 3. GML 3 now supports gml:Curve, gml:Surface, and the multis - with options to write the deprecated elements. Now reading boundedBy on features as geometry.bounds. Corrected lowerCorner and upperCorner elements. Added ability to build without the old gml parser. r=ahocevar,adube (closes #1918)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@8808 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -7,6 +7,14 @@
|
||||
* @requires OpenLayers/Format/GML.js
|
||||
*/
|
||||
|
||||
/**
|
||||
* Though required in the full build, if the GML format is excluded, we set
|
||||
* the namespace here.
|
||||
*/
|
||||
if(!OpenLayers.Format.GML) {
|
||||
OpenLayers.Format.GML = {};
|
||||
}
|
||||
|
||||
/**
|
||||
* Class: OpenLayers.Format.GML.Base
|
||||
* Superclass for GML parsers.
|
||||
@@ -79,6 +87,13 @@ OpenLayers.Format.GML.Base = OpenLayers.Class(OpenLayers.Format.XML, {
|
||||
*/
|
||||
xy: true,
|
||||
|
||||
/**
|
||||
* Property: geometryTypes
|
||||
* {Object} Maps OpenLayers geometry class names to GML element names.
|
||||
* Use <setGeometryTypes> before accessing this property.
|
||||
*/
|
||||
geometryTypes: null,
|
||||
|
||||
/**
|
||||
* Property: regExes
|
||||
* Compiled regular expressions for manipulating strings.
|
||||
@@ -108,6 +123,7 @@ OpenLayers.Format.GML.Base = OpenLayers.Class(OpenLayers.Format.XML, {
|
||||
initialize: function(options) {
|
||||
OpenLayers.Format.XML.prototype.initialize.apply(this, [options]);
|
||||
this.setNamespace("feature", options.featureNS);
|
||||
this.setGeometryTypes();
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -168,6 +184,16 @@ OpenLayers.Format.GML.Base = OpenLayers.Class(OpenLayers.Format.XML, {
|
||||
"featureMembers": function(node, obj) {
|
||||
this.readChildNodes(node, obj);
|
||||
},
|
||||
"name": function(node, obj) {
|
||||
obj.name = this.getChildValue(node);
|
||||
},
|
||||
"boundedBy": function(node, obj) {
|
||||
var container = {};
|
||||
this.readChildNodes(node, container);
|
||||
if(container.components && container.components.length > 0) {
|
||||
obj.bounds = container.components[0];
|
||||
}
|
||||
},
|
||||
"Point": function(node, container) {
|
||||
var obj = {points: []};
|
||||
this.readChildNodes(node, obj);
|
||||
@@ -314,6 +340,10 @@ OpenLayers.Format.GML.Base = OpenLayers.Class(OpenLayers.Format.XML, {
|
||||
"_typeName": function(node, obj) {
|
||||
var container = {components: [], attributes: {}};
|
||||
this.readChildNodes(node, container);
|
||||
// look for common gml namespaced elements
|
||||
if(container.name) {
|
||||
container.attributes.name = container.name;
|
||||
}
|
||||
var feature = new OpenLayers.Feature.Vector(
|
||||
container.components[0], container.attributes
|
||||
);
|
||||
@@ -327,7 +357,10 @@ OpenLayers.Format.GML.Base = OpenLayers.Class(OpenLayers.Format.XML, {
|
||||
feature.geometry.transform(
|
||||
this.externalProjection, this.internalProjection
|
||||
);
|
||||
}
|
||||
}
|
||||
if(container.bounds) {
|
||||
feature.geometry.bounds = container.bounds;
|
||||
}
|
||||
obj.features.push(feature);
|
||||
},
|
||||
"_geometry": function(node, obj) {
|
||||
@@ -499,17 +532,19 @@ OpenLayers.Format.GML.Base = OpenLayers.Class(OpenLayers.Format.XML, {
|
||||
},
|
||||
|
||||
/**
|
||||
* Property: geometryTypes
|
||||
* {Object} Maps OpenLayers geometry class names to GML element names.
|
||||
* Function: setGeometryTypes
|
||||
* Sets the <geometryTypes> mapping.
|
||||
*/
|
||||
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"
|
||||
setGeometryTypes: function() {
|
||||
this.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"
|
||||
|
||||
@@ -22,6 +22,46 @@ OpenLayers.Format.GML.v3 = OpenLayers.Class(OpenLayers.Format.GML.Base, {
|
||||
*/
|
||||
schemaLocation: "http://www.opengis.net/gml http://schemas.opengis.net/gml/3.1.1/profiles/gmlsfProfile/1.0.0/gmlsf.xsd",
|
||||
|
||||
/**
|
||||
* Property: curve
|
||||
* {Boolean} Write gml:Curve instead of gml:LineString elements. This also
|
||||
* affects the elements in multi-part geometries. Default is false.
|
||||
* To write gml:Curve elements instead of gml:LineString, set curve
|
||||
* to true in the options to the contstructor (cannot be changed after
|
||||
* instantiation).
|
||||
*/
|
||||
curve: false,
|
||||
|
||||
/**
|
||||
* Property: multiCurve
|
||||
* {Boolean} Write gml:MultiCurve instead of gml:MultiLineString. Since
|
||||
* the latter is deprecated in GML 3, the default is true. To write
|
||||
* gml:MultiLineString instead of gml:MultiCurve, set multiCurve to
|
||||
* false in the options to the constructor (cannot be changed after
|
||||
* instantiation).
|
||||
*/
|
||||
multiCurve: true,
|
||||
|
||||
/**
|
||||
* Property: surface
|
||||
* {Boolean} Write gml:Surface instead of gml:Polygon elements. This also
|
||||
* affects the elements in multi-part geometries. Default is false.
|
||||
* To write gml:Surface elements instead of gml:Polygon, set surface
|
||||
* to true in the options to the contstructor (cannot be changed after
|
||||
* instantiation).
|
||||
*/
|
||||
surface: false,
|
||||
|
||||
/**
|
||||
* Property: multiSurface
|
||||
* {Boolean} Write gml:multiSurface instead of gml:MultiPolygon. Since
|
||||
* the latter is deprecated in GML 3, the default is true. To write
|
||||
* gml:MultiPolygon instead of gml:multiSurface, set multiSurface to
|
||||
* false in the options to the constructor (cannot be changed after
|
||||
* instantiation).
|
||||
*/
|
||||
multiSurface: true,
|
||||
|
||||
/**
|
||||
* Constructor: OpenLayers.Format.GML.v3
|
||||
* Create a parser for GML v3.
|
||||
@@ -52,6 +92,26 @@ OpenLayers.Format.GML.v3 = OpenLayers.Class(OpenLayers.Format.GML.Base, {
|
||||
"featureMembers": function(node, obj) {
|
||||
this.readChildNodes(node, obj);
|
||||
},
|
||||
"Curve": function(node, container) {
|
||||
var obj = {points: []};
|
||||
this.readChildNodes(node, obj);
|
||||
if(!container.components) {
|
||||
container.components = [];
|
||||
}
|
||||
container.components.push(
|
||||
new OpenLayers.Geometry.LineString(obj.points)
|
||||
);
|
||||
},
|
||||
"segments": function(node, obj) {
|
||||
this.readChildNodes(node, obj);
|
||||
},
|
||||
"LineStringSegment": function(node, container) {
|
||||
var obj = {};
|
||||
this.readChildNodes(node, obj);
|
||||
if(obj.points) {
|
||||
Array.prototype.push.apply(container.points, obj.points);
|
||||
}
|
||||
},
|
||||
"pos": function(node, obj) {
|
||||
var str = this.getChildValue(node).replace(
|
||||
this.regExes.trimSpace, ""
|
||||
@@ -90,6 +150,15 @@ OpenLayers.Format.GML.v3 = OpenLayers.Class(OpenLayers.Format.GML.Base, {
|
||||
}
|
||||
obj.points = points;
|
||||
},
|
||||
"Surface": function(node, obj) {
|
||||
this.readChildNodes(node, obj);
|
||||
},
|
||||
"patches": function(node, obj) {
|
||||
this.readChildNodes(node, obj);
|
||||
},
|
||||
"PolygonPatch": function(node, obj) {
|
||||
this.readers.gml.Polygon.apply(this, [node, obj]);
|
||||
},
|
||||
"exterior": function(node, container) {
|
||||
var obj = {};
|
||||
this.readChildNodes(node, obj);
|
||||
@@ -100,6 +169,18 @@ OpenLayers.Format.GML.v3 = OpenLayers.Class(OpenLayers.Format.GML.Base, {
|
||||
this.readChildNodes(node, obj);
|
||||
container.inner.push(obj.components[0]);
|
||||
},
|
||||
"MultiCurve": function(node, container) {
|
||||
var obj = {components: []};
|
||||
this.readChildNodes(node, obj);
|
||||
if(obj.components.length > 0) {
|
||||
container.components = [
|
||||
new OpenLayers.Geometry.MultiLineString(obj.components)
|
||||
];
|
||||
}
|
||||
},
|
||||
"curveMember": function(node, obj) {
|
||||
this.readChildNodes(node, obj);
|
||||
},
|
||||
"MultiSurface": function(node, container) {
|
||||
var obj = {components: []};
|
||||
this.readChildNodes(node, obj);
|
||||
@@ -141,12 +222,12 @@ OpenLayers.Format.GML.v3 = OpenLayers.Class(OpenLayers.Format.GML.Base, {
|
||||
},
|
||||
"lowerCorner": function(node, container) {
|
||||
var obj = {};
|
||||
this.readChildNodes(node, obj);
|
||||
this.readers.gml.pos.apply(this, [node, obj]);
|
||||
container.points[0] = obj.points[0];
|
||||
},
|
||||
"upperCorner": function(node, container) {
|
||||
var obj = {};
|
||||
this.readChildNodes(node, obj);
|
||||
this.readers.gml.pos.apply(this, [node, obj]);
|
||||
container.points[1] = obj.points[0];
|
||||
}
|
||||
}, OpenLayers.Format.GML.Base.prototype.readers["gml"]),
|
||||
@@ -215,6 +296,21 @@ OpenLayers.Format.GML.v3 = OpenLayers.Class(OpenLayers.Format.GML.Base, {
|
||||
this.writeNode("posList", geometry.components, node);
|
||||
return node;
|
||||
},
|
||||
"Curve": function(geometry) {
|
||||
var node = this.createElementNSPlus("gml:Curve");
|
||||
this.writeNode("segments", geometry, node);
|
||||
return node;
|
||||
},
|
||||
"segments": function(geometry) {
|
||||
var node = this.createElementNSPlus("gml:segments");
|
||||
this.writeNode("LineStringSegment", geometry, node);
|
||||
return node;
|
||||
},
|
||||
"LineStringSegment": function(geometry) {
|
||||
var node = this.createElementNSPlus("gml:LineStringSegment");
|
||||
this.writeNode("posList", geometry.components, node);
|
||||
return node;
|
||||
},
|
||||
"posList": function(points) {
|
||||
// only 2d for simple features profile
|
||||
var len = points.length;
|
||||
@@ -232,6 +328,28 @@ OpenLayers.Format.GML.v3 = OpenLayers.Class(OpenLayers.Format.GML.Base, {
|
||||
value: parts.join(" ")
|
||||
});
|
||||
},
|
||||
"Surface": function(geometry) {
|
||||
var node = this.createElementNSPlus("gml:Surface");
|
||||
this.writeNode("patches", geometry, node);
|
||||
return node;
|
||||
},
|
||||
"patches": function(geometry) {
|
||||
var node = this.createElementNSPlus("gml:patches");
|
||||
this.writeNode("PolygonPatch", geometry, node);
|
||||
return node;
|
||||
},
|
||||
"PolygonPatch": function(geometry) {
|
||||
var node = this.createElementNSPlus("gml:PolygonPatch", {
|
||||
attributes: {interpolation: "planar"}
|
||||
});
|
||||
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;
|
||||
},
|
||||
"Polygon": function(geometry) {
|
||||
var node = this.createElementNSPlus("gml:Polygon");
|
||||
this.writeNode("exterior", geometry.components[0], node);
|
||||
@@ -257,6 +375,38 @@ OpenLayers.Format.GML.v3 = OpenLayers.Class(OpenLayers.Format.GML.Base, {
|
||||
this.writeNode("posList", ring.components, node);
|
||||
return node;
|
||||
},
|
||||
"MultiCurve": function(geometry) {
|
||||
var node = this.createElementNSPlus("gml:MultiCurve");
|
||||
for(var i=0, len=geometry.components.length; i<len; ++i) {
|
||||
this.writeNode("curveMember", geometry.components[i], node);
|
||||
}
|
||||
return node;
|
||||
},
|
||||
"curveMember": function(geometry) {
|
||||
var node = this.createElementNSPlus("gml:curveMember");
|
||||
if(this.curve) {
|
||||
this.writeNode("Curve", geometry, node);
|
||||
} else {
|
||||
this.writeNode("LineString", geometry, node);
|
||||
}
|
||||
return node;
|
||||
},
|
||||
"MultiSurface": function(geometry) {
|
||||
var node = this.createElementNSPlus("gml:MultiSurface");
|
||||
for(var i=0, len=geometry.components.length; i<len; ++i) {
|
||||
this.writeNode("surfaceMember", geometry.components[i], node);
|
||||
}
|
||||
return node;
|
||||
},
|
||||
"surfaceMember": function(polygon) {
|
||||
var node = this.createElementNSPlus("gml:surfaceMember");
|
||||
if(this.surface) {
|
||||
this.writeNode("Surface", polygon, node);
|
||||
} else {
|
||||
this.writeNode("Polygon", polygon, node);
|
||||
}
|
||||
return node;
|
||||
},
|
||||
"Envelope": function(bounds) {
|
||||
var node = this.createElementNSPlus("gml:Envelope");
|
||||
this.writeNode("lowerCorner", bounds, node);
|
||||
@@ -268,19 +418,43 @@ OpenLayers.Format.GML.v3 = OpenLayers.Class(OpenLayers.Format.GML.Base, {
|
||||
return node;
|
||||
},
|
||||
"lowerCorner": function(bounds) {
|
||||
var node = this.createElementNSPlus("gml:lowerCorner");
|
||||
this.writeNode("pos", {x: bounds.left, y: bounds.bottom}, node);
|
||||
return node;
|
||||
// only 2d for simple features profile
|
||||
var pos = (this.xy) ?
|
||||
(bounds.left + " " + bounds.bottom) :
|
||||
(bounds.bottom + " " + bounds.left);
|
||||
return this.createElementNSPlus("gml:lowerCorner", {
|
||||
value: pos
|
||||
});
|
||||
},
|
||||
"upperCorner": function(bounds) {
|
||||
var node = this.createElementNSPlus("gml:upperCorner");
|
||||
this.writeNode("pos", {x: bounds.right, y: bounds.top}, node);
|
||||
return node;
|
||||
// only 2d for simple features profile
|
||||
var pos = (this.xy) ?
|
||||
(bounds.right + " " + bounds.top) :
|
||||
(bounds.top + " " + bounds.right);
|
||||
return this.createElementNSPlus("gml:upperCorner", {
|
||||
value: pos
|
||||
});
|
||||
}
|
||||
}, OpenLayers.Format.GML.Base.prototype.writers["gml"]),
|
||||
"feature": OpenLayers.Format.GML.Base.prototype.writers["feature"],
|
||||
"wfs": OpenLayers.Format.GML.Base.prototype.writers["wfs"]
|
||||
},
|
||||
|
||||
/**
|
||||
* Function: setGeometryTypes
|
||||
* Sets the <geometryTypes> mapping.
|
||||
*/
|
||||
setGeometryTypes: function() {
|
||||
this.geometryTypes = {
|
||||
"OpenLayers.Geometry.Point": "Point",
|
||||
"OpenLayers.Geometry.MultiPoint": "MultiPoint",
|
||||
"OpenLayers.Geometry.LineString": (this.curve === true) ? "Curve": "LineString",
|
||||
"OpenLayers.Geometry.MultiLineString": (this.multiCurve === false) ? "MultiLineString" : "MultiCurve",
|
||||
"OpenLayers.Geometry.Polygon": (this.surface === true) ? "Surface" : "Polygon",
|
||||
"OpenLayers.Geometry.MultiPolygon": (this.multiSurface === false) ? "MultiPolygon" : "MultiSurface",
|
||||
"OpenLayers.Geometry.Collection": "GeometryCollection"
|
||||
};
|
||||
},
|
||||
|
||||
CLASS_NAME: "OpenLayers.Format.GML.v3"
|
||||
|
||||
|
||||
@@ -209,14 +209,19 @@ var cases = {
|
||||
OpenLayers.Util.extend(cases, {
|
||||
"v3/point.xml": cases["v2/point-coordinates.xml"],
|
||||
"v3/linestring.xml": cases["v2/linestring-coordinates.xml"],
|
||||
"v3/curve.xml": cases["v2/linestring-coordinates.xml"],
|
||||
"v3/polygon.xml": cases["v2/polygon-coordinates.xml"],
|
||||
"v3/surface.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/multicurve-singular.xml": cases["v2/multilinestring-coordinates.xml"],
|
||||
"v3/multicurve-curve.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/multisurface-surface.xml": cases["v2/multipolygon-coordinates.xml"],
|
||||
"v3/envelope.xml": cases["v2/box-coordinates.xml"]
|
||||
});
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user