Skip to content

Commit

Permalink
Merge pull request #4957 from HSLdevcom/allzones-to-cdn
Browse files Browse the repository at this point in the history
Fetch assembed zones via CDN
  • Loading branch information
optionsome authored Feb 15, 2024
2 parents ccfc8c5 + 840f8b9 commit 0f4b3ff
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
17 changes: 11 additions & 6 deletions app/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ if (defaultConfig.themeMap) {

let allZones;
export function setAssembledZones(zoneLayer) {
allZones = zoneLayer;
allZones = { ...zoneLayer };
}

function addMetaData(config) {
Expand Down Expand Up @@ -81,6 +81,13 @@ function addMetaData(config) {
}
}

function mapGeoJsonPaths(url, config) {
const appPathPrefix = config.URL.ASSET_URL || '';
const mapUrl = u =>
u.startsWith('http') || u.startsWith('//') ? u : appPathPrefix + u;
return typeof url === 'string' ? mapUrl(url) : url.map(u => mapUrl(u));
}

export function getNamedConfiguration(configName) {
if (!configs[configName]) {
let additionalConfig;
Expand Down Expand Up @@ -126,13 +133,10 @@ export function getNamedConfiguration(configName) {

addMetaData(config); // add dynamic metadata content

const appPathPrefix = config.URL.ASSET_URL || '';
if (config.geoJson && Array.isArray(config.geoJson.layers)) {
if (config.geoJson?.layers) {
for (let i = 0; i < config.geoJson.layers.length; i++) {
const layer = config.geoJson.layers[i];
if (layer.url.indexOf('http') !== 0) {
layer.url = appPathPrefix + layer.url;
}
layer.url = mapGeoJsonPaths(layer.url, config);
}
}
configs[configName] = config;
Expand All @@ -143,6 +147,7 @@ export function getNamedConfiguration(configName) {
if (!conf.geoJson?.layers?.find(l => l.name === allZones.name)) {
const zoneLayer = {
...allZones,
url: mapGeoJsonPaths(allZones.url, conf),
isOffByDefault: conf.useAssembledGeoJsonZones === 'isOffByDefault',
};
if (!conf.geoJson) {
Expand Down
2 changes: 1 addition & 1 deletion app/store/GeoJsonStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class GeoJsonStore extends Store {
let id;
let urlArr;
if (Array.isArray(url)) {
[id] = url;
id = `${url[0]}-array`;
urlArr = url;
} else {
id = url;
Expand Down

0 comments on commit 0f4b3ff

Please sign in to comment.