From 51370330f24d75ec6f4f82515a3f448f1e50e3c9 Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Tue, 27 Nov 2012 18:37:20 -0500 Subject: [PATCH] Reload data, fixes #129, also fixes jshint --- js/id/actions/modes.js | 2 +- js/id/connection.js | 7 +------ js/id/graph/history.js | 1 + js/id/graph/way.js | 2 +- js/id/id.js | 4 ++++ js/id/renderer/map.js | 28 +++++++++++++--------------- 6 files changed, 21 insertions(+), 23 deletions(-) diff --git a/js/id/actions/modes.js b/js/id/actions/modes.js index 5ac6bb895..17302e165 100644 --- a/js/id/actions/modes.js +++ b/js/id/actions/modes.js @@ -8,7 +8,7 @@ iD.modes = {}; iD.modes._node = function(ll) { return iD.Node({ lat: ll[1], - lon: ll[0], + lon: ll[0] }); }; diff --git a/js/id/connection.js b/js/id/connection.js index 5f74d543b..eaa25ea93 100644 --- a/js/id/connection.js +++ b/js/id/connection.js @@ -1,4 +1,5 @@ iD.Connection = function() { + var event = d3.dispatch('auth'), apiURL = 'http://www.openstreetmap.org', connection = {}, @@ -12,11 +13,6 @@ iD.Connection = function() { [box[0][0], box[1][1], box[1][0], box[0][1]], callback); } - // Request data within the bbox from an external OSM server. - function wayFromAPI(id, callback) { - loadFromURL(apiURL + '/api/0.6/way/' + id + '/full', callback); - } - function loadFromURL(url, callback) { d3.xml(url, function(err, dom) { callback(parse(dom)); }); } @@ -155,7 +151,6 @@ iD.Connection = function() { }; connection.bboxFromAPI = bboxFromAPI; - connection.wayFromAPI = wayFromAPI; connection.loadFromURL = loadFromURL; connection.userDetails = userDetails; connection.authenticate = authenticate; diff --git a/js/id/graph/history.js b/js/id/graph/history.js index 7f962b4d8..12a15ed0d 100644 --- a/js/id/graph/history.js +++ b/js/id/graph/history.js @@ -5,6 +5,7 @@ iD.History = function() { }; iD.History.prototype = { + graph: function() { return this.stack[this.index]; }, diff --git a/js/id/graph/way.js b/js/id/graph/way.js index a8f68c087..81590be45 100644 --- a/js/id/graph/way.js +++ b/js/id/graph/way.js @@ -9,4 +9,4 @@ iD.Way.isClosed = function(w) { return (!w.nodes.length) || w.nodes[w.nodes.length - 1].id === w.nodes[0].id; -} +}; diff --git a/js/id/id.js b/js/id/id.js index bfb5b384c..b94bd054c 100644 --- a/js/id/id.js +++ b/js/id/id.js @@ -73,6 +73,10 @@ var iD = function(container) { var l = iD.loading('committing changes to openstreetmap'); connection.putChangeset(map.history.changes(), e.comment, function() { l.remove(); + map.history = new iD.History(); + map.flush(); + map.update(); + map.redraw(); }); } connection.authenticate(function() { diff --git a/js/id/renderer/map.js b/js/id/renderer/map.js index d3849c57b..740f225ca 100644 --- a/js/id/renderer/map.js +++ b/js/id/renderer/map.js @@ -1,9 +1,8 @@ iD.Map = function(elem, connection) { - var map = {}, + var map = { history: iD.History() }, dimensions = [], dispatch = d3.dispatch('move', 'update'), - history = iD.History(), inspector = iD.Inspector(), parent = d3.select(elem), selection = null, @@ -21,17 +20,17 @@ iD.Map = function(elem, connection) { .origin(function(entity) { var p = projection(ll2a(entity)); only = iD.Util.trueObj([entity.id].concat( - _.pluck(history.graph().parents(entity.id), 'id'))); + _.pluck(map.history.graph().parents(entity.id), 'id'))); return { x: p[0], y: p[1] }; }) .on('dragstart', function() { - history.perform(iD.actions.noop()); + map.history.perform(iD.actions.noop()); d3.event.sourceEvent.stopPropagation(); }) .on('drag', function(entity) { var to = projection.invert([d3.event.x, d3.event.y]); d3.event.sourceEvent.stopPropagation(); - history.replace(iD.actions.move(entity, to)); + map.history.replace(iD.actions.move(entity, to)); redraw(only); }) .on('dragend', update), @@ -124,7 +123,7 @@ iD.Map = function(elem, connection) { var z = getZoom(), all = [], ways = [], areas = [], points = [], waynodes = [], extent = getExtent(), - graph = history.graph(); + graph = map.history.graph(); if (!only) { all = graph.intersects(extent); @@ -343,7 +342,7 @@ iD.Map = function(elem, connection) { if (result instanceof Error) { // TODO: handle } else { - history.merge(result); + map.history.merge(result); drawVector(); } }); @@ -369,7 +368,7 @@ iD.Map = function(elem, connection) { selection = entity.id; d3.select('.inspector-wrap') .style('display', 'block') - .datum(history.graph().fetch(entity.id)).call(inspector); + .datum(map.history.graph().fetch(entity.id)).call(inspector); redraw(); } @@ -430,17 +429,17 @@ iD.Map = function(elem, connection) { } function perform(action) { - history.perform(action); + map.history.perform(action); update(); } function undo() { - history.undo(); + map.history.undo(); update(); } function redo() { - history.redo(); + map.history.redo(); update(); } @@ -503,8 +502,8 @@ iD.Map = function(elem, connection) { return map; } - function commit() { - connection.putChangeset(history.changes()); + function flush() { + apiTilesLoaded = {}; } map.download = download; @@ -525,7 +524,6 @@ iD.Map = function(elem, connection) { map.projection = projection; map.setSize = setSize; - map.history = history; map.surface = surface; map.perform = perform; @@ -534,7 +532,7 @@ iD.Map = function(elem, connection) { map.redraw = redraw; - map.commit = commit; + map.flush = flush; setSize([parent.node().offsetWidth, parent.node().offsetHeight]); hideInspector();