| 1 |
<html> |
|---|
| 2 |
<head> |
|---|
| 3 |
<script src="../../lib/OpenLayers.js"></script> |
|---|
| 4 |
<script type="text/javascript"> |
|---|
| 5 |
|
|---|
| 6 |
function test_Format_GML_constructor(t) { |
|---|
| 7 |
t.plan(4); |
|---|
| 8 |
|
|---|
| 9 |
var options = {'foo': 'bar'}; |
|---|
| 10 |
var format = new OpenLayers.Format.GML(options); |
|---|
| 11 |
t.ok(format instanceof OpenLayers.Format.GML, |
|---|
| 12 |
"new OpenLayers.Format.GML returns object" ); |
|---|
| 13 |
t.eq(format.foo, "bar", "constructor sets options correctly"); |
|---|
| 14 |
t.eq(typeof format.read, "function", "format has a read function"); |
|---|
| 15 |
t.eq(typeof format.write, "function", "format has a write function"); |
|---|
| 16 |
} |
|---|
| 17 |
function test_Format_GML_getFid(t) { |
|---|
| 18 |
t.plan(2); |
|---|
| 19 |
var parser = new OpenLayers.Format.GML(); |
|---|
| 20 |
data = parser.read(test_content[1]); |
|---|
| 21 |
t.eq(data[0].fid, '221', 'fid on polygons set correctly (with whitespace)'); |
|---|
| 22 |
t.eq(data[1].fid, '8', 'fid on linestrings set correctly with whitespace'); |
|---|
| 23 |
} |
|---|
| 24 |
function test_Format_GML_no_clobber(t) { |
|---|
| 25 |
t.plan(1); |
|---|
| 26 |
var parser = new OpenLayers.Format.GML(); |
|---|
| 27 |
data = parser.read(test_content[1]); |
|---|
| 28 |
t.eq(window.i, undefined, |
|---|
| 29 |
"i is undefined in window scope after reading."); |
|---|
| 30 |
} |
|---|
| 31 |
function test_Format_GML_read_3d(t) { |
|---|
| 32 |
t.plan(2); |
|---|
| 33 |
var parser = new OpenLayers.Format.GML(); |
|---|
| 34 |
data = parser.read(test_content[0]); |
|---|
| 35 |
t.eq(data[0].geometry.getBounds().toBBOX(), "-1254041.389712,250906.951598,-634517.119991,762236.29408", "Reading 3d content returns geometry with correct bounds (no 0,0)"); |
|---|
| 36 |
t.eq(data[0].geometry.CLASS_NAME, "OpenLayers.Geometry.Polygon", "Reading 3d content returns polygon geometry"); |
|---|
| 37 |
} |
|---|
| 38 |
function test_Format_GML_write_geoms(t) { |
|---|
| 39 |
t.plan(5); |
|---|
| 40 |
var parser = new OpenLayers.Format.GML(); |
|---|
| 41 |
|
|---|
| 42 |
var point = shell_start + serialize_geoms['point'] + shell_end; |
|---|
| 43 |
data = parser.read(point); |
|---|
| 44 |
var output = parser.write(data); |
|---|
| 45 |
t.eq(output, point, "Point geometry round trips correctly."); |
|---|
| 46 |
|
|---|
| 47 |
var linestring = shell_start + serialize_geoms['linestring'] + shell_end; |
|---|
| 48 |
data = parser.read(linestring); |
|---|
| 49 |
var output = parser.write(data); |
|---|
| 50 |
t.eq(output, linestring, "Line geometry round trips correctly."); |
|---|
| 51 |
|
|---|
| 52 |
var polygon = shell_start + serialize_geoms['polygon'] + shell_end; |
|---|
| 53 |
data = parser.read(polygon); |
|---|
| 54 |
var output = parser.write(data); |
|---|
| 55 |
t.eq(output, polygon, "Poly geometry round trips correctly."); |
|---|
| 56 |
|
|---|
| 57 |
var multipoint = shell_start + serialize_geoms['multipoint'] + shell_end; |
|---|
| 58 |
data = parser.read(multipoint); |
|---|
| 59 |
var output = parser.write(data); |
|---|
| 60 |
t.eq(output, multipoint, "MultiPoint geometry round trips correctly."); |
|---|
| 61 |
|
|---|
| 62 |
var multilinestring = shell_start + serialize_geoms['multilinestring'] + shell_end; |
|---|
| 63 |
data = parser.read(multilinestring); |
|---|
| 64 |
var output = parser.write(data); |
|---|
| 65 |
t.eq(output, multilinestring, "MultiLine geometry round trips correctly."); |
|---|
| 66 |
} |
|---|
| 67 |
function test_Format_GML_read_point_geom(t) { |
|---|
| 68 |
t.plan(3); |
|---|
| 69 |
|
|---|
| 70 |
var point = shell_start + geoms['point'] + shell_end; |
|---|
| 71 |
var parser = new OpenLayers.Format.GML(); |
|---|
| 72 |
data = parser.read(point); |
|---|
| 73 |
t.eq(data[0].geometry.CLASS_NAME, "OpenLayers.Geometry.Point", "Point GML returns correct classname"); |
|---|
| 74 |
t.eq(data[0].geometry.x, 1, "x coord correct"); |
|---|
| 75 |
t.eq(data[0].geometry.y, 2, "y coord correct"); |
|---|
| 76 |
} |
|---|
| 77 |
function test_Format_GML_read_linestring_geom(t) { |
|---|
| 78 |
t.plan(5); |
|---|
| 79 |
|
|---|
| 80 |
var line = shell_start + geoms['linestring'] + shell_end; |
|---|
| 81 |
var parser = new OpenLayers.Format.GML(); |
|---|
| 82 |
data = parser.read(line); |
|---|
| 83 |
t.eq(data[0].geometry.CLASS_NAME, "OpenLayers.Geometry.LineString", "LineString GML returns correct classname"); |
|---|
| 84 |
t.eq(data[0].geometry.components[0].x, 1, "first x coord correct"); |
|---|
| 85 |
t.eq(data[0].geometry.components[0].y, 2, "first y coord correct"); |
|---|
| 86 |
t.eq(data[0].geometry.components[1].x, 4, "second x coord correct"); |
|---|
| 87 |
t.eq(data[0].geometry.components[1].y, 5, "second y coord correct"); |
|---|
| 88 |
} |
|---|
| 89 |
function test_Format_GML_read_polygon_geom(t) { |
|---|
| 90 |
t.plan(7); |
|---|
| 91 |
|
|---|
| 92 |
var polygon = shell_start + geoms['polygon'] + shell_end; |
|---|
| 93 |
var parser = new OpenLayers.Format.GML(); |
|---|
| 94 |
data = parser.read(polygon); |
|---|
| 95 |
t.eq(data[0].geometry.CLASS_NAME, "OpenLayers.Geometry.Polygon", "Polygon GML returns correct classname"); |
|---|
| 96 |
t.eq(data[0].geometry.components[0].components[0].x, 1, "first x coord correct"); |
|---|
| 97 |
t.eq(data[0].geometry.components[0].components[0].y, 2, "first y coord correct"); |
|---|
| 98 |
t.eq(data[0].geometry.components[0].components[1].x, 4, "second x coord correct"); |
|---|
| 99 |
t.eq(data[0].geometry.components[0].components[1].y, 5, "second y coord correct"); |
|---|
| 100 |
t.eq(data[0].geometry.components[0].components.length, 4, "coords length correct"); |
|---|
| 101 |
t.eq(data[0].geometry.components.length, 1, "rings length correct"); |
|---|
| 102 |
} |
|---|
| 103 |
function test_Format_GML_read_multipoint_geom(t) { |
|---|
| 104 |
t.plan(6); |
|---|
| 105 |
|
|---|
| 106 |
var multipoint = shell_start + geoms['multipoint'] + shell_end; |
|---|
| 107 |
var parser = new OpenLayers.Format.GML(); |
|---|
| 108 |
data = parser.read(multipoint); |
|---|
| 109 |
t.eq(data[0].geometry.CLASS_NAME, "OpenLayers.Geometry.MultiPoint", "MultiPoint GML returns correct classname"); |
|---|
| 110 |
t.eq(data[0].geometry.components[0].x, 1, "x coord correct"); |
|---|
| 111 |
t.eq(data[0].geometry.components[0].y, 2, "y coord correct"); |
|---|
| 112 |
t.eq(data[0].geometry.components.length, 2, "length correct"); |
|---|
| 113 |
t.eq(data[0].geometry.components[1].x, 4, "x coord correct"); |
|---|
| 114 |
t.eq(data[0].geometry.components[1].y, 5, "y coord correct"); |
|---|
| 115 |
} |
|---|
| 116 |
function test_Format_GML_read_multilinestring_geom(t) { |
|---|
| 117 |
t.plan(6); |
|---|
| 118 |
|
|---|
| 119 |
var multilinestring = shell_start + geoms['multilinestring'] + shell_end; |
|---|
| 120 |
var parser = new OpenLayers.Format.GML(); |
|---|
| 121 |
data = parser.read(multilinestring); |
|---|
| 122 |
t.eq(data[0].geometry.CLASS_NAME, "OpenLayers.Geometry.MultiLineString", "MultiLineString GML returns correct classname"); |
|---|
| 123 |
t.eq(data[0].geometry.components[0].components[0].x, 1, "x coord correct"); |
|---|
| 124 |
t.eq(data[0].geometry.components[0].components[0].y, 2, "y coord correct"); |
|---|
| 125 |
t.eq(data[0].geometry.components[0].components.length, 2, "length correct"); |
|---|
| 126 |
t.eq(data[0].geometry.components[0].components[1].x, 4, "x coord correct"); |
|---|
| 127 |
t.eq(data[0].geometry.components[0].components[1].y, 5, "y coord correct"); |
|---|
| 128 |
|
|---|
| 129 |
} |
|---|
| 130 |
function test_Format_GML_read_polygon_with_holes_geom(t) { |
|---|
| 131 |
t.plan(12); |
|---|
| 132 |
|
|---|
| 133 |
var polygon_with_holes = shell_start + geoms['polygon_with_holes'] + shell_end; |
|---|
| 134 |
var parser = new OpenLayers.Format.GML(); |
|---|
| 135 |
data = parser.read(polygon_with_holes); |
|---|
| 136 |
t.eq(data[0].geometry.CLASS_NAME, "OpenLayers.Geometry.Polygon", "Polygon GML returns correct classname"); |
|---|
| 137 |
t.eq(data[0].geometry.components[0].components[0].x, 1, "first x coord correct"); |
|---|
| 138 |
t.eq(data[0].geometry.components[0].components[0].y, 2, "first y coord correct"); |
|---|
| 139 |
t.eq(data[0].geometry.components[0].components[1].x, 4, "second x coord correct"); |
|---|
| 140 |
t.eq(data[0].geometry.components[0].components[1].y, 5, "second y coord correct"); |
|---|
| 141 |
t.eq(data[0].geometry.components[0].components.length, 4, "coords length correct"); |
|---|
| 142 |
t.eq(data[0].geometry.components[1].components[0].x, 11, "first x coord correct"); |
|---|
| 143 |
t.eq(data[0].geometry.components[1].components[0].y, 12, "first y coord correct"); |
|---|
| 144 |
t.eq(data[0].geometry.components[1].components[1].x, 14, "second x coord correct"); |
|---|
| 145 |
t.eq(data[0].geometry.components[1].components[1].y, 15, "second y coord correct"); |
|---|
| 146 |
t.eq(data[0].geometry.components[1].components.length, 4, "coords length correct"); |
|---|
| 147 |
t.eq(data[0].geometry.components.length, 2, "rings length correct"); |
|---|
| 148 |
} |
|---|
| 149 |
function test_Format_GML_read_attributes(t) { |
|---|
| 150 |
t.plan(2); |
|---|
| 151 |
var parser = new OpenLayers.Format.GML(); |
|---|
| 152 |
data = parser.read(test_content[0]); |
|---|
| 153 |
t.eq(data[0].attributes['NAME'], "WY", "Simple Attribute data is read correctly."); |
|---|
| 154 |
t.eq(data[0].attributes['LONGNAME'], "Wyoming", "Attribute data is read from CDATA node correctly."); |
|---|
| 155 |
} |
|---|
| 156 |
|
|---|
| 157 |
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', |
|---|
| 158 |
'<wfs:FeatureCollection' + |
|---|
| 159 |
' xmlns:fs="http://example.com/featureserver"' + |
|---|
| 160 |
' xmlns:wfs="http://www.opengis.net/wfs"' + |
|---|
| 161 |
' xmlns:gml="http://www.opengis.net/gml"' + |
|---|
| 162 |
' xmlns:ogc="http://www.opengis.net/ogc"' + |
|---|
| 163 |
' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' + |
|---|
| 164 |
' xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengeospatial.net//wfs/1.0.0/WFS-basic.xsd">' + |
|---|
| 165 |
' ' + |
|---|
| 166 |
'' + |
|---|
| 167 |
' <gml:featureMember>' + |
|---|
| 168 |
' \n<fs:scribble fid="221">' + |
|---|
| 169 |
' <fs:geometry>' + |
|---|
| 170 |
' <gml:Polygon>' + |
|---|
| 171 |
' ' + |
|---|
| 172 |
' <gml:outerBoundaryIs><gml:LinearRing>' + |
|---|
| 173 |
' <gml:coordinates>149.105072021,-35.1816558838 149.100608826,-35.1844024658 149.098892212,-35.1898956299 149.105072021,-35.1816558838</gml:coordinates>' + |
|---|
| 174 |
' </gml:LinearRing></gml:outerBoundaryIs>' + |
|---|
| 175 |
' ' + |
|---|
| 176 |
' </gml:Polygon>' + |
|---|
| 177 |
' </fs:geometry>' + |
|---|
| 178 |
' <fs:title>random test features</fs:title>' + |
|---|
| 179 |
' </fs:scribble>' + |
|---|
| 180 |
'</gml:featureMember> ' + |
|---|
| 181 |
' <gml:featureMember><fs:scribble fid="8"> <fs:geometry> <gml:Point><gml:coordinates>-81.38671875,27.0703125</gml:coordinates></gml:Point> </fs:geometry> ' + |
|---|
| 182 |
' <fs:down>south</fs:down><fs:title>Florida</fs:title> </fs:scribble></gml:featureMember>' + |
|---|
| 183 |
'</wfs:FeatureCollection>' |
|---|
| 184 |
]; |
|---|
| 185 |
|
|---|
| 186 |
var shell_start = '<wfs:FeatureCollection xmlns:wfs="http://www.opengis.net/wfs"><gml:featureMember xmlns:gml="http://www.opengis.net/gml"><feature:features xmlns:feature="http://mapserver.gis.umn.edu/mapserver" fid="221"><feature:geometry>'; |
|---|
| 187 |
var shell_end = '</feature:geometry></feature:features></gml:featureMember></wfs:FeatureCollection>'; |
|---|
| 188 |
var serialize_geoms = { |
|---|
| 189 |
'point': '<gml:Point><gml:coordinates decimal="." cs="," ts=" ">1,2</gml:coordinates></gml:Point>', |
|---|
| 190 |
'linestring': '<gml:LineString><gml:coordinates decimal="." cs="," ts=" ">1,2 4,5</gml:coordinates></gml:LineString>', |
|---|
| 191 |
'polygon': '<gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates decimal="." cs="," ts=" ">1,2 4,5 3,6 1,2</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon>', |
|---|
| 192 |
'multipoint': '<gml:MultiPoint><gml:pointMember><gml:Point><gml:coordinates decimal="." cs="," ts=" ">1,2</gml:coordinates></gml:Point></gml:pointMember><gml:pointMember><gml:Point><gml:coordinates decimal="." cs="," ts=" ">4,5</gml:coordinates></gml:Point></gml:pointMember></gml:MultiPoint>', |
|---|
| 193 |
'multilinestring': '<gml:MultiLineString><gml:lineStringMember><gml:LineString><gml:coordinates decimal="." cs="," ts=" ">1,2 4,5</gml:coordinates></gml:LineString></gml:lineStringMember><gml:lineStringMember><gml:LineString><gml:coordinates decimal="." cs="," ts=" ">11,12 14,15</gml:coordinates></gml:LineString></gml:lineStringMember></gml:MultiLineString>' |
|---|
| 194 |
}; |
|---|
| 195 |
var geoms = { |
|---|
| 196 |
'point': '<gml:Point><gml:coordinates>1,2,3</gml:coordinates></gml:Point>', |
|---|
| 197 |
'linestring': '<gml:LineString><gml:coordinates>1,2,3 4,5,6</gml:coordinates></gml:LineString>', |
|---|
| 198 |
'polygon': '<gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>1,2 4,5 3,6 1,2</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon>', |
|---|
| 199 |
'polygon_with_holes': '<gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>1,2 4,5 3,6 1,2</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs><gml:innerBoundaryIs><gml:LinearRing><gml:coordinates>11,12 14,15 13,16 11,12</gml:coordinates></gml:LinearRing></gml:innerBoundaryIs></gml:Polygon>', |
|---|
| 200 |
'multipoint': '<gml:MultiPoint><gml:Point><gml:coordinates>1,2,3</gml:coordinates></gml:Point><gml:Point><gml:coordinates>4,5,6</gml:coordinates></gml:Point></gml:MultiPoint>', |
|---|
| 201 |
'multilinestring': '<gml:MultiLineString><gml:LineString><gml:coordinates>1,2,3 4,5,6</gml:coordinates></gml:LineString><gml:LineString><gml:coordinates>11,12,13 14,15,16</gml:coordinates></gml:LineString></gml:MultiLineString>' // , |
|---|
| 202 |
// 'multipolygon_with_holes': '<gml:MultiPolygon><gml:Polygon><gml:outerBoundaryIs>1,2 4,5 3,6 1,2</gml:outerBoundaryIs><gml:innerBoundaryIs>11,12 14,15 13,16 11,12</gml:innerBoundaryIs></gml:Polygon><gml:Polygon><gml:outerBoundaryIs>101,102 104,105 103,106 101,102</gml:outerBoundaryIs><gml:innerBoundaryIs>111,112 114,115 113,116 111,112</gml:innerBoundaryIs></gml:Polygon></gml:MultiPolygon>' |
|---|
| 203 |
}; |
|---|
| 204 |
</script> |
|---|
| 205 |
</head> |
|---|
| 206 |
<body> |
|---|
| 207 |
</body> |
|---|
| 208 |
</html> |
|---|