3
<script src="../../lib/OpenLayers.js"></script>
4
<script src="../data/osm.js"></script>
5
<script type="text/javascript">
7
function test_Format_OSM_constructor(t) {
10
var options = {'foo': 'bar'};
11
var format = new OpenLayers.Format.OSM(options);
12
t.ok(format instanceof OpenLayers.Format.OSM,
13
"new OpenLayers.Format.OSM returns object" );
14
t.eq(format.foo, "bar", "constructor sets options correctly");
15
t.eq(typeof format.read, "function", "format has a read function");
16
t.eq(typeof format.write, "function", "format has a write function");
18
function test_Format_OSM_node(t) {
20
var f = new OpenLayers.Format.OSM();
21
var features = f.read(osm_test_data['node']);
22
var feat = features[0];
23
t.eq(feat.attributes, {}, "attributes is empty");
24
t.eq(feat.osm_id, 200545, "internal osm_id property set correctly");
25
t.eq(feat.geometry.x, -1.8166417, "lon is correct");
26
t.eq(feat.geometry.y, 52.5503033, "lat is correct");
28
function test_Format_OSM_node_with_tags(t) {
30
var f = new OpenLayers.Format.OSM();
31
var features = f.read(osm_test_data['node_with_tags']);
32
var feat = features[0];
33
t.eq(feat.attributes, {'a':'b'}, "attributes match");
34
t.eq(feat.osm_id, 200545, "internal osm_id property set correctly");
35
t.eq(feat.fid, "node.200545", "OSM-based FID set correctly.");
36
t.eq(feat.geometry.x, -1.8166417, "lon is correct");
37
t.eq(feat.geometry.y, 52.5503033, "lat is correct");
39
function test_Format_OSM_way(t) {
41
var f = new OpenLayers.Format.OSM();
42
var features = f.read(osm_test_data['way']);
43
t.eq(features.length, 1, "One feature");
44
var feat = features[0];
45
t.eq(feat.osm_id, 4685537, "OSM ID set correctly.");
46
t.eq(feat.fid, "way.4685537", "OSM-based FID set correctly.");
47
t.eq(feat.geometry.CLASS_NAME, "OpenLayers.Geometry.Polygon", "returned as polygon");
48
t.eq(feat.geometry.components[0].components.length, 11, "Correct number of components");
49
t.eq(feat.geometry.components[0].components[0].osm_id, 29783472, "OSM ID set on components");
50
t.eq(feat.geometry.toString(), "POLYGON((-1.8164007 52.5501836,-1.8170311 52.5506035,-1.8164092 52.5509559,-1.8169385 52.5513103,-1.8159626 52.5517893,-1.8145067 52.5518461,-1.8143197 52.5511883,-1.8141177 52.5506446,-1.8151451 52.5501275,-1.8157703 52.5505521,-1.8164007 52.5501836))", "WKT of feature is correct");
51
t.eq(feat.attributes.landuse, "school", "landuse attribute correct");
54
function test_Format_OSM_node_way(t) {
56
var f = new OpenLayers.Format.OSM();
57
var features = f.read(osm_test_data['node_way']);
58
t.eq(features.length, 1, "One feature");
59
var feat = features[0];
60
t.eq(feat.osm_id, 21329267, "OSM ID set correctly");
61
t.eq(feat.attributes.highway, "unclassified", "highway attribute is correct.");
62
t.eq(feat.geometry.CLASS_NAME, "OpenLayers.Geometry.LineString", "returned as linestring");
63
t.eq(feat.geometry.components.length, 12, "correct number of segments");
66
function test_Format_OSM_node_way_checkTags(t) {
68
var f = new OpenLayers.Format.OSM({'checkTags': true});
69
var features = f.read(osm_test_data['node_way']);
70
t.eq(features.length, 3, "multiple features");
72
var feat = features[1];
73
t.eq(feat.geometry.CLASS_NAME, "OpenLayers.Geometry.Point", "point class");
74
t.ok(feat.attributes != {}, "feature has attributes");
76
var feat = features[2];
77
t.eq(feat.geometry.CLASS_NAME, "OpenLayers.Geometry.Point", "point class");
78
t.ok(feat.attributes != {}, "feature has attributes");
81
t.eq(feat.osm_id, 21329267, "OSM ID set correctly");
82
t.eq(feat.attributes.highway, "unclassified", "highway attribute is correct.");
83
t.eq(feat.geometry.CLASS_NAME, "OpenLayers.Geometry.LineString", "returned as linestring");
84
t.eq(feat.geometry.components.length, 12, "correct number of segments");
87
function test_Format_OSM_serialize(t) {
89
var f = new OpenLayers.Format.OSM({'checkTags': true});
90
for (var key in osm_serialized_data) {
91
var input = f.read(osm_test_data[key]);
92
var output = f.write(input);
93
output = output.replace(/<\?[^>]*\?>/, '');
94
t.eq(output, osm_serialized_data[key], key + " serialized correctly");