Add support for georss:box parsing, and parsing of summary as fallback for
'content'. git-svn-id: http://svn.openlayers.org/trunk/openlayers@9049 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -110,6 +110,10 @@ OpenLayers.Format.GeoRSS = OpenLayers.Class(OpenLayers.Format.XML, {
|
|||||||
var where = this.getElementsByTagNameNS(item,
|
var where = this.getElementsByTagNameNS(item,
|
||||||
this.georssns,
|
this.georssns,
|
||||||
"where");
|
"where");
|
||||||
|
var box = this.getElementsByTagNameNS(item,
|
||||||
|
this.georssns,
|
||||||
|
"box");
|
||||||
|
|
||||||
if (point.length > 0 || (lat.length > 0 && lon.length > 0)) {
|
if (point.length > 0 || (lat.length > 0 && lon.length > 0)) {
|
||||||
var location;
|
var location;
|
||||||
if (point.length > 0) {
|
if (point.length > 0) {
|
||||||
@@ -153,6 +157,28 @@ OpenLayers.Format.GeoRSS = OpenLayers.Class(OpenLayers.Format.XML, {
|
|||||||
}
|
}
|
||||||
var feature = this.gmlParser.parseFeature(where[0]);
|
var feature = this.gmlParser.parseFeature(where[0]);
|
||||||
geometry = feature.geometry;
|
geometry = feature.geometry;
|
||||||
|
} else if (box.length > 0) {
|
||||||
|
var coords = OpenLayers.String.trim(box[0].firstChild.nodeValue).split(/\s+/);
|
||||||
|
var components = [];
|
||||||
|
var point;
|
||||||
|
if (coords.length > 3) {
|
||||||
|
point = new OpenLayers.Geometry.Point(parseFloat(coords[1]),
|
||||||
|
parseFloat(coords[0]));
|
||||||
|
components.push(point);
|
||||||
|
point = new OpenLayers.Geometry.Point(parseFloat(coords[1]),
|
||||||
|
parseFloat(coords[2]));
|
||||||
|
components.push(point);
|
||||||
|
point = new OpenLayers.Geometry.Point(parseFloat(coords[3]),
|
||||||
|
parseFloat(coords[2]));
|
||||||
|
components.push(point);
|
||||||
|
point = new OpenLayers.Geometry.Point(parseFloat(coords[3]),
|
||||||
|
parseFloat(coords[0]));
|
||||||
|
components.push(point);
|
||||||
|
point = new OpenLayers.Geometry.Point(parseFloat(coords[1]),
|
||||||
|
parseFloat(coords[0]));
|
||||||
|
components.push(point);
|
||||||
|
}
|
||||||
|
geometry = new OpenLayers.Geometry.Polygon([new OpenLayers.Geometry.LinearRing(components)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (geometry && this.internalProjection && this.externalProjection) {
|
if (geometry && this.internalProjection && this.externalProjection) {
|
||||||
@@ -182,8 +208,8 @@ OpenLayers.Format.GeoRSS = OpenLayers.Class(OpenLayers.Format.XML, {
|
|||||||
/* First try RSS descriptions, then Atom summaries */
|
/* First try RSS descriptions, then Atom summaries */
|
||||||
var description = this.getChildValue(
|
var description = this.getChildValue(
|
||||||
item, "*", "description",
|
item, "*", "description",
|
||||||
this.getChildValue(item, "*", "content", this.featureDescription)
|
this.getChildValue(item, "*", "content",
|
||||||
);
|
this.getChildValue(item, "*", "summary", this.featureDescription)));
|
||||||
|
|
||||||
/* If no link URL is found in the first child node, try the
|
/* If no link URL is found in the first child node, try the
|
||||||
href attribute */
|
href attribute */
|
||||||
|
|||||||
@@ -26,6 +26,16 @@
|
|||||||
var data = parser.write([f]);
|
var data = parser.write([f]);
|
||||||
t.xml_eq(data, '<rss xmlns="http://backend.userland.com/rss2"><item><title></title><description></description><georss:line xmlns:georss="http://www.georss.org/georss">45.68 -111.04 45.68 -112.04</georss:line></item></rss>', 'GeoRSS serializes a line correctly');
|
t.xml_eq(data, '<rss xmlns="http://backend.userland.com/rss2"><item><title></title><description></description><georss:line xmlns:georss="http://www.georss.org/georss">45.68 -111.04 45.68 -112.04</georss:line></item></rss>', 'GeoRSS serializes a line correctly');
|
||||||
}
|
}
|
||||||
|
function test_Format_GeoRSS_box(t) {
|
||||||
|
t.plan(4);
|
||||||
|
var xml = '<rss xmlns="http://backend.userland.com/rss2"><item><title></title><description></description><georss:box xmlns:georss="http://www.georss.org/georss">45.68 -112.04 47.68 -111.04</georss:box></item></rss>';
|
||||||
|
var format = new OpenLayers.Format.GeoRSS();
|
||||||
|
var features = format.read(xml);
|
||||||
|
t.eq(features.length, 1, "one feature returned");
|
||||||
|
t.eq(features[0].geometry.components[0].components.length, 5, "polygon returned");
|
||||||
|
t.eq(features[0].geometry.components[0].components[0].x, -112.04, "polygon returned with correct first x");
|
||||||
|
t.eq(features[0].geometry.components[0].components[0].y, 45.68, "polygon returned with correct first y");
|
||||||
|
}
|
||||||
function test_Format_GeoRSS_w3cgeo(t) {
|
function test_Format_GeoRSS_w3cgeo(t) {
|
||||||
t.plan(2);
|
t.plan(2);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user