Respect the srsDimension attribute.

This also fixes http://trac.osgeo.org/openlayers/ticket/2762. Note: it seems there is no "dimension" attribute for posList in the spec. This attribute name is only used in some examples of the GML 3.1 specification, but it is not mentioned in any of the XSDs.
This commit is contained in:
ahocevar
2012-06-14 12:34:45 +02:00
parent 704f36639b
commit fa90a42806
4 changed files with 37 additions and 7 deletions
+17 -1
View File
@@ -230,7 +230,7 @@ OpenLayers.Format.GML.Base = OpenLayers.Class(OpenLayers.Format.XML, {
} }
return OpenLayers.Format.XML.prototype.readNode.apply(this, [node, obj]); return OpenLayers.Format.XML.prototype.readNode.apply(this, [node, obj]);
}, },
/** /**
* Property: readers * Property: readers
* Contains public functions, grouped by namespace prefix, that will * Contains public functions, grouped by namespace prefix, that will
@@ -241,6 +241,15 @@ OpenLayers.Format.GML.Base = OpenLayers.Class(OpenLayers.Format.XML, {
*/ */
readers: { readers: {
"gml": { "gml": {
// Part of the v3 spec, but defined here for common readers.
// Read-only for now.
"_srsReferenceGroup": function(node, obj, container) {
var dim = parseInt(node.getAttribute("srsDimension"), 10) ||
(container && container.srsDimension);
if (dim) {
obj.srsDimension = dim;
}
},
"featureMember": function(node, obj) { "featureMember": function(node, obj) {
this.readChildNodes(node, obj); this.readChildNodes(node, obj);
}, },
@@ -309,6 +318,7 @@ OpenLayers.Format.GML.Base = OpenLayers.Class(OpenLayers.Format.XML, {
}, },
"MultiPoint": function(node, container) { "MultiPoint": function(node, container) {
var obj = {components: []}; var obj = {components: []};
this.readers.gml._srsReferenceGroup.apply(this, [node, obj, container]);
this.readChildNodes(node, obj); this.readChildNodes(node, obj);
container.components = [ container.components = [
new OpenLayers.Geometry.MultiPoint(obj.components) new OpenLayers.Geometry.MultiPoint(obj.components)
@@ -319,6 +329,7 @@ OpenLayers.Format.GML.Base = OpenLayers.Class(OpenLayers.Format.XML, {
}, },
"LineString": function(node, container) { "LineString": function(node, container) {
var obj = {}; var obj = {};
this.readers.gml._srsReferenceGroup.apply(this, [node, obj, container]);
this.readChildNodes(node, obj); this.readChildNodes(node, obj);
if(!container.components) { if(!container.components) {
container.components = []; container.components = [];
@@ -329,6 +340,7 @@ OpenLayers.Format.GML.Base = OpenLayers.Class(OpenLayers.Format.XML, {
}, },
"MultiLineString": function(node, container) { "MultiLineString": function(node, container) {
var obj = {components: []}; var obj = {components: []};
this.readers.gml._srsReferenceGroup.apply(this, [node, obj, container]);
this.readChildNodes(node, obj); this.readChildNodes(node, obj);
container.components = [ container.components = [
new OpenLayers.Geometry.MultiLineString(obj.components) new OpenLayers.Geometry.MultiLineString(obj.components)
@@ -339,6 +351,7 @@ OpenLayers.Format.GML.Base = OpenLayers.Class(OpenLayers.Format.XML, {
}, },
"Polygon": function(node, container) { "Polygon": function(node, container) {
var obj = {outer: null, inner: []}; var obj = {outer: null, inner: []};
this.readers.gml._srsReferenceGroup.apply(this, [node, obj, container]);
this.readChildNodes(node, obj); this.readChildNodes(node, obj);
obj.inner.unshift(obj.outer); obj.inner.unshift(obj.outer);
if(!container.components) { if(!container.components) {
@@ -350,6 +363,7 @@ OpenLayers.Format.GML.Base = OpenLayers.Class(OpenLayers.Format.XML, {
}, },
"LinearRing": function(node, obj) { "LinearRing": function(node, obj) {
var container = {}; var container = {};
this.readers.gml._srsReferenceGroup.apply(this, [node, container]);
this.readChildNodes(node, container); this.readChildNodes(node, container);
obj.components = [new OpenLayers.Geometry.LinearRing( obj.components = [new OpenLayers.Geometry.LinearRing(
container.points container.points
@@ -357,6 +371,7 @@ OpenLayers.Format.GML.Base = OpenLayers.Class(OpenLayers.Format.XML, {
}, },
"MultiPolygon": function(node, container) { "MultiPolygon": function(node, container) {
var obj = {components: []}; var obj = {components: []};
this.readers.gml._srsReferenceGroup.apply(this, [node, obj, container]);
this.readChildNodes(node, obj); this.readChildNodes(node, obj);
container.components = [ container.components = [
new OpenLayers.Geometry.MultiPolygon(obj.components) new OpenLayers.Geometry.MultiPolygon(obj.components)
@@ -367,6 +382,7 @@ OpenLayers.Format.GML.Base = OpenLayers.Class(OpenLayers.Format.XML, {
}, },
"GeometryCollection": function(node, container) { "GeometryCollection": function(node, container) {
var obj = {components: []}; var obj = {components: []};
this.readers.gml._srsReferenceGroup.apply(this, [node, obj, container]);
this.readChildNodes(node, obj); this.readChildNodes(node, obj);
container.components = [ container.components = [
new OpenLayers.Geometry.Collection(obj.components) new OpenLayers.Geometry.Collection(obj.components)
+5 -1
View File
@@ -95,6 +95,7 @@ OpenLayers.Format.GML.v3 = OpenLayers.Class(OpenLayers.Format.GML.Base, {
}, },
"Curve": function(node, container) { "Curve": function(node, container) {
var obj = {points: []}; var obj = {points: []};
this.readers.gml._srsReferenceGroup.apply(this, [node, obj, container]);
this.readChildNodes(node, obj); this.readChildNodes(node, obj);
if(!container.components) { if(!container.components) {
container.components = []; container.components = [];
@@ -135,7 +136,8 @@ OpenLayers.Format.GML.v3 = OpenLayers.Class(OpenLayers.Format.GML.Base, {
this.regExes.trimSpace, "" this.regExes.trimSpace, ""
); );
var coords = str.split(this.regExes.splitSpace); var coords = str.split(this.regExes.splitSpace);
var dim = parseInt(node.getAttribute("dimension")) || 2; var dim = obj.srsDimension ||
parseInt(node.getAttribute("dimension") || node.getAttribute("srsDimension"), 10) || 2;
var j, x, y, z; var j, x, y, z;
var numPoints = coords.length / dim; var numPoints = coords.length / dim;
var points = new Array(numPoints); var points = new Array(numPoints);
@@ -172,6 +174,7 @@ OpenLayers.Format.GML.v3 = OpenLayers.Class(OpenLayers.Format.GML.Base, {
}, },
"MultiCurve": function(node, container) { "MultiCurve": function(node, container) {
var obj = {components: []}; var obj = {components: []};
this.readers.gml._srsReferenceGroup.apply(this, [node, obj, container]);
this.readChildNodes(node, obj); this.readChildNodes(node, obj);
if(obj.components.length > 0) { if(obj.components.length > 0) {
container.components = [ container.components = [
@@ -184,6 +187,7 @@ OpenLayers.Format.GML.v3 = OpenLayers.Class(OpenLayers.Format.GML.Base, {
}, },
"MultiSurface": function(node, container) { "MultiSurface": function(node, container) {
var obj = {components: []}; var obj = {components: []};
this.readers.gml._srsReferenceGroup.apply(this, [node, obj, container]);
this.readChildNodes(node, obj); this.readChildNodes(node, obj);
if(obj.components.length > 0) { if(obj.components.length > 0) {
container.components = [ container.components = [
+8 -3
View File
@@ -198,14 +198,19 @@ var cases = {
]) ])
]) ])
]), ]),
"v2/box-coord.xml": new OpenLayers.Bounds(1, 2, 3, 4), "v2/box-coord.xml": new OpenLayers.Bounds(1, 2, 3, 4),
"v2/box-coordinates.xml": new OpenLayers.Bounds(1, 2, 3, 4) "v2/box-coordinates.xml": new OpenLayers.Bounds(1, 2, 3, 4),
"v3/linestring3d.xml": new OpenLayers.Geometry.LineString([
new OpenLayers.Geometry.Point(1, 2, 3),
new OpenLayers.Geometry.Point(4, 5, 6)
])
}; };
// cases for v3 use the same geometries // some cases for v3 use the same geometries
OpenLayers.Util.extend(cases, { OpenLayers.Util.extend(cases, {
"v3/point.xml": cases["v2/point-coordinates.xml"], "v3/point.xml": cases["v2/point-coordinates.xml"],
"v3/linestring.xml": cases["v2/linestring-coordinates.xml"], "v3/linestring.xml": cases["v2/linestring-coordinates.xml"],
+7 -2
View File
@@ -10,8 +10,8 @@
"v2/linestring-coord.xml", "v2/linestring-coordinates.xml", "v2/linestring-coord.xml", "v2/linestring-coordinates.xml",
"v2/multipoint-coord.xml", "v2/multipoint-coordinates.xml", "v2/multipoint-coord.xml", "v2/multipoint-coordinates.xml",
"v2/multilinestring-coord.xml", "v2/multilinestring-coordinates.xml", "v2/multilinestring-coord.xml", "v2/multilinestring-coordinates.xml",
"v3/point.xml", "v3/linestring.xml", "v3/curve.xml", "v3/point.xml", "v3/linestring.xml", "v3/linestring3d.xml",
"v3/polygon.xml", "v3/surface.xml", "v3/curve.xml", "v3/polygon.xml", "v3/surface.xml",
"v3/multipoint-singular.xml", "v3/multipoint-plural.xml", "v3/multipoint-singular.xml", "v3/multipoint-plural.xml",
"v3/multilinestring-singular.xml", "v3/multilinestring-plural.xml", "v3/multilinestring-singular.xml", "v3/multilinestring-plural.xml",
"v3/multicurve-singular.xml", "v3/multicurve-curve.xml", "v3/multicurve-singular.xml", "v3/multicurve-curve.xml",
@@ -332,6 +332,11 @@
<gml:posList>1 2 3 4</gml:posList> <gml:posList>1 2 3 4</gml:posList>
</gml:LineString> </gml:LineString>
--></div> --></div>
<div id="v3/linestring3d.xml"><!--
<gml:LineString xmlns:gml="http://www.opengis.net/gml" srsName="foo" srsDimension="3">
<gml:posList>1 2 3 4 5 6</gml:posList>
</gml:LineString>
--></div>
<div id="v3/curve.xml"><!-- <div id="v3/curve.xml"><!--
<gml:Curve xmlns:gml="http://www.opengis.net/gml" srsName="foo"> <gml:Curve xmlns:gml="http://www.opengis.net/gml" srsName="foo">
<gml:segments> <gml:segments>