Eliminate attribution flashing (fixes #1134)

This commit is contained in:
John Firebaugh
2013-03-27 14:24:59 -07:00
parent 8e4bab8022
commit d2f3d161e5

View File

@@ -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 = '<img class="source-image" src="img/' + d.data.logo + '">';
}
var source = d.data.sourcetag || d.data.name;
if (d.data.logo) {
source = '<img class="source-image" src="img/' + d.data.logo + '">';
}
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) {