doxa-maps/internal/check-map-attribution.mjs
Doxa Maps 54df0de2a8 The map credit names the basemap that was actually drawn: OpenFreeMap / OpenMapTiles under MapLibre
addMapAttribution always credited "Mapbox · © OpenStreetMap". Under MapLibre the tiles are OpenFreeMap's
(OpenMapTiles on OpenStreetMap), so cities-internet, key-cities and gospel-resources credited Mapbox,
which served nothing, and omitted the OpenMapTiles credit (rega, row 28 at ccc2b1bb). The basemap credit
is now read from the map INSTANCE (instanceof maplibregl.Map, as setProjectionOn does): OpenFreeMap +
© OpenMapTiles + © OpenStreetMap contributors under MapLibre, Mapbox + © OpenStreetMap under Mapbox.
attributionText(provider) gives the print/PDF text per engine; ATTRIBUTION_TEXT is unchanged for
existing importers. check:map-attribution (headless, gates:post): 7 cases.
2026-09-26 08:51:38 +00:00

32 lines
2.7 KiB
JavaScript

#!/usr/bin/env node
/**
* check-map-attribution — the credit line names the basemap of the engine that actually drew the map.
*
* WHY (licence credit, rega's row 28 at ccc2b1bb): addMapAttribution always credited "Mapbox ·
* © OpenStreetMap". Under MapLibre the tiles are OpenFreeMap's (OpenMapTiles on OpenStreetMap), so
* gospel-resources, key-cities and cities-internet credited Mapbox, which served nothing, and omitted
* the OpenMapTiles credit. Headless: the real module against stand-in map classes and a minimal DOM.
* EXIT 0 pass · 1 fail
*/
const made = []
globalThis.window = globalThis
globalThis.document = { createElement: () => { const el = { style: {}, className: '', innerHTML: '' }; made.push(el); return el } }
class MapboxMap { addControl(c) { this.ctrl = c.onAdd() } }
class MaplibreMap { addControl(c) { this.ctrl = c.onAdd() } }
window.mapboxgl = { Map: MapboxMap }
window.maplibregl = { Map: MaplibreMap }
const { addMapAttribution, attributionText, ATTRIBUTION_TEXT } = await import('../library/composables/useMapAttribution.js')
let bad = 0
const check = (name, ok, got) => { if (!ok) bad++; console.log(` ${ok ? 'ok ' : 'FAIL'} ${name}${ok ? '' : ' — ' + got}`) }
const ml = new MaplibreMap(); addMapAttribution(ml, { boundaries: true })
check('MapLibre map credits OpenFreeMap, OpenMapTiles and OSM contributors', /OpenFreeMap/.test(ml.ctrl.innerHTML) && /OpenMapTiles/.test(ml.ctrl.innerHTML) && /OpenStreetMap contributors/.test(ml.ctrl.innerHTML), ml.ctrl.innerHTML)
check('MapLibre map does NOT credit Mapbox', !/Mapbox/.test(ml.ctrl.innerHTML), ml.ctrl.innerHTML)
const mb = new MapboxMap(); addMapAttribution(mb, { boundaries: true })
check('Mapbox map credits Mapbox and OpenStreetMap', /Mapbox/.test(mb.ctrl.innerHTML) && /OpenStreetMap/.test(mb.ctrl.innerHTML), mb.ctrl.innerHTML)
check('both credit geoBoundaries', /geoBoundaries/.test(ml.ctrl.innerHTML) && /geoBoundaries/.test(mb.ctrl.innerHTML), '')
const nb = new MaplibreMap(); addMapAttribution(nb, { boundaries: true, basemap: false })
check('basemap:false leaves only the boundaries credit', !/OpenFreeMap|Mapbox/.test(nb.ctrl.innerHTML), nb.ctrl.innerHTML)
check('print text for maplibre names OpenMapTiles, not Mapbox', /OpenMapTiles/.test(attributionText('maplibre')) && !/Mapbox/.test(attributionText('maplibre')), attributionText('maplibre'))
check('ATTRIBUTION_TEXT (existing importers) is unchanged', ATTRIBUTION_TEXT === 'Boundaries: geoBoundaries (geoboundaries.org) · © Mapbox © OpenStreetMap', ATTRIBUTION_TEXT)
if (bad) { console.log(`MAP-ATTRIBUTION: FAIL — ${bad} case(s).`); process.exit(1) }
console.log('MAP-ATTRIBUTION: PASS — the credit names the basemap of the engine that drew the map.')