From d2f3d161e5863be2d0ebe6efd3d5bee8b5058e62 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Wed, 27 Mar 2013 14:24:59 -0700 Subject: [PATCH] Eliminate attribution flashing (fixes #1134) --- js/id/ui/attribution.js | 63 +++++++++++++++++++++++++++-------------- 1 file changed, 41 insertions(+), 22 deletions(-) diff --git a/js/id/ui/attribution.js b/js/id/ui/attribution.js index 9c4ecb7a7..eb3182e46 100644 --- a/js/id/ui/attribution.js +++ b/js/id/ui/attribution.js @@ -2,34 +2,53 @@ iD.ui.Attribution = function(context) { var selection; function update() { - var d = context.background().source(); + if (!context.background().source()) { + selection.html(''); + return + } - var provided_by = selection - .html('') + var attribution = selection.selectAll('.provided-by') + .data([context.background().source()], function(d) { return d.data.name; }); + + attribution.enter() .append('span') - .attr('class', 'provided-by'); + .attr('class', 'provided-by') + .each(function(d) { + var source = d.data.sourcetag || d.data.name; - if (!d) return; + if (d.data.logo) { + source = ''; + } - var source = d.data.sourcetag || d.data.name; - if (d.data.logo) { - source = ''; - } + if (d.data.terms_url) { + d3.select(this) + .append('a') + .attr('href', d.data.terms_url) + .attr('target', '_blank') + .html(source); + } else { + d3.select(this) + .text(source); + } + }); - if (d.data.terms_url) { - provided_by.append('a') - .attr('href', d.data.terms_url) - .attr('target', '_blank') - .html(source); - } else { - provided_by.text(source); - } + attribution.exit() + .remove(); - var copyright = d.copyrightNotices(context.map().zoom(), context.map().extent()); - if (copyright) { - provided_by.append('span') - .text(copyright); - } + var copyright = attribution.selectAll('.copyright-notice') + .data(function(d) { + var notice = d.copyrightNotices(context.map().zoom(), context.map().extent()); + return notice ? [notice] : []; + }); + + copyright.enter() + .append('span') + .attr('class', 'copyright-notice'); + + copyright.text(String); + + copyright.exit() + .remove(); } return function(select) {