From 5977424a5fc82cdfa0adbf105239bf02e59426c8 Mon Sep 17 00:00:00 2001 From: dbauszus-glx Date: Fri, 26 Jan 2024 18:33:44 +0000 Subject: [PATCH 1/7] Check whether a plugin string endsWith some value from an array --- lib/utils/loadPlugins.mjs | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/lib/utils/loadPlugins.mjs b/lib/utils/loadPlugins.mjs index 67b6134c28..c855ae8b82 100644 --- a/lib/utils/loadPlugins.mjs +++ b/lib/utils/loadPlugins.mjs @@ -1,26 +1,28 @@ -export default plugins => { +export default (plugins, endsWith = ['.js','.mjs']) => { if (!Array.isArray(plugins)) return; - - return new Promise(resolveAll=>{ - const promises = plugins.map( - plugin => - new Promise((resolve, reject) => - import(plugin) - .then(mod=> { - resolve(mod) - }) - .catch(()=> { - reject() - }))) + return new Promise(resolveAll => { + + const promises = plugins + .filter(plugin => endsWith.some(_this => plugin.endsWith(_this))) + .map( + plugin => + new Promise((resolve, reject) => + import(plugin) + .then(mod => { + resolve(mod) + }) + .catch(() => { + reject() + }))) Promise .allSettled(promises) - .then(()=>{ + .then(() => { resolveAll() }) - .catch(err=>{ + .catch(err => { console.error(err) resolveAll() }) From 879988b9ded9c2dcc6072ff7919fb79fe7d7c396 Mon Sep 17 00:00:00 2001 From: dbauszus-glx Date: Mon, 29 Jan 2024 10:22:14 +0000 Subject: [PATCH 2/7] Replace custom clone util with structuredClone --- lib/layer/Style.mjs | 4 ++-- lib/layer/themes/graduated.mjs | 2 +- lib/utils/_utils.mjs | 4 ---- lib/utils/clone.mjs | 25 ------------------------- 4 files changed, 3 insertions(+), 32 deletions(-) delete mode 100644 lib/utils/clone.mjs diff --git a/lib/layer/Style.mjs b/lib/layer/Style.mjs index 0be9781eac..d7420f7d75 100644 --- a/lib/layer/Style.mjs +++ b/lib/layer/Style.mjs @@ -52,7 +52,7 @@ export default layer => { } // Assign default style as feature.style. - feature.style = { ...mapp.utils.clone(layer.style.default), ...layer.style.theme?.style } + feature.style = { ...structuredClone(layer.style.default), ...layer.style.theme?.style } // Check whether feature is in lookup. if (Array.isArray(layer.featureLookup)) { @@ -75,7 +75,7 @@ export default layer => { if (feature.geometryType === 'Point') { // The style must be cloned as icon if not otherwise defined to prevent circular reference - feature.style.icon ??= mapp.utils.clone(feature.style) + feature.style.icon ??= structuredClone(feature.style) // Assign cluster style. if (feature.properties.count > 1 && layer.style.cluster) { diff --git a/lib/layer/themes/graduated.mjs b/lib/layer/themes/graduated.mjs index 1126fc93ad..aad39dd4e2 100644 --- a/lib/layer/themes/graduated.mjs +++ b/lib/layer/themes/graduated.mjs @@ -19,7 +19,7 @@ export default function(theme, feature) { if (catValue <= parseFloat(theme.cat_arr[i].value)) break; // Set cat_style to current cat style after value check. - var catStyle = mapp.utils.clone(theme.cat_arr[i].style || theme.cat_arr[i]) + var catStyle = structuredClone(theme.cat_arr[i].style || theme.cat_arr[i]) delete catStyle.label } diff --git a/lib/utils/_utils.mjs b/lib/utils/_utils.mjs index 7857c273db..8bcdf902d1 100644 --- a/lib/utils/_utils.mjs +++ b/lib/utils/_utils.mjs @@ -5,9 +5,6 @@ import * as stats from 'simple-statistics' const areSetsEqual = (a, b) => a.size === b.size && [...a].every(value => b.has(value)) -// local import -import clone from './clone.mjs' - import csvDownload from './csvDownload.mjs' const compose = (...fns) => { @@ -69,7 +66,6 @@ export default { svg, convert, areSetsEqual, - clone, compose, copyToClipboard, csvDownload, diff --git a/lib/utils/clone.mjs b/lib/utils/clone.mjs deleted file mode 100644 index 1d270b7ce8..0000000000 --- a/lib/utils/clone.mjs +++ /dev/null @@ -1,25 +0,0 @@ -export default function clone(target, map = new WeakMap()) { - - // Return the value if target is not an object or null - if (target === null - || typeof target !== 'object' - || typeof target === 'function' - || target instanceof HTMLElement) { - return target - } - - // Check whether target is an array. - let cloneTarget = Array.isArray(target) ? [] : {}; - - // Use WeakMap to prevent circular references. - if (map.get(target)) { - return map.get(target); - } - map.set(target, cloneTarget); - - for (const key in target) { - cloneTarget[key] = clone(target[key], map); - } - - return cloneTarget; -}; \ No newline at end of file From 7b91407b2f7dd422733bc1b338ce9e8c68ff7369 Mon Sep 17 00:00:00 2001 From: dbauszus-glx Date: Mon, 29 Jan 2024 12:48:49 +0000 Subject: [PATCH 3/7] Add map-attribution to mapview --- lib/mapview/_mapview.mjs | 34 ++++------------------------------ lib/mapview/attribution.mjs | 34 ++++++++++++++++++++++++++++++++++ public/css/_mapp.css | 12 ++++++++++++ public/css/mapp.css | 11 +++++++++++ public/views/_default.html | 26 ++++++-------------------- public/views/_default.js | 6 ++++-- 6 files changed, 71 insertions(+), 52 deletions(-) create mode 100644 lib/mapview/attribution.mjs diff --git a/lib/mapview/_mapview.mjs b/lib/mapview/_mapview.mjs index 85b2ecd2b6..d097f69093 100644 --- a/lib/mapview/_mapview.mjs +++ b/lib/mapview/_mapview.mjs @@ -1,3 +1,5 @@ +import attribution from './attribution.mjs' + import addLayer from './addLayer.mjs' import fitView from './fitView.mjs' @@ -185,36 +187,8 @@ export default (mapview) => { units: mapview.locale.ScaleLine === 'imperial' ? 'imperial' : 'metric', })) - // Attribution - if (mapview.attribution) { - - if (typeof mapview.attribution !== 'object') { - mapview.attribution = {} - } - - mapview.attribution.target = mapview.attribution.target - || mapview.Map.getTargetElement() - .appendChild(mapp.utils.html.node` -