Don't rely on OSM IDs being in range of JS numbers

This commit is contained in:
John Firebaugh
2013-01-28 10:15:17 -05:00
parent 562a161896
commit 2ac0f1dc26
2 changed files with 9 additions and 9 deletions
+3 -3
View File
@@ -20,7 +20,7 @@ iD.Entity.id.fromOSM = function (type, id) {
};
iD.Entity.id.toOSM = function (id) {
return +id.slice(1);
return id.slice(1);
};
// A function suitable for use as the second argument to d3.selection#data().
@@ -67,11 +67,11 @@ iD.Entity.prototype = {
},
created: function() {
return this._updated && this.osmId() < 0;
return this._updated && this.osmId().charAt(0) === '-';
},
modified: function() {
return this._updated && this.osmId() > 0;
return this._updated && this.osmId().charAt(0) !== '-';
},
intersects: function(extent, resolver) {
+6 -6
View File
@@ -22,13 +22,13 @@ describe('iD.Entity', function () {
describe(".fromOSM", function () {
it("returns a ID string unique across entity types", function () {
expect(iD.Entity.id.fromOSM('node', 1)).to.equal("n1");
expect(iD.Entity.id.fromOSM('node', '1')).to.equal("n1");
});
});
describe(".toOSM", function () {
it("reverses fromOSM", function () {
expect(iD.Entity.id.toOSM(iD.Entity.id.fromOSM('node', 1))).to.equal(1);
expect(iD.Entity.id.toOSM(iD.Entity.id.fromOSM('node', '1'))).to.equal('1');
});
});
});
@@ -70,10 +70,10 @@ describe('iD.Entity', function () {
});
describe("#osmId", function () {
it("returns a numeric osm id", function () {
expect(iD.Entity({id: 'w1234'}).osmId()).to.eql(1234);
expect(iD.Entity({id: 'n1234'}).osmId()).to.eql(1234);
expect(iD.Entity({id: 'r1234'}).osmId()).to.eql(1234);
it("returns an OSM ID as a string", function () {
expect(iD.Entity({id: 'w1234'}).osmId()).to.eql('1234');
expect(iD.Entity({id: 'n1234'}).osmId()).to.eql('1234');
expect(iD.Entity({id: 'r1234'}).osmId()).to.eql('1234');
});
});