Commit this quite-excellent patch from Roald de Wit, which adds:
* the ability to 'flip' the GML format xy ordering on parsing, allowing the GML parser to parse 'real' GML in 4326 when the option is on. * parsing of GML 'envelope' as a Polygon. this is primarily to support the next... * GeoRSS GML read support, using the GML format when neccesary. Includes a comprehensive set of tests, and is really one of the better assembled major patches from a first-time contributor I've ever seen. Thanks for the hard work, Roald! (Closes #1109) git-svn-id: http://svn.openlayers.org/trunk/openlayers@5238 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -71,6 +71,13 @@ OpenLayers.Format.GML = OpenLayers.Class(OpenLayers.Format.XML, {
|
||||
*/
|
||||
extractAttributes: true,
|
||||
|
||||
/**
|
||||
* 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,
|
||||
|
||||
/**
|
||||
* Constructor: OpenLayers.Format.GML
|
||||
* Create a new parser for GML.
|
||||
@@ -130,7 +137,7 @@ OpenLayers.Format.GML = OpenLayers.Class(OpenLayers.Format.XML, {
|
||||
// only accept on geometry per feature - look for highest "order"
|
||||
var order = ["MultiPolygon", "Polygon",
|
||||
"MultiLineString", "LineString",
|
||||
"MultiPoint", "Point"];
|
||||
"MultiPoint", "Point", "Envelope"];
|
||||
var type, nodeList, geometry, parser;
|
||||
for(var i=0; i<order.length; ++i) {
|
||||
type = order[i];
|
||||
@@ -197,13 +204,13 @@ OpenLayers.Format.GML = OpenLayers.Class(OpenLayers.Format.XML, {
|
||||
* 2) <gml:coordinates>x, y, z</gml:coordinates>
|
||||
* 3) <gml:coord><gml:X>x</gml:X><gml:Y>y</gml:Y></gml:coord>
|
||||
*/
|
||||
var nodeList;
|
||||
var nodeList, coordString;
|
||||
var coords = [];
|
||||
|
||||
// look for <gml:pos>
|
||||
var nodeList = this.getElementsByTagNameNS(node, this.gmlns, "pos");
|
||||
if(nodeList.length > 0) {
|
||||
var coordString = nodeList[0].firstChild.nodeValue;
|
||||
coordString = nodeList[0].firstChild.nodeValue;
|
||||
coordString = coordString.replace(this.regExes.trimSpace, "");
|
||||
coords = coordString.split(this.regExes.splitSpace);
|
||||
}
|
||||
@@ -240,8 +247,15 @@ OpenLayers.Format.GML = OpenLayers.Class(OpenLayers.Format.XML, {
|
||||
if(coords.length == 2) {
|
||||
coords[2] = null;
|
||||
}
|
||||
return new OpenLayers.Geometry.Point(coords[0], coords[1],
|
||||
|
||||
if (this.xy) {
|
||||
return new OpenLayers.Geometry.Point(coords[0], coords[1],
|
||||
coords[2]);
|
||||
}
|
||||
else{
|
||||
return new OpenLayers.Geometry.Point(coords[1], coords[0],
|
||||
coords[2]);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -305,7 +319,11 @@ OpenLayers.Format.GML = OpenLayers.Class(OpenLayers.Format.XML, {
|
||||
x = coords[j];
|
||||
y = coords[j+1];
|
||||
z = (dim == 2) ? null : coords[j+2];
|
||||
points.push(new OpenLayers.Geometry.Point(x, y, z));
|
||||
if (this.xy) {
|
||||
points.push(new OpenLayers.Geometry.Point(x, y, z));
|
||||
} else {
|
||||
points.push(new OpenLayers.Geometry.Point(y, x, z));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -325,9 +343,15 @@ OpenLayers.Format.GML = OpenLayers.Class(OpenLayers.Format.XML, {
|
||||
if(coords.length == 2) {
|
||||
coords[2] = null;
|
||||
}
|
||||
points.push(new OpenLayers.Geometry.Point(coords[0],
|
||||
if (this.xy) {
|
||||
points.push(new OpenLayers.Geometry.Point(coords[0],
|
||||
coords[1],
|
||||
coords[2]));
|
||||
} else {
|
||||
points.push(new OpenLayers.Geometry.Point(coords[1],
|
||||
coords[0],
|
||||
coords[2]));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -426,6 +450,64 @@ OpenLayers.Format.GML = OpenLayers.Class(OpenLayers.Format.XML, {
|
||||
}
|
||||
}
|
||||
return new OpenLayers.Geometry.MultiPolygon(components);
|
||||
},
|
||||
|
||||
envelope: function(node) {
|
||||
var components = [];
|
||||
var coordString;
|
||||
var envelope;
|
||||
|
||||
var lpoint = this.getElementsByTagNameNS(node, this.gmlns, "lowerCorner");
|
||||
if (lpoint.length > 0) {
|
||||
var coords = [];
|
||||
|
||||
if(lpoint.length > 0) {
|
||||
coordString = lpoint[0].firstChild.nodeValue;
|
||||
coordString = coordString.replace(this.regExes.trimSpace, "");
|
||||
coords = coordString.split(this.regExes.splitSpace);
|
||||
}
|
||||
|
||||
if(coords.length == 2) {
|
||||
coords[2] = null;
|
||||
}
|
||||
if (this.xy) {
|
||||
var lowerPoint = new OpenLayers.Geometry.Point(coords[0], coords[1],coords[2]);
|
||||
} else {
|
||||
var lowerPoint = new OpenLayers.Geometry.Point(coords[1], coords[0],coords[2]);
|
||||
}
|
||||
}
|
||||
|
||||
var upoint = this.getElementsByTagNameNS(node, this.gmlns, "upperCorner");
|
||||
if (upoint.length > 0) {
|
||||
var coords = [];
|
||||
|
||||
if(upoint.length > 0) {
|
||||
coordString = upoint[0].firstChild.nodeValue;
|
||||
coordString = coordString.replace(this.regExes.trimSpace, "");
|
||||
coords = coordString.split(this.regExes.splitSpace);
|
||||
}
|
||||
|
||||
if(coords.length == 2) {
|
||||
coords[2] = null;
|
||||
}
|
||||
if (this.xy) {
|
||||
var upperPoint = new OpenLayers.Geometry.Point(coords[0], coords[1],coords[2]);
|
||||
} else {
|
||||
var upperPoint = new OpenLayers.Geometry.Point(coords[1], coords[0],coords[2]);
|
||||
}
|
||||
}
|
||||
|
||||
if (lowerPoint && upperPoint) {
|
||||
components.push(new OpenLayers.Geometry.Point(lowerPoint.x, lowerPoint.y));
|
||||
components.push(new OpenLayers.Geometry.Point(upperPoint.x, lowerPoint.y));
|
||||
components.push(new OpenLayers.Geometry.Point(upperPoint.x, upperPoint.y));
|
||||
components.push(new OpenLayers.Geometry.Point(lowerPoint.x, upperPoint.y));
|
||||
components.push(new OpenLayers.Geometry.Point(lowerPoint.x, lowerPoint.y));
|
||||
|
||||
var ring = new OpenLayers.Geometry.LinearRing(components);
|
||||
envelope = new OpenLayers.Geometry.Polygon([ring]);
|
||||
}
|
||||
return envelope;
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@@ -58,6 +58,20 @@ OpenLayers.Format.GeoRSS = OpenLayers.Class(OpenLayers.Format.XML, {
|
||||
*/
|
||||
featureDescription: "No Description",
|
||||
|
||||
/**
|
||||
* Property: gmlParse
|
||||
* {Object} GML Format object for parsing features
|
||||
* Non-API and only created if necessary
|
||||
*/
|
||||
gmlParser: null,
|
||||
|
||||
/**
|
||||
* APIProperty: xy
|
||||
* {Boolean} Order of the GML coordinate: true:(x,y) or false:(y,x)
|
||||
* For GeoRSS the default is (y,x), therefore: false
|
||||
*/
|
||||
xy: false,
|
||||
|
||||
/**
|
||||
* Constructor: OpenLayers.Format.GeoRSS
|
||||
* Create a new parser for GeoRSS.
|
||||
@@ -91,38 +105,52 @@ OpenLayers.Format.GeoRSS = OpenLayers.Class(OpenLayers.Format.XML, {
|
||||
var polygon = this.getElementsByTagNameNS(item,
|
||||
this.georssns,
|
||||
"polygon");
|
||||
|
||||
var where = this.getElementsByTagNameNS(item,
|
||||
this.georssns,
|
||||
"where");
|
||||
if (point.length > 0 || (lat.length > 0 && lon.length > 0)) {
|
||||
var location;
|
||||
if (point.length > 0) {
|
||||
var location = OpenLayers.String.trim(
|
||||
location = OpenLayers.String.trim(
|
||||
point[0].firstChild.nodeValue).split(/\s+/);
|
||||
|
||||
if (location.length !=2) {
|
||||
var location = OpenLayers.String.trim(
|
||||
location = OpenLayers.String.trim(
|
||||
point[0].firstChild.nodeValue).split(/\s*,\s*/);
|
||||
}
|
||||
} else {
|
||||
var location = [parseFloat(lat[0].firstChild.nodeValue),
|
||||
location = [parseFloat(lat[0].firstChild.nodeValue),
|
||||
parseFloat(lon[0].firstChild.nodeValue)];
|
||||
}
|
||||
|
||||
var geometry = new OpenLayers.Geometry.Point(parseFloat(location[1]),
|
||||
parseFloat(location[0]));
|
||||
parseFloat(location[0]));
|
||||
|
||||
} else if (line.length > 0) {
|
||||
var coords = OpenLayers.String.trim(line[0].firstChild.nodeValue).split(/\s+/);
|
||||
var components = [];
|
||||
var point;
|
||||
for (var i=0; i < coords.length; i+=2) {
|
||||
var point = new OpenLayers.Geometry.Point(parseFloat(coords[i+1]), parseFloat(coords[i]));
|
||||
point = new OpenLayers.Geometry.Point(parseFloat(coords[i+1]),
|
||||
parseFloat(coords[i]));
|
||||
components.push(point);
|
||||
}
|
||||
geometry = new OpenLayers.Geometry.LineString(components);
|
||||
} else if (polygon.length > 0) {
|
||||
var coords = OpenLayers.String.trim(polygon[0].firstChild.nodeValue).split(/\s+/);
|
||||
var components = [];
|
||||
var point;
|
||||
for (var i=0; i < coords.length; i+=2) {
|
||||
var point = new OpenLayers.Geometry.Point(parseFloat(coords[i+1]), parseFloat(coords[i]));
|
||||
point = new OpenLayers.Geometry.Point(parseFloat(coords[i+1]),
|
||||
parseFloat(coords[i]));
|
||||
components.push(point);
|
||||
}
|
||||
geometry = new OpenLayers.Geometry.Polygon([new OpenLayers.Geometry.LinearRing(components)]);
|
||||
} else if (where.length > 0) {
|
||||
if (!this.gmlParser) {
|
||||
this.gmlParser = new OpenLayers.Format.GML({'xy': this.xy});
|
||||
}
|
||||
var feature = this.gmlParser.parseFeature(where[0]);
|
||||
geometry = feature.geometry;
|
||||
}
|
||||
return geometry;
|
||||
},
|
||||
@@ -139,6 +167,7 @@ OpenLayers.Format.GeoRSS = OpenLayers.Class(OpenLayers.Format.XML, {
|
||||
*/
|
||||
createFeatureFromItem: function(item) {
|
||||
var geometry = this.createGeometryFromItem(item);
|
||||
|
||||
/* Provide defaults for title and description */
|
||||
var title = this.getChildValue(item, "*", "title", this.featureTitle);
|
||||
|
||||
@@ -340,7 +369,7 @@ OpenLayers.Format.GeoRSS = OpenLayers.Class(OpenLayers.Format.XML, {
|
||||
}
|
||||
path = parts.join(" ");
|
||||
} else {
|
||||
path = geometry.y + " " + geometry.x;
|
||||
path = geometry.y + " " + geometry.x;
|
||||
}
|
||||
return this.createTextNode(path);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user