Skip to content

Commit ff7cf01

Browse files
authored
Merge pull request #5696 from plotly/fix5675-open-street-map-credit
Revise attributions of Carto, Stamen and Open Street Map styles
2 parents d36b491 + 97bac68 commit ff7cf01

File tree

6 files changed

+95
-7
lines changed

6 files changed

+95
-7
lines changed

src/plots/mapbox/constants.js

+28-6
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,36 @@
22

33
var requiredVersion = '1.10.1';
44

5+
var OSM = '© <a target="_blank" href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors';
6+
var carto = [
7+
'© <a target="_blank" href="https://carto.com/">Carto</a>',
8+
OSM
9+
].join(' ');
10+
11+
var stamenTerrainOrToner = [
12+
'Map tiles by <a target="_blank" href="https://stamen.com">Stamen Design</a>',
13+
'under <a target="_blank" href="https://creativecommons.org/licenses/by/3.0">CC BY 3.0</a>',
14+
'|',
15+
'Data by <a target="_blank" href="https://openstreetmap.org">OpenStreetMap</a> contributors',
16+
'under <a target="_blank" href="https://www.openstreetmap.org/copyright">ODbL</a>'
17+
].join(' ');
18+
19+
var stamenWaterColor = [
20+
'Map tiles by <a target="_blank" href="https://stamen.com">Stamen Design</a>',
21+
'under <a target="_blank" href="https://creativecommons.org/licenses/by/3.0">CC BY 3.0</a>',
22+
'|',
23+
'Data by <a target="_blank" href="https://openstreetmap.org">OpenStreetMap</a> contributors',
24+
'under <a target="_blank" href="https://creativecommons.org/licenses/by-sa/3.0">CC BY SA</a>'
25+
].join(' ');
26+
527
var stylesNonMapbox = {
628
'open-street-map': {
729
id: 'osm',
830
version: 8,
931
sources: {
1032
'plotly-osm-tiles': {
1133
type: 'raster',
12-
attribution: '<a href="http://www.openstreetmap.org/about/" target="_blank">© OpenStreetMap</a>',
34+
attribution: OSM,
1335
tiles: [
1436
'https://a.tile.openstreetmap.org/{z}/{x}/{y}.png',
1537
'https://b.tile.openstreetmap.org/{z}/{x}/{y}.png'
@@ -43,7 +65,7 @@ var stylesNonMapbox = {
4365
sources: {
4466
'plotly-carto-positron': {
4567
type: 'raster',
46-
attribution: '<a href="https://carto.com/" target="_blank">© CARTO</a>',
68+
attribution: carto,
4769
tiles: ['https://cartodb-basemaps-c.global.ssl.fastly.net/light_all/{z}/{x}/{y}.png'],
4870
tileSize: 256
4971
}
@@ -62,7 +84,7 @@ var stylesNonMapbox = {
6284
sources: {
6385
'plotly-carto-darkmatter': {
6486
type: 'raster',
65-
attribution: '<a href="https://carto.com/" target="_blank">© CARTO</a>',
87+
attribution: carto,
6688
tiles: ['https://cartodb-basemaps-c.global.ssl.fastly.net/dark_all/{z}/{x}/{y}.png'],
6789
tileSize: 256
6890
}
@@ -81,7 +103,7 @@ var stylesNonMapbox = {
81103
sources: {
82104
'plotly-stamen-terrain': {
83105
type: 'raster',
84-
attribution: 'Map tiles by <a href="http://stamen.com">Stamen Design</a>, under <a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a> | Data by <a href="http://openstreetmap.org">OpenStreetMap</a>, under <a href="http://www.openstreetmap.org/copyright">ODbL</a>.',
106+
attribution: stamenTerrainOrToner,
85107
tiles: ['https://stamen-tiles.a.ssl.fastly.net/terrain/{z}/{x}/{y}.png'],
86108
tileSize: 256
87109
}
@@ -100,7 +122,7 @@ var stylesNonMapbox = {
100122
sources: {
101123
'plotly-stamen-toner': {
102124
type: 'raster',
103-
attribution: 'Map tiles by <a href="http://stamen.com">Stamen Design</a>, under <a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a> | Data by <a href="http://openstreetmap.org">OpenStreetMap</a>, under <a href="http://www.openstreetmap.org/copyright">ODbL</a>.',
125+
attribution: stamenTerrainOrToner,
104126
tiles: ['https://stamen-tiles.a.ssl.fastly.net/toner/{z}/{x}/{y}.png'],
105127
tileSize: 256
106128
}
@@ -119,7 +141,7 @@ var stylesNonMapbox = {
119141
sources: {
120142
'plotly-stamen-watercolor': {
121143
type: 'raster',
122-
attribution: 'Map tiles by <a href="http://stamen.com">Stamen Design</a>, under <a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a> | Data by <a href="http://openstreetmap.org">OpenStreetMap</a>, under <a href="http://creativecommons.org/licenses/by-sa/3.0">CC BY SA</a>.',
144+
attribution: stamenWaterColor,
123145
tiles: ['https://stamen-tiles.a.ssl.fastly.net/watercolor/{z}/{x}/{y}.png'],
124146
tileSize: 256
125147
}
4.07 KB
Loading
784 Bytes
Loading
1 KB
Loading
328 Bytes
Loading

test/jasmine/tests/mapbox_test.js

+67-1
Original file line numberDiff line numberDiff line change
@@ -1471,12 +1471,73 @@ describe('mapbox plots', function() {
14711471
}, LONG_TIMEOUT_INTERVAL);
14721472

14731473
describe('attributions', function() {
1474+
function assertLinks(s, exp) {
1475+
var elements = s[0][0].getElementsByTagName('a');
1476+
expect(elements.length).toEqual(exp.length);
1477+
for(var i = 0; i < elements.length; i++) {
1478+
var e = elements[i];
1479+
expect(e.href).toEqual(exp[i]);
1480+
expect(e.target).toEqual('_blank');
1481+
}
1482+
}
1483+
1484+
it('@gl should be displayed for style "Carto"', function(done) {
1485+
Plotly.newPlot(gd, [{type: 'scattermapbox'}], {mapbox: {style: 'carto-darkmatter'}})
1486+
.then(function() {
1487+
var s = d3SelectAll('.mapboxgl-ctrl-attrib');
1488+
expect(s.size()).toBe(1);
1489+
expect(s.text()).toEqual('© Carto © OpenStreetMap contributors');
1490+
assertLinks(s, [
1491+
'https://carto.com/',
1492+
'https://www.openstreetmap.org/copyright'
1493+
]);
1494+
})
1495+
.then(done, done.fail);
1496+
});
1497+
1498+
['stamen-terrain', 'stamen-toner'].forEach(function(style) {
1499+
it('@gl should be displayed for style "' + style + '"', function(done) {
1500+
Plotly.newPlot(gd, [{type: 'scattermapbox'}], {mapbox: {style: style}})
1501+
.then(function() {
1502+
var s = d3SelectAll('.mapboxgl-ctrl-attrib');
1503+
expect(s.size()).toBe(1);
1504+
expect(s.text()).toEqual('Map tiles by Stamen Design under CC BY 3.0 | Data by OpenStreetMap contributors under ODbL');
1505+
assertLinks(s, [
1506+
'https://stamen.com/',
1507+
'https://creativecommons.org/licenses/by/3.0',
1508+
'https://openstreetmap.org/',
1509+
'https://www.openstreetmap.org/copyright'
1510+
]);
1511+
})
1512+
.then(done, done.fail);
1513+
});
1514+
});
1515+
1516+
it('@gl should be displayed for style "stamen-watercolor"', function(done) {
1517+
Plotly.newPlot(gd, [{type: 'scattermapbox'}], {mapbox: {style: 'stamen-watercolor'}})
1518+
.then(function() {
1519+
var s = d3SelectAll('.mapboxgl-ctrl-attrib');
1520+
expect(s.size()).toBe(1);
1521+
expect(s.text()).toEqual('Map tiles by Stamen Design under CC BY 3.0 | Data by OpenStreetMap contributors under CC BY SA');
1522+
assertLinks(s, [
1523+
'https://stamen.com/',
1524+
'https://creativecommons.org/licenses/by/3.0',
1525+
'https://openstreetmap.org/',
1526+
'https://creativecommons.org/licenses/by-sa/3.0'
1527+
]);
1528+
})
1529+
.then(done, done.fail);
1530+
});
1531+
14741532
it('@gl should be displayed for style "open-street-map"', function(done) {
14751533
Plotly.newPlot(gd, [{type: 'scattermapbox'}], {mapbox: {style: 'open-street-map'}})
14761534
.then(function() {
14771535
var s = d3SelectAll('.mapboxgl-ctrl-attrib');
14781536
expect(s.size()).toBe(1);
1479-
expect(s.text()).toEqual('© OpenStreetMap');
1537+
expect(s.text()).toEqual('© OpenStreetMap contributors');
1538+
assertLinks(s, [
1539+
'https://www.openstreetmap.org/copyright'
1540+
]);
14801541
})
14811542
.then(done, done.fail);
14821543
});
@@ -1487,6 +1548,11 @@ describe('mapbox plots', function() {
14871548
var s = d3SelectAll('.mapboxgl-ctrl-attrib');
14881549
expect(s.size()).toBe(1);
14891550
expect(s.text()).toEqual('© Mapbox © OpenStreetMap Improve this map');
1551+
assertLinks(s, [
1552+
'https://www.mapbox.com/about/maps/',
1553+
'http://www.openstreetmap.org/about/',
1554+
'https://www.mapbox.com/map-feedback/' // Improve this map
1555+
]);
14901556
})
14911557
.then(done, done.fail);
14921558
});

0 commit comments

Comments
 (0)