Add data credits through the renderer's credits port

Data attribution no longer builds Cesium credits itself: each credit is
added through the renderer's credits port, in the attribution list as
before. The port's credit carries one link, so a credit whose markup
holds several links becomes one credit per link, shown together in
order, its wording kept. dataCredits.js leaves the Cesium allow-list.
This commit is contained in:
Sameh Khamis committed 2026-11-06 17:59:00 -08:00
1 parent b9daac73c6
commit 69e8cef846
3 files changed
+167 -25

No files matched your search

+102
View File
@@ -142,3 +142,105 @@ test('every Street Level imagery source is in the attribution lightbox', () => {
`${key} has no credit`,
);
});
test('a credit with several links becomes one credit per link, in order', async () => {
const {
creditsFromMarkup,
OSM_CREDIT,
OPENMAPTILES_CREDIT,
WOF_CREDIT,
BHOTE_KOSHI_CREDIT,
} = await import('./dataCredits.js');
const html = (key) => DATA_CREDITS.find((entry) => entry.key === key).html;
const read = (markup) =>
creditsFromMarkup(markup).map(({ text, href }) => [text, href]);
assert.deepEqual(read(OSM_CREDIT.html), [
[
'Map and place data © OpenStreetMap contributors',
'https://www.openstreetmap.org/copyright',
],
['(ODbL)', 'https://opendatacommons.org/licenses/odbl/1-0/'],
]);
assert.deepEqual(read(OPENMAPTILES_CREDIT.html), [
['Vector tiles: OpenFreeMap', 'https://openfreemap.org'],
['© OpenMapTiles', 'https://openmaptiles.org'],
]);
assert.deepEqual(read(html('nasa-gibs'))[1], [
'HLS product page',
'https://lpdaac.usgs.gov/products/hlss30v002/',
]);
assert.deepEqual(read(html('wfigs')), [
[
'Wildfire perimeters: National Interagency Fire Center (WFIGS)',
'https://data-nifc.opendata.arcgis.com/',
],
['Incident information: InciWeb', 'https://inciweb.wildfire.gov/'],
]);
assert.deepEqual(read(html('eccc-aqhi')), [
[
'Air quality (AQHI): Environment and Climate Change Canada — MSC GeoMet (eccc-msc.github.io/open-data)',
'https://eccc-msc.github.io/open-data/',
],
[
'ECCC Data Servers End-use Licence',
'https://eccc-msc.github.io/open-data/licence/readme_en/',
],
]);
assert.deepEqual(
read(BHOTE_KOSHI_CREDIT.html)[1][0].slice(0, 15),
'and GeoPera (CC',
);
assert.deepEqual(
read(WOF_CREDIT.html).map(([text]) => text),
[
"Neighborhood boundaries: Who's On First and contributors, simplified",
'(sources and licences)',
],
);
const link = (text) => `<a href="https://example.org">${text}</a>`;
assert.deepEqual(
read(`${link('A')} by Hoffleit &amp; Warren ${link('B')}`).map(
([text]) => text,
),
['A', 'by Hoffleit & Warren B'],
'a character reference is not a separator',
);
assert.deepEqual(read(html('usgs')), [
['Earthquakes: Data courtesy of the U.S. Geological Survey', undefined],
]);
for (const entry of DATA_CREDITS) {
const credits = creditsFromMarkup(entry.html);
const links = entry.html.match(/<a\b/g)?.length ?? 0;
assert.equal(credits.length, Math.max(links, 1), entry.key);
assert.ok(
credits.every((credit) => credit.inline === false),
`${entry.key} belongs in the attribution list`,
);
}
});
test('data credits go through the renderer to the attribution list', async () => {
const { registerDataCredits, registerDynamicCredit, TOMTOM_CREDIT } =
await import('./dataCredits.js');
const shown = [];
const viewer = bindFakeCesiumCredits({
creditDisplay: {
addStaticCredit: (c) => shown.push(c),
removeStaticCredit() {},
},
});
const credits = DATA_CREDITS.filter((entry) =>
['openstreetmap', 'usgs'].includes(entry.key),
);
registerDataCredits(viewer, credits);
assert.equal(shown.length, 3);
assert.ok(shown.every((credit) => !credit.showOnScreen));
const odbl = shown.find((credit) => credit.html.includes('opendatacommons'));
assert.match(odbl.html, /href="https:\/\/opendatacommons.org/);
assert.match(odbl.html, />\(ODbL\)</);
assert.equal(registerDynamicCredit(viewer, TOMTOM_CREDIT), true);
assert.equal(registerDynamicCredit(viewer, TOMTOM_CREDIT), true);
assert.equal(shown.length, 4, 'a dynamic credit is added once');
assert.match(shown[3].html, /Traffic flow data © TomTom/);
assert.equal(registerDynamicCredit({}, { key: 'none', html: 'x' }), false);
});