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:
@@ -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"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user