Display Bing copyrights

This commit is contained in:
John Firebaugh
2013-03-21 12:23:57 -07:00
parent 235cb52d26
commit e01d2e611f
6 changed files with 46 additions and 22 deletions

View File

@@ -102,7 +102,13 @@ window.iD = function () {
context.zoomOut = map.zoomOut;
/* Background */
var backgroundSources = iD.data.imagery.map(iD.BackgroundSource.template);
var backgroundSources = iD.data.imagery.map(function(source) {
if (source.sourcetag === 'Bing') {
return iD.BackgroundSource.Bing(source, context.background().dispatch);
} else {
return iD.BackgroundSource.template(source);
}
});
backgroundSources.push(iD.BackgroundSource.Custom);
context.backgroundSources = function() {

View File

@@ -168,14 +168,17 @@ iD.Background = function() {
}
}
background.dispatch = d3.dispatch('change');
background.source = function(_) {
if (!arguments.length) return source;
source = _;
cache = {};
tile.scaleExtent((source.data && source.data.scaleExtent) || [1, 20]);
setHash(source);
background.dispatch.change();
return background;
};
return background;
return d3.rebind(background, background.dispatch, 'on');
};

View File

@@ -29,20 +29,22 @@ iD.BackgroundSource.template = function(data) {
}
generator.data = data;
generator.copyrightNotices = function() {};
return generator;
};
iD.BackgroundSource.Bing = function(data) {
iD.BackgroundSource.Bing = function(data, dispatch) {
// http://msdn.microsoft.com/en-us/library/ff701716.aspx
// http://msdn.microsoft.com/en-us/library/ff701701.aspx
var bing = iD.BackgroundSource.template(data),
key = 'Arzdiw4nlOJzRwOz__qailc8NiR31Tt51dN2D7cm57NrnceZnCpgOkmJhNpGoppU', // Same as P2 and JOSM
url = 'http://dev.virtualearth.net/REST/v1/Imagery/Metadata/Aerial?include=ImageryProviders&key=' + key + '&jsonp={callback}';
url = 'http://dev.virtualearth.net/REST/v1/Imagery/Metadata/Aerial?include=ImageryProviders&key=' + key + '&jsonp={callback}',
providers = [];
d3.jsonp(url, function(json) {
bing.providers = json.resourceSets[0].resources[0].imageryProviders.map(function(provider) {
providers = json.resourceSets[0].resources[0].imageryProviders.map(function(provider) {
return {
attribution: provider.attribution,
areas: provider.coverageAreas.map(function(area) {
@@ -53,10 +55,12 @@ iD.BackgroundSource.Bing = function(data) {
})
};
});
dispatch.change();
});
bing.copyrightNotices = function(zoom, extent) {
return bing.providers.filter(function(provider) {
zoom = Math.min(zoom, 21);
return providers.filter(function(provider) {
return _.any(provider.areas, function(area) {
return extent.intersects(area.extent) &&
area.zoom[0] <= zoom &&

View File

@@ -100,7 +100,6 @@ iD.ui = function(context) {
linkList.append('li')
.attr('class', 'attribution')
.attr('tabindex', -1)
.data([context.background().source()])
.call(iD.ui.Attribution(context));
linkList.append('li')

View File

@@ -1,6 +1,8 @@
iD.ui.Attribution = function(context) {
return function attribution(selection) {
var d = selection.data()[0];
var selection;
function update() {
var d = context.background().source();
var provided_by = selection
.html('')
@@ -10,13 +12,11 @@ iD.ui.Attribution = function(context) {
if (!d) return;
var source = d.data.sourcetag || d.data.name;
if (d.data.logo) {
source = '<img src="img/' + d.data.logo + '">'
}
var desc = t('imagery.provided_by', {source: source});
if (d.data.terms_url) {
provided_by.append('a')
.attr('href', d.data.terms_url)
@@ -25,5 +25,23 @@ iD.ui.Attribution = function(context) {
} else {
provided_by.text(desc);
}
var copyright = d.copyrightNotices(context.map().zoom(), context.map().extent());
if (copyright) {
provided_by.append('span')
.text(copyright);
}
}
return function(select) {
selection = select;
context.background()
.on('change.attribution', update);
context.map()
.on('move.attribution', _.throttle(update, 400));
update();
};
};

View File

@@ -1,6 +1,5 @@
iD.ui.Background = function(context) {
var event = d3.dispatch('cancel', 'save'),
key = 'b',
var key = 'b',
opacities = [1, 0.5, 0],
directions = [
['left', [1, 0]],
@@ -57,16 +56,11 @@ iD.ui.Background = function(context) {
}
}
function selectLayer(d) {
function selectLayer() {
content.selectAll('a.layer')
.classed('selected', function(d) {
return d.data.name === context.background().source().data.name;
});
context.container()
.select('.attribution')
.data([d])
.call(iD.ui.Attribution(context));
}
function clickSetSource(d) {
@@ -85,7 +79,7 @@ iD.ui.Background = function(context) {
.imagery_used(d.data.sourcetag || d.data.name);
}
context.redraw();
selectLayer(d);
selectLayer();
}
function clickGpx(d) {
@@ -139,7 +133,7 @@ iD.ui.Background = function(context) {
layerLinks.exit()
.remove();
selectLayer(context.background().source());
selectLayer();
}
function clickNudge(d) {
@@ -289,5 +283,5 @@ iD.ui.Background = function(context) {
.call(keybinding);
}
return d3.rebind(background, event, 'on');
return background;
};