From 5f02f348de2853a029e8355ecac630035c267934 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Thu, 25 Jul 2013 11:46:41 -0700 Subject: [PATCH] Include GPX and overlay layers in imagery_used Fixes #1463 --- js/id/core/connection.js | 8 ++++---- js/id/core/history.js | 23 ++++++++++++++-------- js/id/modes/save.js | 2 +- js/id/renderer/background.js | 37 ++++++++++++++++++++++-------------- 4 files changed, 43 insertions(+), 27 deletions(-) diff --git a/js/id/core/connection.js b/js/id/core/connection.js index e3197eb80..7442a9992 100644 --- a/js/id/core/connection.js +++ b/js/id/core/connection.js @@ -203,9 +203,9 @@ iD.Connection = function() { }; }; - connection.changesetTags = function(comment, imagery_used) { + connection.changesetTags = function(comment, imageryUsed) { var tags = { - imagery_used: imagery_used.join(';'), + imagery_used: imageryUsed.join(';'), created_by: 'iD ' + iD.version }; @@ -216,12 +216,12 @@ iD.Connection = function() { return tags; }; - connection.putChangeset = function(changes, comment, imagery_used, callback) { + connection.putChangeset = function(changes, comment, imageryUsed, callback) { oauth.xhr({ method: 'PUT', path: '/api/0.6/changeset/create', options: { header: { 'Content-Type': 'text/xml' } }, - content: JXON.stringify(connection.changesetJXON(connection.changesetTags(comment, imagery_used))) + content: JXON.stringify(connection.changesetJXON(connection.changesetTags(comment, imageryUsed))) }, function(err, changeset_id) { if (err) return callback(err); oauth.xhr({ diff --git a/js/id/core/history.js b/js/id/core/history.js index badcc57c2..cea3be181 100644 --- a/js/id/core/history.js +++ b/js/id/core/history.js @@ -1,6 +1,6 @@ iD.History = function(context) { var stack, index, tree, - imagery_used = 'Bing', + imageryUsed = ['Bing'], dispatch = d3.dispatch('change', 'undone', 'redone'), lock = false; @@ -21,7 +21,7 @@ iD.History = function(context) { return { graph: graph, annotation: annotation, - imagery_used: imagery_used + imageryUsed: imageryUsed }; } @@ -162,11 +162,18 @@ iD.History = function(context) { return this.difference().length(); }, - imagery_used: function(source) { - if (source) imagery_used = source; - else return _.without( - _.unique(_.pluck(stack.slice(1, index + 1), 'imagery_used')), - undefined, 'Custom'); + imageryUsed: function(sources) { + if (sources) { + imageryUsed = sources; + return history; + } else { + return _(stack.slice(1, index + 1)) + .pluck('imageryUsed') + .flatten() + .unique() + .without(undefined, 'Custom') + .value(); + } }, reset: function() { @@ -182,7 +189,7 @@ iD.History = function(context) { var s = stack.map(function(i) { var x = { entities: i.graph.entities }; - if (i.imagery_used) x.imagery_used = i.imagery_used; + if (i.imageryUsed) x.imageryUsed = i.imageryUsed; if (i.annotation) x.annotation = i.annotation; return x; }); diff --git a/js/id/modes/save.js b/js/id/modes/save.js index 019716538..3566b1dc3 100644 --- a/js/id/modes/save.js +++ b/js/id/modes/save.js @@ -24,7 +24,7 @@ iD.modes.Save = function(context) { context.connection().putChangeset( context.history().changes(iD.actions.DiscardTags(context.history().difference())), e.comment, - context.history().imagery_used(), + context.history().imageryUsed(), function(err, changeset_id) { loading.close(); if (err) { diff --git a/js/id/renderer/background.js b/js/id/renderer/background.js index 78b7754f7..7a13260fa 100644 --- a/js/id/renderer/background.js +++ b/js/id/renderer/background.js @@ -22,13 +22,13 @@ iD.Background = function(context) { }); } - function updateHash() { + function updateImagery() { var b = background.baseLayerSource().data, o = overlayLayers.map(function (d) { return d.source().data.sourcetag; }).join(','), q = iD.util.stringQs(location.hash.substring(1)); - var tag = b && b.sourcetag; - if (!tag && b && b.name === 'Custom') { + var tag = b.sourcetag; + if (!tag && b.name === 'Custom') { tag = 'custom:' + b.template; } @@ -45,6 +45,23 @@ iD.Background = function(context) { } location.replace('#' + iD.util.qsString(q, true)); + + var imageryUsed = []; + if (b.name === 'Custom') { + imageryUsed.push('Custom (' + b.template + ')'); + } else { + imageryUsed.push(b.sourcetag || b.name); + } + + overlayLayers.forEach(function (d) { + imageryUsed.push(d.source().data.sourcetag || d.source().data.name); + }); + + if (background.showsGpxLayer()) { + imageryUsed.push('Local GPX'); + } + + context.history().imageryUsed(imageryUsed); } function background(selection) { @@ -101,15 +118,7 @@ iD.Background = function(context) { baseLayer.source(d); dispatch.change(); - updateHash(); - - if (d.data.name === 'Custom (customized)') { - context.history() - .imagery_used('Custom (' + d.data.template + ')'); - } else { - context.history() - .imagery_used(d.data.sourcetag || d.data.name); - } + updateImagery(); return background; }; @@ -150,7 +159,7 @@ iD.Background = function(context) { if (layer.source() === d) { overlayLayers.splice(i, 1); dispatch.change(); - updateHash(); + updateImagery(); return; } } @@ -162,7 +171,7 @@ iD.Background = function(context) { overlayLayers.push(layer); dispatch.change(); - updateHash(); + updateImagery(); }; background.nudge = function(d, zoom) {