Skip to content

Commit 810bf5f

Browse files
committed
Fix insets ignoring custom nuts2jsonBaseURL; add worldTopojsonURL override
buildInset()'s main-map attribute copy list never included nuts2jsonBaseURL_, so any override set on the top-level map was silently dropped for every inset (default/'image'/'eu'/'euEfta' presets and custom insets alike) - they kept hitting the real Nuts2json GitHub/ec.europa.eu host regardless. Verified with a headless-browser network trace before and after. Separately, geo('WORLD') maps fetch a bundled eurostat-map topojson asset (not Nuts2json data), so that URL was hardcoded and had no override at all. Added a dedicated worldTopojsonURL_ config/setter (propagated to insets the same way nuts2jsonBaseURL_ already was) instead of conflating it with nuts2jsonBaseURL's semantics.
1 parent ce7a0d3 commit 810bf5f

12 files changed

Lines changed: 74 additions & 24 deletions

‎build/eurostatmap.js‎

Lines changed: 19 additions & 16 deletions
Large diffs are not rendered by default.

‎build/eurostatmap.min.js‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎build/eurostatmap.min.js.map‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎build/types/core/InsetConfig.d.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ export interface InsetConfig {
3737
zoomButtons?: boolean
3838
/** Custom base URL for this inset's nuts2json boundary data. */
3939
nuts2jsonBaseURL?: string
40+
/** Custom URL for this inset's world boundaries topojson (only relevant if the inset's `geo` is 'WORLD'). */
41+
worldTopojsonURL?: string
4042
/** Custom D3 projection function for this inset. */
4143
projectionFunction?: Function | boolean
4244

‎build/types/core/MapConfig.d.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,16 @@ export interface MapConfig {
4646
* ec.europa.eu cache when running on an ec.europa.eu host)
4747
*/
4848
nuts2jsonBaseURL?: string
49+
50+
/**
51+
* URL of the world boundaries topojson file used by `geo: 'WORLD'` maps. Not part of
52+
* Nuts2json (a separate, bundled eurostat-map asset), so it is independent of
53+
* `nuts2jsonBaseURL`. Applies to the top-level map and all of its insets.
54+
* @default 'https://raw.githubusercontent.com/eurostat/eurostat-map/master/src/assets/topojson/WORLD_4326.json'
55+
* (or the ec.europa.eu asset host when running on an ec.europa.eu host)
56+
*/
57+
worldTopojsonURL?: string
58+
4959
/** Geographic center as [longitude, latitude]. */
5060
geoCenter?: [number, number]
5161

‎build/types/core/MapInstance.d.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,16 @@ export interface MapInstance {
8787
nuts2jsonBaseURL(): string
8888
nuts2jsonBaseURL(url: string): this
8989

90+
/**
91+
* URL of the world boundaries topojson file used by `geo('WORLD')` maps. Not part of
92+
* Nuts2json (a separate, bundled eurostat-map asset), so it is independent of
93+
* `nuts2jsonBaseURL`. Setting this on the top-level map also propagates it to all insets.
94+
* @default 'https://raw.githubusercontent.com/eurostat/eurostat-map/master/src/assets/topojson/WORLD_4326.json'
95+
* (or the ec.europa.eu asset host when running on an ec.europa.eu host)
96+
*/
97+
worldTopojsonURL(): string
98+
worldTopojsonURL(url: string): this
99+
90100
/**
91101
* Initial map viewport. x/y in projected coordinates, z is pixel size
92102
* (map units per screen pixel — smaller = more zoomed in).

‎src/core/geo/geometries.js‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,7 @@ export const Geometries = function (map, withCenterPoints) {
198198
})
199199
}
200200
} else if (map.geo_ === 'WORLD') {
201-
const worldMapTopojsonURL = window.location.hostname.includes('ec.europa.eu')
202-
? 'https://ec.europa.eu/assets/estat/E/E4/gisco/IMAGE/WORLD_4326.json'
203-
: 'https://raw.githubusercontent.com/eurostat/eurostat-map/master/src/assets/topojson/WORLD_4326.json'
204-
205-
promises.push(fetchWithCache(worldMapTopojsonURL))
201+
promises.push(fetchWithCache(map.worldTopojsonURL_))
206202
} else {
207203
const mainUrl = buildUrl(map.nuts2jsonBaseURL_, map.nutsYear_, map.geo_, map.proj_, map.scale_, map.nutsLevel_)
208204
promises.push(fetchWithCache(mainUrl)) // index 0: polygon topology for current level

‎src/core/insets.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,8 @@ const buildInset = function (config, out, withCenterPoints, mapType) {
196196
'projectionFunction_',
197197
'filterGeometriesFunction_',
198198
'processCentroids_',
199+
'nuts2jsonBaseURL_',
200+
'worldTopojsonURL_',
199201
].forEach(function (att) {
200202
mt[att] = out[att]
201203
})

‎src/core/map-instance.js‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,11 @@ export const createMapInstance = function (config, withCenterPoints, mapType) {
213213
out.nuts2jsonBaseURL_ = window.location.hostname.includes('ec.europa.eu')
214214
? 'https://ec.europa.eu/eurostat/cache/GISCO/pub/nuts2json/v2/'
215215
: 'https://raw.githubusercontent.com/eurostat/Nuts2json/master/pub/v2'
216+
//URL of the world boundaries topojson used by geo('WORLD') maps. Not part of Nuts2json (a
217+
//separate, bundled eurostat-map asset), so it isn't derived from nuts2jsonBaseURL_.
218+
out.worldTopojsonURL_ = window.location.hostname.includes('ec.europa.eu')
219+
? 'https://ec.europa.eu/assets/estat/E/E4/gisco/IMAGE/WORLD_4326.json'
220+
: 'https://raw.githubusercontent.com/eurostat/eurostat-map/master/src/assets/topojson/WORLD_4326.json'
216221

217222
//style for no data regions
218223
out.noDataFillStyle_ = '#ADADAD'
@@ -261,7 +266,7 @@ export const createMapInstance = function (config, withCenterPoints, mapType) {
261266
}
262267

263268
//special ones which affect also the insets
264-
;['tooltip_', 'nuts2jsonBaseURL_', 'processCentroids_', 'coastalMarginSettings_'].forEach(function (att) {
269+
;['tooltip_', 'nuts2jsonBaseURL_', 'worldTopojsonURL_', 'processCentroids_', 'coastalMarginSettings_'].forEach(function (att) {
265270
out[att.substring(0, att.length - 1)] = function (v) {
266271
if (!arguments.length) return out[att]
267272

‎src/types/core/InsetConfig.d.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ export interface InsetConfig {
3737
zoomButtons?: boolean
3838
/** Custom base URL for this inset's nuts2json boundary data. */
3939
nuts2jsonBaseURL?: string
40+
/** Custom URL for this inset's world boundaries topojson (only relevant if the inset's `geo` is 'WORLD'). */
41+
worldTopojsonURL?: string
4042
/** Custom D3 projection function for this inset. */
4143
projectionFunction?: Function | boolean
4244

0 commit comments

Comments
 (0)