Set a FID on OSM features. Includes tests. Original patch by kleptog

(thx), r=me (Closes #1351


git-svn-id: http://svn.openlayers.org/trunk/openlayers@6181 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
crschmidt
2008-02-10 16:18:48 +00:00
parent c70fb21103
commit 03248296e7
2 changed files with 6 additions and 2 deletions

View File

@@ -131,6 +131,7 @@ OpenLayers.Format.OSM = OpenLayers.Class(OpenLayers.Format.XML, {
var feat = new OpenLayers.Feature.Vector(geometry,
ways[i].tags);
feat.osm_id = parseInt(ways[i].id);
feat.fid = "way." + feat.osm_id;
feat_list[i] = feat;
}
for (var node_id in nodes) {
@@ -156,6 +157,7 @@ OpenLayers.Format.OSM = OpenLayers.Class(OpenLayers.Format.XML, {
this.internalProjection);
}
feat.osm_id = parseInt(node_id);
feat.fid = "node." + feat.osm_id;
feat_list.push(feat);
}
// Memory cleanup

View File

@@ -26,22 +26,24 @@
t.eq(feat.geometry.y, 52.5503033, "lat is correct");
}
function test_Format_OSM_node_with_tags(t) {
t.plan(4);
t.plan(5);
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.fid, "node.200545", "OSM-based FID 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);
t.plan(8);
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.fid, "way.4685537", "OSM-based FID 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");