Prefix ids for objects, separate counters for new objects of each type

This commit is contained in:
Tom MacWright
2012-11-06 14:12:40 -05:00
parent 50f8e7f224
commit c9aa40a38d
3 changed files with 18 additions and 26 deletions
+10 -10
View File
@@ -1,8 +1,5 @@
iD.Connection = function(graph) {
var nextNode = -1,
nextWay = -1,
nextRelation = -1,
apiURL = 'http://www.openstreetmap.org/api/0.6/';
var apiURL = 'http://www.openstreetmap.org/api/0.6/';
var connection = {};
@@ -18,8 +15,8 @@ iD.Connection = function(graph) {
function getNodes(obj) {
var nodes = [], nelems = obj.getElementsByTagName('nd');
for (var i = 0; i < nelems.length; i++) {
nodes[i] = +nelems[i].attributes.ref.nodeValue;
for (var i = 0, l = nelems.length; i < l; i++) {
nodes[i] = 'n' + nelems[i].attributes.ref.nodeValue;
}
return nodes;
}
@@ -39,9 +36,9 @@ iD.Connection = function(graph) {
var members = [],
elems = obj.getElementsByTagName('member');
for (var i = 0; i < elems.length; i++) {
for (var i = 0, l = elems.length; i < l; i++) {
members[i] = {
id: +elems[i].attributes.ref.nodeValue,
id: elems[i].attributes.type.nodeValue[0] + elems[i].attributes.ref.nodeValue,
type: elems[i].attributes.type.nodeValue,
role: elems[i].attributes.role.nodeValue
};
@@ -66,12 +63,15 @@ iD.Connection = function(graph) {
nodes: getNodes(obj),
tags: getTags(obj)
};
var numbers = {id: true, lat: true, lon: true };
for (var i = 0; i < obj.attributes.length; i++) {
var n = obj.attributes[i].nodeName;
var v = obj.attributes[i].nodeValue;
o[n] = numbers[n] ? +v : v;
o[n] = v;
}
if (o.lat) o.lat = parseFloat(o.lat);
if (o.lon) o.lon = parseFloat(o.lon);
o._id = o.id;
o.id = o.type[0] + o.id;
return o;
}
+4 -12
View File
@@ -1,9 +1,10 @@
iD.Util = {};
iD.Util._id = -1;
iD.Util._counters = {};
iD.Util.id = function() {
return iD.Util._id--;
iD.Util.id = function(counter) {
if (!iD.Util._counters[counter]) iD.Util._counters[counter] = 0;
return iD.Util._counters[counter];
};
iD.Util.friendlyName = function(entity) {
@@ -30,15 +31,6 @@ iD.Util.friendlyName = function(entity) {
return n.length === 0 ? 'unknown' : n.join('; ');
};
iD.Util.extend = function(child, parent) {
for (var property in parent.prototype) {
if (typeof child.prototype[property] == "undefined") {
child.prototype[property] = parent.prototype[property];
}
}
return child;
};
iD.Util.codeWindow = function(content) {
top.win = window.open('','contentWindow',
'width=350,height=350,menubar=0' +
+4 -4
View File
@@ -6,7 +6,7 @@ iD.actions.AddPlace = {
type: 'node',
lat: ll[1],
lon: ll[0],
id: iD.Util.id(),
id: iD.Util.id('node'),
tags: {}
};
},
@@ -54,7 +54,7 @@ iD.actions.AddRoad = {
type: 'node',
lat: ll[1],
lon: ll[0],
id: iD.Util.id(),
id: iD.Util.id('node'),
modified: true,
tags: {}
};
@@ -67,7 +67,7 @@ iD.actions.AddRoad = {
highway: 'residential'
},
modified: true,
id: iD.Util.id()
id: iD.Util.id('way')
};
},
enter: function() {
@@ -119,7 +119,7 @@ iD.actions.DrawRoad = function(way) {
type: 'node',
lat: ll[1],
lon: ll[0],
id: iD.Util.id(),
id: iD.Util.id('node'),
modified: true,
tags: {}
};