Adding support to the gml parser for serializing OpenLayers.Bounds as gml:Box. This gives the filter format (and the sld format) the ability to write spatial filters (that have bounds as a value). r=me (closes #1543)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@7955 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -139,7 +139,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", "Envelope"];
|
||||
"MultiPoint", "Point", "Envelope", "Box"];
|
||||
var type, nodeList, geometry, parser;
|
||||
for(var i=0; i<order.length; ++i) {
|
||||
type = order[i];
|
||||
@@ -804,6 +804,23 @@ OpenLayers.Format.GML = OpenLayers.Class(OpenLayers.Format.XML, {
|
||||
gml.appendChild(polyMember);
|
||||
}
|
||||
return gml;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: buildGeometry.bounds
|
||||
* Given an OpenLayers bounds, create a GML box.
|
||||
*
|
||||
* Parameters:
|
||||
* bounds - {<OpenLayers.Geometry.Bounds>} A bounds object.
|
||||
*
|
||||
* Returns:
|
||||
* {DOMElement} A GML box node.
|
||||
*/
|
||||
bounds: function(bounds) {
|
||||
var gml = this.createElementNS(this.gmlns, "gml:Box");
|
||||
gml.appendChild(this.buildCoordinatesNode(bounds));
|
||||
return gml;
|
||||
}
|
||||
},
|
||||
|
||||
@@ -825,11 +842,17 @@ OpenLayers.Format.GML = OpenLayers.Class(OpenLayers.Format.XML, {
|
||||
coordinatesNode.setAttribute("decimal", ".");
|
||||
coordinatesNode.setAttribute("cs", ",");
|
||||
coordinatesNode.setAttribute("ts", " ");
|
||||
|
||||
var points = (geometry.components) ? geometry.components : [geometry];
|
||||
|
||||
var parts = [];
|
||||
for(var i=0; i<points.length; i++) {
|
||||
parts.push(points[i].x + "," + points[i].y);
|
||||
|
||||
if(geometry instanceof OpenLayers.Bounds){
|
||||
parts.push(geometry.left + "," + geometry.bottom);
|
||||
parts.push(geometry.right + "," + geometry.top);
|
||||
} else {
|
||||
var points = (geometry.components) ? geometry.components : [geometry];
|
||||
for(var i=0; i<points.length; i++) {
|
||||
parts.push(points[i].x + "," + points[i].y);
|
||||
}
|
||||
}
|
||||
|
||||
var txtNode = this.createTextNode(parts.join(" "));
|
||||
|
||||
@@ -68,6 +68,7 @@
|
||||
var output = parser.write(data);
|
||||
var output = output.replace(/<\?[^>]*\?>/, ''); // Remove XML Prolog
|
||||
t.eq(output, multilinestring, "MultiLine geometry round trips correctly.");
|
||||
|
||||
}
|
||||
function test_Format_GML_read_point_geom(t) {
|
||||
t.plan(3);
|
||||
@@ -325,6 +326,17 @@
|
||||
t.eq(output, multilinestring_xy, "MultiLine geometry round trips correctly.");
|
||||
}
|
||||
|
||||
function test_buildGeometryNode_bounds(t) {
|
||||
t.plan(1);
|
||||
var parser = new OpenLayers.Format.GML();
|
||||
var bounds = new OpenLayers.Bounds(-180, -90, 180, 90);
|
||||
var output, expect;
|
||||
|
||||
// test that bounds are written as gml:Box
|
||||
var output = parser.buildGeometryNode(bounds);
|
||||
var expect = '<gml:Box xmlns:gml="http://www.opengis.net/gml"><gml:coordinates decimal="." cs="," ts=" ">-180,-90 180,90</gml:coordinates></gml:Box>';
|
||||
t.xml_eq(output, expect, "[xy true] Bounds correctly written as gml:Box");
|
||||
}
|
||||
|
||||
var test_content = ['<?xml version="1.0" encoding="utf-8" ?>\n<ogr:FeatureCollection\n xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\n xsi:schemaLocation="http://ogr.maptools.org/ testoutput.xsd"\n xmlns:ogr="http://ogr.maptools.org/"\n xmlns:gml="http://www.opengis.net/gml">\n <gml:boundedBy>\n <gml:Box>\n <gml:coord><gml:X>-1254041.389711702</gml:X><gml:Y>250906.9515983529</gml:Y></gml:coord>\n <gml:coord><gml:X>-634517.1199908922</gml:X><gml:Y>762236.2940800377</gml:Y></gml:coord>\n </gml:Box>\n </gml:boundedBy> \n <gml:featureMember>\n <ogr:states fid="F0">\n <ogr:geometryProperty><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>-634517.11999089224,691849.77929356066,0 -653761.64509297756,471181.53429472551,0 -673343.60852865304,250906.9515983529,0 -1088825.734430399,299284.85108220269,0 -1254041.3897117018,324729.27754874947,0 -1235750.4212498858,434167.33911316615,0 -1190777.7803201093,704392.96327195223,0 -1181607.835811228,762236.29408003774,0 -634517.11999089224,691849.77929356066,0</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>\n <ogr:NAME>WY</ogr:NAME>\n <ogr:LONGNAME><![CDATA[Wyoming]]></ogr:LONGNAME>\n </ogr:states>\n </gml:featureMember>\n</ogr:FeatureCollection>\n',
|
||||
'<wfs:FeatureCollection' +
|
||||
|
||||
Reference in New Issue
Block a user