rolling back ;'s after a function declaration, cleaning up some whitespace. no functional changes. all tests still pass ff && ie6. note that it has never been either a policy or a priority for us to maintain coding standards in the test files. I'm only doing this as an exercise for my brain, waiting for the second cup of coffee to kick in.

git-svn-id: http://svn.openlayers.org/trunk/openlayers@4156 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
euzuro
2007-08-31 15:08:38 +00:00
parent a8d7097e67
commit 8ae2a01b66
8 changed files with 186 additions and 101 deletions
+3 -1
View File
@@ -30,7 +30,6 @@
' <fs:down>south</fs:down><fs:title>Florida</fs:title> </fs:scribble></gml:featureMember>' + ' <fs:down>south</fs:down><fs:title>Florida</fs:title> </fs:scribble></gml:featureMember>' +
'</wfs:FeatureCollection>'; '</wfs:FeatureCollection>';
function test_Format_GML_constructor(t) { function test_Format_GML_constructor(t) {
t.plan(4); t.plan(4);
@@ -42,13 +41,16 @@
t.eq(typeof format.read, "function", "format has a read function"); t.eq(typeof format.read, "function", "format has a read function");
t.eq(typeof format.write, "function", "format has a write function"); t.eq(typeof format.write, "function", "format has a write function");
} }
function test_Format_GML_getFid(t) { function test_Format_GML_getFid(t) {
t.plan(2); t.plan(2);
var parser = new OpenLayers.Format.GML(); var parser = new OpenLayers.Format.GML();
data = parser.read(test_content); data = parser.read(test_content);
t.eq(data[0].fid, '221', 'fid on polygons set correctly (with whitespace)'); t.eq(data[0].fid, '221', 'fid on polygons set correctly (with whitespace)');
t.eq(data[1].fid, '8', 'fid on linestrings set correctly with whitespace'); t.eq(data[1].fid, '8', 'fid on linestrings set correctly with whitespace');
} }
function test_Format_GML_no_clobber(t) { function test_Format_GML_no_clobber(t) {
t.plan(1); t.plan(1);
var parser = new OpenLayers.Format.GML(); var parser = new OpenLayers.Format.GML();
+96 -53
View File
@@ -9,7 +9,6 @@
var multiple_features = '{"type": "FeatureCollection", "members": [{"geometry": {"type": "Point", "coordinates": [-91.0546875, 43.9453125]}, "type": "Feature", "id": 577, "properties": {"strokeColor": "red", "title": "Feature 2", "image": "foo.gif", "author": "Your Name Here"}}, {"geometry": {"type": "LineString", "coordinates": [[91.40625, -1.40625], [116.015625, -42.890625], [153.28125, -28.125], [108.984375, 11.25], [75.234375, 8.4375], [76.640625, 9.140625], [67.5, -36.5625], [67.5, -35.859375]]}, "type": "Feature", "id": 576, "properties": {"strokeColor": "red", "title": "Feature 1", "author": "Your Name Here"}}, {"geometry": {"type": "Point", "coordinates": [139.5703125, 57.48046875]}, "type": "Feature", "id": 575, "properties": {"strokeColor": "blue", "title": "Feature 7", "author": "Your Name Here"}}, {"geometry": {"type": "Point", "coordinates": [107.2265625, 82.44140625]}, "type": "Feature", "id": 574, "properties": {"strokeColor": "blue", "title": "Feature 6", "author": "Your Name Here"}}, {"geometry": {"type": "Point", "coordinates": [94.21875, 72.94921875]}, "type": "Feature", "id": 573, "properties": {"strokeColor": "blue", "title": "Feature 5", "author": "Your Name Here"}}, {"geometry": {"type": "Point", "coordinates": [116.3671875, 61.69921875]}, "type": "Feature", "id": 572, "properties": {"strokeColor": "blue", "title": "Feature 4", "author": "Your Name Here"}}, {"geometry": {"type": "Point", "coordinates": [145.8984375, 73.65234375]}, "type": "Feature", "id": 571, "properties": {"strokeColor": "blue", "title": "Feature 3", "author": "Your Name Here"}}, {"geometry": {"type": "Polygon", "coordinates": [[[32.34375, 52.20703125], [87.1875, 70.13671875], [122.6953125, 37.44140625], [75.234375, 42.36328125], [40.078125, 42.36328125], [28.828125, 48.33984375], [18.6328125, 56.77734375], [23.203125, 65.56640625], [32.34375, 52.20703125]]]}, "type": "Feature", "id": 570, "properties": {"strokeColor": "blue", "title": "Feature 2", "author": "Your Name Here"}}, {"geometry": {"type": "Point", "coordinates": [62.578125, -53.4375]}, "type": "Feature", "id": 569, "properties": {"strokeColor": "red", "title": "Feature 3", "author": "Your Name Here"}}, {"geometry": {"type": "Point", "coordinates": [121.640625, 16.875]}, "type": "Feature", "id": 568, "properties": {"strokeColor": "red", "title": "Feature 6", "author": "Your Name Here"}}, {"geometry": {"type": "Point", "coordinates": [135.703125, 8.4375]}, "type": "Feature", "id": 567, "properties": {"strokeColor": "red", "title": "Feature 4", "author": "Your Name Here"}}, {"geometry": {"type": "Point", "coordinates": [137.109375, 48.515625]}, "type": "Feature", "id": 566, "properties": {"strokeColor": "red", "title": "Feature 274", "author": "Your Name Here"}}, {"geometry": {"type": "Point", "coordinates": [0, 5]}, "type": "Feature", "id": 565, "properties": {}}, {"geometry": {"type": "Point", "coordinates": [0, 5]}, "type": "Feature", "id": 564, "properties": {}}, {"geometry": {"type": "Point", "coordinates": [0, 5]}, "type": "Feature", "id": 563, "properties": {}}, {"geometry": {"type": "Polygon", "coordinates": [[[-131.484375, -5.9765625], [-112.5, -58.0078125], [-32.34375, -50.2734375], [-114.609375, 52.3828125], [-167.34375, -35.5078125], [-146.953125, -57.3046875], [-139.921875, -34.1015625], [-131.484375, -5.9765625]]]}, "type": "Feature", "id": 562, "properties": {"strokeColor": "red", "title": "Feature 2", "author": "Your Name Here"}}, {"geometry": {"type": "Point", "coordinates": [48.8671875, -15.8203125]}, "type": "Feature", "id": 560, "properties": {"strokeColor": "red", "title": "Feature 2", "author": "Your Name Here"}}, {"geometry": {"type": "LineString", "coordinates": [[-27.0703125, 59.4140625], [-77.6953125, 20.7421875], [30.5859375, -36.2109375], [67.1484375, 34.8046875]]}, "type": "Feature", "id": 559, "properties": {"strokeColor": "red", "title": "Feature 1", "author": "Your Name Here"}}, {"geometry": {"type": "Point", "coordinates": [12.65625, 16.5234375]}, "type": "Feature", "id": 558, "properties": {"styleUrl": "#allstyle", "title": "Feature 1", "strokeColor": "red", "author": "Your Name Here"}}]}'; var multiple_features = '{"type": "FeatureCollection", "members": [{"geometry": {"type": "Point", "coordinates": [-91.0546875, 43.9453125]}, "type": "Feature", "id": 577, "properties": {"strokeColor": "red", "title": "Feature 2", "image": "foo.gif", "author": "Your Name Here"}}, {"geometry": {"type": "LineString", "coordinates": [[91.40625, -1.40625], [116.015625, -42.890625], [153.28125, -28.125], [108.984375, 11.25], [75.234375, 8.4375], [76.640625, 9.140625], [67.5, -36.5625], [67.5, -35.859375]]}, "type": "Feature", "id": 576, "properties": {"strokeColor": "red", "title": "Feature 1", "author": "Your Name Here"}}, {"geometry": {"type": "Point", "coordinates": [139.5703125, 57.48046875]}, "type": "Feature", "id": 575, "properties": {"strokeColor": "blue", "title": "Feature 7", "author": "Your Name Here"}}, {"geometry": {"type": "Point", "coordinates": [107.2265625, 82.44140625]}, "type": "Feature", "id": 574, "properties": {"strokeColor": "blue", "title": "Feature 6", "author": "Your Name Here"}}, {"geometry": {"type": "Point", "coordinates": [94.21875, 72.94921875]}, "type": "Feature", "id": 573, "properties": {"strokeColor": "blue", "title": "Feature 5", "author": "Your Name Here"}}, {"geometry": {"type": "Point", "coordinates": [116.3671875, 61.69921875]}, "type": "Feature", "id": 572, "properties": {"strokeColor": "blue", "title": "Feature 4", "author": "Your Name Here"}}, {"geometry": {"type": "Point", "coordinates": [145.8984375, 73.65234375]}, "type": "Feature", "id": 571, "properties": {"strokeColor": "blue", "title": "Feature 3", "author": "Your Name Here"}}, {"geometry": {"type": "Polygon", "coordinates": [[[32.34375, 52.20703125], [87.1875, 70.13671875], [122.6953125, 37.44140625], [75.234375, 42.36328125], [40.078125, 42.36328125], [28.828125, 48.33984375], [18.6328125, 56.77734375], [23.203125, 65.56640625], [32.34375, 52.20703125]]]}, "type": "Feature", "id": 570, "properties": {"strokeColor": "blue", "title": "Feature 2", "author": "Your Name Here"}}, {"geometry": {"type": "Point", "coordinates": [62.578125, -53.4375]}, "type": "Feature", "id": 569, "properties": {"strokeColor": "red", "title": "Feature 3", "author": "Your Name Here"}}, {"geometry": {"type": "Point", "coordinates": [121.640625, 16.875]}, "type": "Feature", "id": 568, "properties": {"strokeColor": "red", "title": "Feature 6", "author": "Your Name Here"}}, {"geometry": {"type": "Point", "coordinates": [135.703125, 8.4375]}, "type": "Feature", "id": 567, "properties": {"strokeColor": "red", "title": "Feature 4", "author": "Your Name Here"}}, {"geometry": {"type": "Point", "coordinates": [137.109375, 48.515625]}, "type": "Feature", "id": 566, "properties": {"strokeColor": "red", "title": "Feature 274", "author": "Your Name Here"}}, {"geometry": {"type": "Point", "coordinates": [0, 5]}, "type": "Feature", "id": 565, "properties": {}}, {"geometry": {"type": "Point", "coordinates": [0, 5]}, "type": "Feature", "id": 564, "properties": {}}, {"geometry": {"type": "Point", "coordinates": [0, 5]}, "type": "Feature", "id": 563, "properties": {}}, {"geometry": {"type": "Polygon", "coordinates": [[[-131.484375, -5.9765625], [-112.5, -58.0078125], [-32.34375, -50.2734375], [-114.609375, 52.3828125], [-167.34375, -35.5078125], [-146.953125, -57.3046875], [-139.921875, -34.1015625], [-131.484375, -5.9765625]]]}, "type": "Feature", "id": 562, "properties": {"strokeColor": "red", "title": "Feature 2", "author": "Your Name Here"}}, {"geometry": {"type": "Point", "coordinates": [48.8671875, -15.8203125]}, "type": "Feature", "id": 560, "properties": {"strokeColor": "red", "title": "Feature 2", "author": "Your Name Here"}}, {"geometry": {"type": "LineString", "coordinates": [[-27.0703125, 59.4140625], [-77.6953125, 20.7421875], [30.5859375, -36.2109375], [67.1484375, 34.8046875]]}, "type": "Feature", "id": 559, "properties": {"strokeColor": "red", "title": "Feature 1", "author": "Your Name Here"}}, {"geometry": {"type": "Point", "coordinates": [12.65625, 16.5234375]}, "type": "Feature", "id": 558, "properties": {"styleUrl": "#allstyle", "title": "Feature 1", "strokeColor": "red", "author": "Your Name Here"}}]}';
var parser = new OpenLayers.Format.GeoJSON(); var parser = new OpenLayers.Format.GeoJSON();
function test_Format_GeoJSON_constructor(t) { function test_Format_GeoJSON_constructor(t) {
t.plan(4); t.plan(4);
@@ -24,6 +23,7 @@
function test_Format_GeoJSON_valid_type(t) { function test_Format_GeoJSON_valid_type(t) {
t.plan(13); t.plan(13);
OpenLayers.Console.error = function(error) { window.global_error = error; } OpenLayers.Console.error = function(error) { window.global_error = error; }
var types = ["Point", "MultiPoint", "LineString", "MultiLineString", "Polygon", "MultiPolygon", "Box"]; var types = ["Point", "MultiPoint", "LineString", "MultiLineString", "Polygon", "MultiPolygon", "Box"];
for (var i = 0; i < types.length; i++) { for (var i = 0; i < types.length; i++) {
@@ -39,14 +39,17 @@
function test_Format_GeoJSON_point(t) { function test_Format_GeoJSON_point(t) {
t.plan(3); t.plan(3);
data = parser.read(point_feature); data = parser.read(point_feature);
t.eq(data[0].fid, 573, "Fid is correct on point feature"); t.eq(data[0].fid, 573, "Fid is correct on point feature");
t.eq(data[0].geometry.x, 94.21875, 'Reading point feature gives correct x'); t.eq(data[0].geometry.x, 94.21875, 'Reading point feature gives correct x');
data = parser.read(point_feature, "Feature"); data = parser.read(point_feature, "Feature");
t.eq(data.fid, 573, 'Reading point feature with type gives feature instead of array of features '); t.eq(data.fid, 573, 'Reading point feature with type gives feature instead of array of features ');
} }
function test_Format_GeoJSON_line(t) { function test_Format_GeoJSON_line(t) {
t.plan(5); t.plan(5);
data = parser.read(line_feature); data = parser.read(line_feature);
t.eq(data[0].fid, 559, "Fid is correct on line feature"); t.eq(data[0].fid, 559, "Fid is correct on line feature");
t.eq(data[0].geometry.components.length, 4, 'Reading line feature gives correct length'); t.eq(data[0].geometry.components.length, 4, 'Reading line feature gives correct length');
@@ -54,8 +57,10 @@
t.eq(data[0].geometry.components[0].x, -27.0703125, 'Reading line feature gives correct x'); t.eq(data[0].geometry.components[0].x, -27.0703125, 'Reading line feature gives correct x');
t.eq(data[0].geometry.components[0].y, 59.4140625, 'Reading line feature gives correct y'); t.eq(data[0].geometry.components[0].y, 59.4140625, 'Reading line feature gives correct y');
} }
function test_Format_GeoJSON_poly(t) { function test_Format_GeoJSON_poly(t) {
t.plan(2); t.plan(2);
data = parser.read(poly_content); data = parser.read(poly_content);
t.eq(data[0].fid, 562, "poly id is correct") t.eq(data[0].fid, 562, "poly id is correct")
t.eq(data[0].geometry.components[0].components.length, 8, t.eq(data[0].geometry.components[0].components.length, 8,
@@ -64,6 +69,7 @@
function test_Format_GeoJSON_multipoint(t) { function test_Format_GeoJSON_multipoint(t) {
t.plan(5); t.plan(5);
var multipoint = { var multipoint = {
"type": "MultiPoint", "type": "MultiPoint",
"coordinates": [ "coordinates": [
@@ -79,23 +85,25 @@
t.eq(data.components[1].y, 1, "y of second component is right"); t.eq(data.components[1].y, 1, "y of second component is right");
} }
function test_Format_GeoJSON_multiline(t) { function test_Format_GeoJSON_multiline(t) {
t.plan(3); t.plan(3);
var multiline = { var multiline = {
"type": "MultiLineString", "type": "MultiLineString",
"coordinates": [ "coordinates": [
[ [100.0, 0.0], [101.0, 1.0] ], [ [100.0, 0.0], [101.0, 1.0] ],
[ [102.0, 2.0], [103.0, 3.0] ] [ [102.0, 2.0], [103.0, 3.0] ]
] ]
} };
data = parser.read(multiline, "Geometry"); data = parser.read(multiline, "Geometry");
t.eq(data.CLASS_NAME, "OpenLayers.Geometry.MultiLineString", "Correct class retrieved") t.eq(data.CLASS_NAME, "OpenLayers.Geometry.MultiLineString", "Correct class retrieved")
t.eq(data.components[0].components[0].CLASS_NAME, "OpenLayers.Geometry.Point", "correct type of components") t.eq(data.components[0].components[0].CLASS_NAME, "OpenLayers.Geometry.Point", "correct type of components")
t.eq(data.components[0].CLASS_NAME, "OpenLayers.Geometry.LineString", "correct type of components") t.eq(data.components[0].CLASS_NAME, "OpenLayers.Geometry.LineString", "correct type of components")
} }
function test_Format_GeoJSON_multipol(t) { function test_Format_GeoJSON_multipol(t) {
t.plan(2); t.plan(2);
var multipol = { var multipol = {
"type": "MultiPolygon", "type": "MultiPolygon",
"coordinates": [ "coordinates": [
@@ -107,7 +115,7 @@
[ [100.2, 0.2], [100.8, 0.2], [100.8, 0.8], [100.2, 0.8], [100.2, 0.2] ] [ [100.2, 0.2], [100.8, 0.2], [100.8, 0.8], [100.2, 0.8], [100.2, 0.2] ]
] ]
] ]
} };
OpenLayers.Console.error = function(error) { window.global_error = error; } OpenLayers.Console.error = function(error) { window.global_error = error; }
data = parser.read(multipol, "Geometry"); data = parser.read(multipol, "Geometry");
t.eq(data.CLASS_NAME, "OpenLayers.Geometry.MultiPolygon", "Correct class retrieved") t.eq(data.CLASS_NAME, "OpenLayers.Geometry.MultiPolygon", "Correct class retrieved")
@@ -116,6 +124,7 @@
function test_Format_GeoJSON_box(t) { function test_Format_GeoJSON_box(t) {
t.plan(6); t.plan(6);
var box = { var box = {
"type": "Box", "type": "Box",
"coordinates": [[100.0, 0.0], [101.0, 1.0]] "coordinates": [[100.0, 0.0], [101.0, 1.0]]
@@ -130,12 +139,10 @@
t.ok(box.search("Polygon") != -1 , "Serializes back to polygon"); t.ok(box.search("Polygon") != -1 , "Serializes back to polygon");
} }
// This test is from the geom_collection example on geojson spec. // This test is from the geom_collection example on geojson spec.
function test_Format_GeoJSON_geom_collection(t) { function test_Format_GeoJSON_geom_collection(t) {
t.plan(7); t.plan(7);
var geomcol = { var geomcol = {
"type": "GeometryCollection", "type": "GeometryCollection",
"members": [ "members": [
@@ -150,7 +157,7 @@
] ]
} }
] ]
} };
data = parser.read(geomcol, "GeometryCollection"); data = parser.read(geomcol, "GeometryCollection");
t.eq(data[0].CLASS_NAME, t.eq(data[0].CLASS_NAME,
"OpenLayers.Geometry.Point", "First geom in geom collection is point type"); "OpenLayers.Geometry.Point", "First geom in geom collection is point type");
@@ -162,11 +169,11 @@
t.eq(data[1].components.length, 2, "linestring is correct length"); t.eq(data[1].components.length, 2, "linestring is correct length");
t.eq(data[1].components[1].x, 102, "linestring is correct x end"); t.eq(data[1].components[1].x, 102, "linestring is correct x end");
t.eq(data[1].components[1].y, 1, "linestring is correct y end"); t.eq(data[1].components[1].y, 1, "linestring is correct y end");
} }
function test_Format_GeoJSON_multipleFeatures(t) { function test_Format_GeoJSON_multipleFeatures(t) {
t.plan(2); t.plan(2);
var feats = parser.read(multiple_features); var feats = parser.read(multiple_features);
t.eq(feats.length, 19, "parsing a feature collection returns the correct number of features."); t.eq(feats.length, 19, "parsing a feature collection returns the correct number of features.");
var types = {'Point':0, 'LineString':0, 'Polygon':0} var types = {'Point':0, 'LineString':0, 'Polygon':0}
@@ -179,40 +186,67 @@
function test_Format_GeoJSON_write(t) { function test_Format_GeoJSON_write(t) {
t.plan(10); t.plan(10);
var line_object = {"type": "FeatureCollection",
"members": [{"geometry": var line_object = {
{"type": "LineString", "type": "FeatureCollection",
"coordinates": [[-27.0703125, 59.4140625], "members": [
[-77.6953125, 20.7421875], {
[30.5859375, -36.2109375], "geometry": {
[67.1484375, 34.8046875]]}, "type": "LineString",
"type": "Feature", "coordinates": [
"id": 559, [-27.0703125, 59.4140625],
"properties": [-77.6953125, 20.7421875],
{ [30.5859375, -36.2109375],
"strokeColor": "red", [67.1484375, 34.8046875]
"title": "Feature 1", ]
"author": "Your Name Here"}}]}; },
"type": "Feature",
"id": 559,
"properties": {
"strokeColor": "red",
"title": "Feature 1",
"author": "Your Name Here"
}
}
]
};
data = parser.read(line_object); data = parser.read(line_object);
out = parser.write(data); out = parser.write(data);
serialized = '{"type":"FeatureCollection","members":[{"type":"Feature","id":559,"properties":{"strokeColor":"red","title":"Feature 1","author":"Your Name Here"},"geometry":{"type":"LineString","coordinates":[[-27.0703125,59.4140625],[-77.6953125,20.7421875],[30.5859375,-36.2109375],[67.1484375,34.8046875]]}}]}'; serialized = '{"type":"FeatureCollection","members":[{"type":"Feature","id":559,"properties":{"strokeColor":"red","title":"Feature 1","author":"Your Name Here"},"geometry":{"type":"LineString","coordinates":[[-27.0703125,59.4140625],[-77.6953125,20.7421875],[30.5859375,-36.2109375],[67.1484375,34.8046875]]}}]}';
t.eq(out, serialized, "input and output on line collections are the same"); t.eq(out, serialized, "input and output on line collections are the same");
var serialize_tests = [ var serialize_tests = [
[new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(1,2)), [
'{"type":"Feature","id":0,"properties":{},"geometry":{"type":"Point","coordinates":[1,2]}}'], new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(1,2)),
[new OpenLayers.Geometry.Point(1,2), '{"type":"Feature","id":0,"properties":{},"geometry":{"type":"Point","coordinates":[1,2]}}'
'{"type":"Point","coordinates":[1,2]}'], ],
[new OpenLayers.Geometry.MultiPoint([new OpenLayers.Geometry.Point(1,2)]), [
'{"type":"MultiPoint","coordinates":[[1,2]]}'], new OpenLayers.Geometry.Point(1,2),
[new OpenLayers.Geometry.LineString([new OpenLayers.Geometry.Point(1,2), new OpenLayers.Geometry.Point(3,4)]), '{"type":"Point","coordinates":[1,2]}'
'{"type":"LineString","coordinates":[[1,2],[3,4]]}'], ],
[new OpenLayers.Geometry.Polygon([ [
new OpenLayers.Geometry.LinearRing([ new OpenLayers.Geometry.MultiPoint([
new OpenLayers.Geometry.Point(1,2), new OpenLayers.Geometry.Point(1,2)
new OpenLayers.Geometry.Point(3,4), ]),
new OpenLayers.Geometry.Point(5,6)])]), '{"type":"MultiPoint","coordinates":[[1,2]]}'
'{"type":"Polygon","coordinates":[[[1,2],[3,4],[5,6],[1,2]]]}'] ],
[
new OpenLayers.Geometry.LineString([
new OpenLayers.Geometry.Point(1,2),
new OpenLayers.Geometry.Point(3,4)
]),
'{"type":"LineString","coordinates":[[1,2],[3,4]]}'
],
[
new OpenLayers.Geometry.Polygon([
new OpenLayers.Geometry.LinearRing([
new OpenLayers.Geometry.Point(1,2),
new OpenLayers.Geometry.Point(3,4),
new OpenLayers.Geometry.Point(5,6)
])
]),
'{"type":"Polygon","coordinates":[[[1,2],[3,4],[5,6],[1,2]]]}'
]
]; ];
serialize_tests[0][0].fid = 0; serialize_tests[0][0].fid = 0;
multiline = new OpenLayers.Geometry.MultiLineString([serialize_tests[3][0], serialize_tests[3][0]]); multiline = new OpenLayers.Geometry.MultiLineString([serialize_tests[3][0], serialize_tests[3][0]]);
@@ -229,29 +263,39 @@
} }
} }
function test_Format_GeoJSON_read_object(t) { function test_Format_GeoJSON_read_object(t) {
t.plan(1); t.plan(1);
var line_object = {"type": "FeatureCollection",
"members": [{"geometry": var line_object = {
{"type": "LineString", "type": "FeatureCollection",
"coordinates": [[-27.0703125, 59.4140625], "members": [
[-77.6953125, 20.7421875], {
[30.5859375, -36.2109375], "geometry": {
[67.1484375, 34.8046875]]}, "type": "LineString",
"type": "Feature", "coordinates": [
"id": 559, [-27.0703125, 59.4140625],
"properties": [-77.6953125, 20.7421875],
{ [30.5859375, -36.2109375],
"strokeColor": "red", [67.1484375, 34.8046875]
"title": "Feature 1", ]
"author": "Your Name Here"}}]}; },
"type": "Feature",
"id": 559,
"properties": {
"strokeColor": "red",
"title": "Feature 1",
"author": "Your Name Here"
}
}
]
};
data = parser.read(line_object); data = parser.read(line_object);
t.eq(data[0].fid, 559, "Can read data from an object correctly."); t.eq(data[0].fid, 559, "Can read data from an object correctly.");
} }
function test_Format_GeoJSON_read_attributes(t) { function test_Format_GeoJSON_read_attributes(t) {
t.plan(3); t.plan(3);
var parser = new OpenLayers.Format.GeoJSON(); var parser = new OpenLayers.Format.GeoJSON();
data = parser.read(line_feature); data = parser.read(line_feature);
t.eq(data[0].attributes['strokeColor'], 'red', 'read strokeColor attribute properly'); t.eq(data[0].attributes['strokeColor'], 'red', 'read strokeColor attribute properly');
@@ -259,7 +303,6 @@
t.eq(data[0].attributes['author'], 'Your Name Here', 'read author attribute properly'); t.eq(data[0].attributes['author'], 'Your Name Here', 'read author attribute properly');
} }
</script> </script>
</head> </head>
<body> <body>
+2 -2
View File
@@ -3,8 +3,6 @@
<script src="../../lib/OpenLayers.js"></script> <script src="../../lib/OpenLayers.js"></script>
<script type="text/javascript"> <script type="text/javascript">
function test_Format_GeoRSS_constructor(t) { function test_Format_GeoRSS_constructor(t) {
t.plan(4); t.plan(4);
@@ -16,8 +14,10 @@
t.eq(typeof format.read, "function", "format has a read function"); t.eq(typeof format.read, "function", "format has a read function");
t.eq(typeof format.write, "function", "format has a write function"); t.eq(typeof format.write, "function", "format has a write function");
} }
function test_Format_GeoRSS_serializeline(t) { function test_Format_GeoRSS_serializeline(t) {
t.plan(1); t.plan(1);
if (OpenLayers.Util.getBrowserName() == "msie") { if (OpenLayers.Util.getBrowserName() == "msie") {
//serialization currently not supported in IE //serialization currently not supported in IE
t.ok(true, "GeoRSS serialization not currently supported in IE"); t.ok(true, "GeoRSS serialization not currently supported in IE");
+2 -2
View File
@@ -3,8 +3,6 @@
<script src="../../lib/OpenLayers.js"></script> <script src="../../lib/OpenLayers.js"></script>
<script type="text/javascript"> <script type="text/javascript">
function test_Format_JSON_constructor(t) { function test_Format_JSON_constructor(t) {
t.plan(4); t.plan(4);
@@ -16,6 +14,7 @@
t.eq(typeof format.read, "function", "format has a read function"); t.eq(typeof format.read, "function", "format has a read function");
t.eq(typeof format.write, "function", "format has a write function"); t.eq(typeof format.write, "function", "format has a write function");
} }
function test_Format_JSON_parser(t) { function test_Format_JSON_parser(t) {
t.plan(2); t.plan(2);
@@ -25,6 +24,7 @@
t.eq(obj['a'], data['a'], "element with array parsed correctly."); t.eq(obj['a'], data['a'], "element with array parsed correctly.");
t.eq(obj['c'], data['c'], "element with number parsed correctly."); t.eq(obj['c'], data['c'], "element with number parsed correctly.");
} }
function test_Format_JSON_writer(t) { function test_Format_JSON_writer(t) {
t.plan(1); t.plan(1);
+42 -9
View File
@@ -12,30 +12,57 @@
} }
var multipoint = new OpenLayers.Feature.Vector( var multipoint = new OpenLayers.Feature.Vector(
new OpenLayers.Geometry.MultiPoint([ new OpenLayers.Geometry.MultiPoint([
points[0].geometry, points[1].geometry, points[2].geometry points[0].geometry,
points[1].geometry,
points[2].geometry
]) ])
); );
var linestrings = [ var linestrings = [
new OpenLayers.Feature.Vector( new OpenLayers.Feature.Vector(
new OpenLayers.Geometry.LineString([points[0].geometry, points[1].geometry, points[2].geometry]) new OpenLayers.Geometry.LineString([
points[0].geometry,
points[1].geometry,
points[2].geometry
])
), ),
new OpenLayers.Feature.Vector( new OpenLayers.Feature.Vector(
new OpenLayers.Geometry.LineString([points[3].geometry, points[4].geometry, points[5].geometry]) new OpenLayers.Geometry.LineString([
points[3].geometry,
points[4].geometry,
points[5].geometry
])
) )
]; ];
var multilinestring = new OpenLayers.Feature.Vector( var multilinestring = new OpenLayers.Feature.Vector(
new OpenLayers.Geometry.MultiLineString([ new OpenLayers.Geometry.MultiLineString([
linestrings[0].geometry, linestrings[1].geometry linestrings[0].geometry,
linestrings[1].geometry
]) ])
); );
var rings = [ var rings = [
new OpenLayers.Geometry.LinearRing([points[0].geometry, points[1].geometry, points[2].geometry]), new OpenLayers.Geometry.LinearRing([
new OpenLayers.Geometry.LinearRing([points[3].geometry, points[4].geometry, points[5].geometry]), points[0].geometry,
new OpenLayers.Geometry.LinearRing([points[6].geometry, points[7].geometry, points[8].geometry]), points[1].geometry,
new OpenLayers.Geometry.LinearRing([points[9].geometry, points[10].geometry, points[11].geometry]) points[2].geometry
]),
new OpenLayers.Geometry.LinearRing([
points[3].geometry,
points[4].geometry,
points[5].geometry
]),
new OpenLayers.Geometry.LinearRing([
points[6].geometry,
points[7].geometry,
points[8].geometry
]),
new OpenLayers.Geometry.LinearRing([
points[9].geometry,
points[10].geometry,
points[11].geometry
])
]; ];
var polygons = [ var polygons = [
@@ -49,7 +76,8 @@
var multipolygon = new OpenLayers.Feature.Vector( var multipolygon = new OpenLayers.Feature.Vector(
new OpenLayers.Geometry.MultiPolygon([ new OpenLayers.Geometry.MultiPolygon([
polygons[0].geometry, polygons[1].geometry polygons[0].geometry,
polygons[1].geometry
]) ])
); );
@@ -66,11 +94,14 @@
t.eq(typeof format.read, "function", "format has a read function"); t.eq(typeof format.read, "function", "format has a read function");
t.eq(typeof format.write, "function", "format has a write function"); t.eq(typeof format.write, "function", "format has a write function");
} }
function test_Format_WKT_write(t) { function test_Format_WKT_write(t) {
t.plan(7); t.plan(7);
var format = new OpenLayers.Format.WKT(); var format = new OpenLayers.Format.WKT();
// test a point // test a point
t.eq(format.write(points[0]), t.eq(format.write(points[0]),
"POINT(" + points[0].geometry.x + " " + points[0].geometry.y + ")", "POINT(" + points[0].geometry.x + " " + points[0].geometry.y + ")",
"format correctly writes Point WKT"); "format correctly writes Point WKT");
@@ -140,8 +171,10 @@
"format correctly writes GeometryCollection WKT"); "format correctly writes GeometryCollection WKT");
} }
function test_Format_WKT_read(t) { function test_Format_WKT_read(t) {
t.plan(7); t.plan(7);
var format = new OpenLayers.Format.WKT(); var format = new OpenLayers.Format.WKT();
/** /**
+7 -1
View File
@@ -2,6 +2,7 @@
<head> <head>
<script src="../../lib/OpenLayers.js"></script> <script src="../../lib/OpenLayers.js"></script>
<script type="text/javascript"> <script type="text/javascript">
var text = var text =
'<?xml version="1.0"?>' + '<?xml version="1.0"?>' +
'<ol:root xmlns="http://namespace.default.net" ' + '<ol:root xmlns="http://namespace.default.net" ' +
@@ -71,6 +72,7 @@
function test_Format_XML_write(t) { function test_Format_XML_write(t) {
t.plan(1); t.plan(1);
var format = new OpenLayers.Format.XML(); var format = new OpenLayers.Format.XML();
var doc = format.read(text); var doc = format.read(text);
var out = format.write(doc); var out = format.write(doc);
@@ -81,6 +83,7 @@
function test_Format_XML_createElementNS(t) { function test_Format_XML_createElementNS(t) {
t.plan(5); t.plan(5);
var format = new OpenLayers.Format.XML(); var format = new OpenLayers.Format.XML();
var uri = "http://foo.com"; var uri = "http://foo.com";
var prefix = "foo"; var prefix = "foo";
@@ -103,6 +106,7 @@
function test_Format_XML_createTextNode(t) { function test_Format_XML_createTextNode(t) {
t.plan(4); t.plan(4);
var format = new OpenLayers.Format.XML(); var format = new OpenLayers.Format.XML();
var value = Math.random().toString(); var value = Math.random().toString();
var node = format.createTextNode(value); var node = format.createTextNode(value);
@@ -144,6 +148,7 @@
function test_Format_XML_getAttributeNodeNS(t) { function test_Format_XML_getAttributeNodeNS(t) {
t.plan(5); t.plan(5);
var format = new OpenLayers.Format.XML(); var format = new OpenLayers.Format.XML();
var doc = format.read(text); var doc = format.read(text);
var olUri = "http://namespace.openlayers.org"; var olUri = "http://namespace.openlayers.org";
@@ -173,6 +178,7 @@
function test_Format_XML_getAttributeNS(t) { function test_Format_XML_getAttributeNS(t) {
t.plan(2); t.plan(2);
var format = new OpenLayers.Format.XML(); var format = new OpenLayers.Format.XML();
var doc = format.read(text); var doc = format.read(text);
var olUri = "http://namespace.openlayers.org"; var olUri = "http://namespace.openlayers.org";
@@ -194,6 +200,7 @@
function test_Format_XML_hasAttributeNS(t) { function test_Format_XML_hasAttributeNS(t) {
t.plan(2); t.plan(2);
var format = new OpenLayers.Format.XML(); var format = new OpenLayers.Format.XML();
var doc = format.read(text); var doc = format.read(text);
var olUri = "http://namespace.openlayers.org"; var olUri = "http://namespace.openlayers.org";
@@ -209,7 +216,6 @@
t.ok(found === false, "returns false for bad attribute"); t.ok(found === false, "returns false for bad attribute");
} }
</script> </script>
</head> </head>
<body> <body>
+1
View File
@@ -2,6 +2,7 @@
<head> <head>
<script src="../lib/OpenLayers.js"></script> <script src="../lib/OpenLayers.js"></script>
<script type="text/javascript"> <script type="text/javascript">
function test_01_Format_constructor(t) { function test_01_Format_constructor(t) {
t.plan(4); t.plan(4);
+3 -3
View File
@@ -25,7 +25,7 @@
t.ok( tile.id != null, "tile is given an id"); t.ok( tile.id != null, "tile is given an id");
t.ok( tile.id.startsWith("Tile_"), "tile's id starts correctly"); t.ok( tile.id.startsWith("Tile_"), "tile's id starts correctly");
t.ok( tile.events != null, "tile's events intitialized"); t.ok( tile.events != null, "tile's events intitialized");
}; }
function test_99_Tile_destroy(t) { function test_99_Tile_destroy(t) {
t.plan( 6 ); t.plan( 6 );
@@ -39,7 +39,7 @@
tile = new OpenLayers.Tile(layer, position, bounds, url, size); tile = new OpenLayers.Tile(layer, position, bounds, url, size);
tile.events.destroy = function() { tile.events.destroy = function() {
t.ok(true, "tile events destroy() called"); t.ok(true, "tile events destroy() called");
} };
tile.destroy(); tile.destroy();
@@ -50,7 +50,7 @@
t.ok(tile.position == null, "tile.position set to null"); t.ok(tile.position == null, "tile.position set to null");
t.ok(tile.events == null, "tile.events set to null"); t.ok(tile.events == null, "tile.events set to null");
}; }
</script> </script>
</head> </head>