tests, examples, modification to proxy.cgi, etc. This should allow one to build an OpenLayers based OpenStreetMap editor with some effort, and makes it trivially simple to drop OpenStreetMap data from the API into your OpenLayers application. r=ahocevar,elemoine (Closes #1271) git-svn-id: http://svn.openlayers.org/trunk/openlayers@5902 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
100 lines
4.6 KiB
HTML
100 lines
4.6 KiB
HTML
<html>
|
|
<head>
|
|
<script src="../../lib/OpenLayers.js"></script>
|
|
<script src="../data/osm.js"></script>
|
|
<script type="text/javascript">
|
|
|
|
function test_Format_OSM_constructor(t) {
|
|
t.plan(4);
|
|
|
|
var options = {'foo': 'bar'};
|
|
var format = new OpenLayers.Format.OSM(options);
|
|
t.ok(format instanceof OpenLayers.Format.OSM,
|
|
"new OpenLayers.Format.OSM returns object" );
|
|
t.eq(format.foo, "bar", "constructor sets options correctly");
|
|
t.eq(typeof format.read, "function", "format has a read function");
|
|
t.eq(typeof format.write, "function", "format has a write function");
|
|
}
|
|
function test_Format_OSM_node(t) {
|
|
t.plan(4);
|
|
var f = new OpenLayers.Format.OSM();
|
|
var features = f.read(osm_test_data['node']);
|
|
var feat = features[0];
|
|
t.eq(feat.attributes, {}, "attributes is empty");
|
|
t.eq(feat.osm_id, 200545, "internal osm_id property set correctly");
|
|
t.eq(feat.geometry.x, -1.8166417, "lon is correct");
|
|
t.eq(feat.geometry.y, 52.5503033, "lat is correct");
|
|
}
|
|
function test_Format_OSM_node_with_tags(t) {
|
|
t.plan(4);
|
|
var f = new OpenLayers.Format.OSM();
|
|
var features = f.read(osm_test_data['node_with_tags']);
|
|
var feat = features[0];
|
|
t.eq(feat.attributes, {'a':'b'}, "attributes match");
|
|
t.eq(feat.osm_id, 200545, "internal osm_id property set correctly");
|
|
t.eq(feat.geometry.x, -1.8166417, "lon is correct");
|
|
t.eq(feat.geometry.y, 52.5503033, "lat is correct");
|
|
}
|
|
function test_Format_OSM_way(t) {
|
|
t.plan(7);
|
|
var f = new OpenLayers.Format.OSM();
|
|
var features = f.read(osm_test_data['way']);
|
|
t.eq(features.length, 1, "One feature");
|
|
var feat = features[0];
|
|
t.eq(feat.osm_id, 4685537, "OSM ID set correctly.");
|
|
t.eq(feat.geometry.CLASS_NAME, "OpenLayers.Geometry.Polygon", "returned as polygon");
|
|
t.eq(feat.geometry.components[0].components.length, 11, "Correct number of components");
|
|
t.eq(feat.geometry.components[0].components[0].osm_id, 29783472, "OSM ID set on components");
|
|
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");
|
|
t.eq(feat.attributes.landuse, "school", "landuse attribute correct");
|
|
}
|
|
|
|
function test_Format_OSM_node_way(t) {
|
|
t.plan(5)
|
|
var f = new OpenLayers.Format.OSM();
|
|
var features = f.read(osm_test_data['node_way']);
|
|
t.eq(features.length, 1, "One feature");
|
|
var feat = features[0];
|
|
t.eq(feat.osm_id, 21329267, "OSM ID set correctly");
|
|
t.eq(feat.attributes.highway, "unclassified", "highway attribute is correct.");
|
|
t.eq(feat.geometry.CLASS_NAME, "OpenLayers.Geometry.LineString", "returned as linestring");
|
|
t.eq(feat.geometry.components.length, 12, "correct number of segments");
|
|
}
|
|
|
|
function test_Format_OSM_node_way_checkTags(t) {
|
|
t.plan(9)
|
|
var f = new OpenLayers.Format.OSM({'checkTags': true});
|
|
var features = f.read(osm_test_data['node_way']);
|
|
t.eq(features.length, 3, "multiple features");
|
|
|
|
var feat = features[1];
|
|
t.eq(feat.geometry.CLASS_NAME, "OpenLayers.Geometry.Point", "point class");
|
|
t.ok(feat.attributes != {}, "feature has attributes");
|
|
|
|
var feat = features[2];
|
|
t.eq(feat.geometry.CLASS_NAME, "OpenLayers.Geometry.Point", "point class");
|
|
t.ok(feat.attributes != {}, "feature has attributes");
|
|
|
|
feat = features[0];
|
|
t.eq(feat.osm_id, 21329267, "OSM ID set correctly");
|
|
t.eq(feat.attributes.highway, "unclassified", "highway attribute is correct.");
|
|
t.eq(feat.geometry.CLASS_NAME, "OpenLayers.Geometry.LineString", "returned as linestring");
|
|
t.eq(feat.geometry.components.length, 12, "correct number of segments");
|
|
}
|
|
|
|
function test_Format_OSM_serialize(t) {
|
|
t.plan(4);
|
|
var f = new OpenLayers.Format.OSM({'checkTags': true});
|
|
for (var key in osm_serialized_data) {
|
|
var input = f.read(osm_test_data[key]);
|
|
var output = f.write(input);
|
|
output = output.replace(/<\?[^>]*\?>/, '');
|
|
t.eq(output, osm_serialized_data[key], key + " serialized correctly");
|
|
}
|
|
}
|
|
</script>
|
|
</head>
|
|
<body>
|
|
</body>
|
|
</html>
|