OpenLayers OpenLayers

root/trunk/openlayers/tests/Format/OSM.html

Revision 6719, 4.7 kB (checked in by crschmidt, 9 months ago)

bring back r6710 now that popup changes are in

  • Property svn:eol-style set to native
Line 
1 <html> 
2 <head> 
3     <script src="../../lib/OpenLayers.js"></script>
4     <script src="../data/osm.js"></script>
5     <script type="text/javascript">
6    
7     function test_Format_OSM_constructor(t) {
8         t.plan(4);
9          
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");
17     }
18     function test_Format_OSM_node(t) {
19         t.plan(4);
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");
27     }
28     function test_Format_OSM_node_with_tags(t) {
29         t.plan(5);
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");
38     }
39     function test_Format_OSM_way(t) {
40         t.plan(8);
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");
52     }
53    
54     function test_Format_OSM_node_way(t) {
55         t.plan(5)
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");
64     }
65    
66     function test_Format_OSM_node_way_checkTags(t) {
67         t.plan(9)
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");
71        
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");
75        
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");
79        
80         feat = features[0];
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");
85     }
86
87     function test_Format_OSM_serialize(t) {
88         t.plan(4);
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");
95         }
96     }   
97     </script>
98 </head> 
99 <body> 
100 </body> 
101 </html> 
Note: See TracBrowser for help on using the browser.