diff --git a/js/iD/Connection.js b/js/iD/Connection.js index 0f779676a..661ee07dc 100755 --- a/js/iD/Connection.js +++ b/js/iD/Connection.js @@ -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; } diff --git a/js/iD/Util.js b/js/iD/Util.js index 55f908233..c3dde3ebf 100644 --- a/js/iD/Util.js +++ b/js/iD/Util.js @@ -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' + diff --git a/js/iD/actions/actions.js b/js/iD/actions/actions.js index 31d1477bb..03f20ccca 100644 --- a/js/iD/actions/actions.js +++ b/js/iD/actions/actions.js @@ -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: {} };