diff --git a/umap/settings/base.py b/umap/settings/base.py
index df56ccd7..0fad343c 100644
--- a/umap/settings/base.py
+++ b/umap/settings/base.py
@@ -259,6 +259,16 @@ UMAP_DEFAULT_SHARE_STATUS = None
UMAP_DEFAULT_EDIT_STATUS = None
UMAP_DEFAULT_FEATURES_HAVE_OWNERS = False
UMAP_HOME_FEED = "latest"
+UMAP_EXPERIMENTAL_PLUGINS = {
+ # "geodatamine": {},
+ # "communesfr": {},
+ # "presets": {
+ # "choices": [
+ # {"label": "Régions", "url": "https://france-geojson.gregoiredavid.fr/repo/regions.geojson", "format": "geojson"},
+ # {"label": "Départements", "url": "https://france-geojson.gregoiredavid.fr/repo/departements.geojson", "format": "geojson"},
+ # ]
+ # }
+}
UMAP_READONLY = env("UMAP_READONLY", default=False)
UMAP_GZIP = True
diff --git a/umap/static/umap/js/modules/importer.js b/umap/static/umap/js/modules/importer.js
index e8bed468..cee0cf9c 100644
--- a/umap/static/umap/js/modules/importer.js
+++ b/umap/static/umap/js/modules/importer.js
@@ -2,9 +2,8 @@ import { DomUtil, DomEvent } from '../../vendors/leaflet/leaflet-src.esm.js'
import { translate } from './i18n.js'
import { uMapAlert as Alert } from '../components/alerts/alert.js'
import Dialog from './ui/dialog.js'
-import { Importer as GeoDataMine } from './importers/geodatamine.js'
-import { Importer as Communes } from './importers/communes.js'
-import { Importer as Presets } from './importers/presets.js'
+
+const AVAILABLE_PLUGINS = ['geodatamine', 'communesfr', 'presets']
const TEMPLATE = `
${translate('Import data')}
@@ -41,10 +40,21 @@ export default class Importer {
constructor(map) {
this.map = map
this.TYPES = ['geojson', 'csv', 'gpx', 'kml', 'osm', 'georss', 'umap']
- this.PLUGINS = [new GeoDataMine(map), new Communes(map), new Presets(map)]
+ this.PLUGINS = []
+ this.loadPlugins()
this.dialog = new Dialog(this.map._controlContainer)
}
+ loadPlugins() {
+ for (const key of AVAILABLE_PLUGINS) {
+ if (key in this.map.options.plugins) {
+ import(`./importers/${key}.js`).then((mod) => {
+ this.PLUGINS.push(new mod.Importer(this.map, this.map.options.plugins[key]))
+ })
+ }
+ }
+ }
+
qs(query) {
return this.container.querySelector(query)
}
@@ -85,13 +95,17 @@ export default class Importer {
build() {
this.container = DomUtil.create('div', 'umap-upload')
this.container.innerHTML = TEMPLATE
- for (const plugin of this.PLUGINS) {
- L.DomUtil.createButton(
- 'flat',
- this.container.querySelector('#plugins'),
- plugin.name,
- () => plugin.open(this)
- )
+ if (this.PLUGINS.length) {
+ for (const plugin of this.PLUGINS) {
+ L.DomUtil.createButton(
+ 'flat',
+ this.container.querySelector('#plugins'),
+ plugin.name,
+ () => plugin.open(this)
+ )
+ }
+ } else {
+ this.qs('.plugins').style.display = 'none'
}
for (const type of this.TYPES) {
DomUtil.element({
diff --git a/umap/static/umap/js/modules/importers/communes.js b/umap/static/umap/js/modules/importers/communesfr.js
similarity index 100%
rename from umap/static/umap/js/modules/importers/communes.js
rename to umap/static/umap/js/modules/importers/communesfr.js
diff --git a/umap/static/umap/js/modules/importers/presets.js b/umap/static/umap/js/modules/importers/presets.js
index 6a43e9ec..78325943 100644
--- a/umap/static/umap/js/modules/importers/presets.js
+++ b/umap/static/umap/js/modules/importers/presets.js
@@ -2,9 +2,9 @@ import { DomUtil } from '../../../vendors/leaflet/leaflet-src.esm.js'
import { translate } from '../i18n.js'
export class Importer {
- constructor(map) {
+ constructor(map, options) {
this.name = 'Presets'
- this.presets = map.options.importPresets
+ this.choices = options?.choices
}
async open(importer) {
@@ -16,7 +16,7 @@ export class Importer {
value: '',
textContent: translate('Choose a preset'),
})
- for (const preset of this.presets) {
+ for (const preset of this.choices) {
const option = DomUtil.create('option', '', select)
option.value = preset.url
option.textContent = preset.label
diff --git a/umap/views.py b/umap/views.py
index e53b382c..8258ac1c 100644
--- a/umap/views.py
+++ b/umap/views.py
@@ -505,6 +505,7 @@ class MapDetailMixin:
"featuresHaveOwner": settings.UMAP_DEFAULT_FEATURES_HAVE_OWNERS,
"websocketEnabled": settings.WEBSOCKET_ENABLED,
"websocketURI": settings.WEBSOCKET_FRONT_URI,
+ "plugins": settings.UMAP_EXPERIMENTAL_PLUGINS,
}
created = bool(getattr(self, "object", None))
if (created and self.object.owner) or (not created and not user.is_anonymous):