Minimize functional tricks in connection

This commit is contained in:
Tom MacWright
2012-11-16 11:34:20 -05:00
parent 656349b7aa
commit 330da451f2
2 changed files with 24 additions and 32 deletions

View File

@@ -15,7 +15,9 @@ iD.Connection = function() {
}
function loadFromURL(url, callback) {
d3.xml(url, parse(callback));
d3.xml(url, function(err, dom) {
callback(parse(dom));
});
}
function getNodes(obj) {
@@ -81,24 +83,22 @@ iD.Connection = function() {
return iD.Entity(o);
}
function parse(callback) {
return function(err, dom) {
if (!dom.childNodes) return callback(new Error('Bad request'));
var root = dom.childNodes[0];
var entities = {};
refNodes = {};
var addEntity = function (obj) {
var o = objectData(obj);
if (o.type === 'node') o._poi = !refNodes[o.id];
entities[o.id] = o;
};
function parse(dom) {
if (!dom.childNodes) return new Error('Bad request');
var root = dom.childNodes[0];
var entities = {};
refNodes = {};
function addEntity(obj) {
var o = objectData(obj);
if (o.type === 'node') o._poi = !refNodes[o.id];
entities[o.id] = o;
}
_.forEach(root.getElementsByTagName('way'), addEntity);
_.forEach(root.getElementsByTagName('node'), addEntity);
_.forEach(root.getElementsByTagName('relation'), addEntity);
_.forEach(root.getElementsByTagName('way'), addEntity);
_.forEach(root.getElementsByTagName('node'), addEntity);
_.forEach(root.getElementsByTagName('relation'), addEntity);
callback(iD.Graph(entities));
};
return iD.Graph(entities);
}
connection.bboxFromAPI = bboxFromAPI;

View File

@@ -19,10 +19,7 @@ iD.Map = function(elem) {
}
function roundCoords(c) {
return [
Math.floor(c[0]),
Math.floor(c[1])
];
return [Math.floor(c[0]), Math.floor(c[1])];
}
var map = {},
@@ -103,9 +100,12 @@ iD.Map = function(elem) {
var tileclient = iD.Tiles(tilegroup, projection);
// For one-way roads, find the length of a triangle
var arrow = surface.append('text').text('►');
var alength = arrow.node().getComputedTextLength();
arrow.remove();
var alength = (function() {
var arrow = surface.append('text').text('►');
var alength = arrow.node().getComputedTextLength();
arrow.remove();
return alength;
})();
function classActive(d) { return d.id === selection; }
@@ -171,14 +171,6 @@ iD.Map = function(elem) {
hit_g.selectAll('rect.handle').remove();
}
function hideFills() {
fill_g.selectAll('path').remove();
}
function hideMarkers() {
hit_g.selectAll('g.marker').remove();
}
function drawFills(areas) {
var fills = fill_g.selectAll('path').data(areas, key);
fills.exit().remove();