mirror of
https://github.com/umap-project/umap.git
synced 2025-04-28 19:42:36 +02:00
wip: control plugins from settings
This commit is contained in:
parent
a7a214d7fe
commit
93a189497b
5 changed files with 39 additions and 14 deletions
|
@ -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
|
||||
|
|
|
@ -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 = `
|
||||
<h3><i class="icon icon-16 icon-upload"></i><span>${translate('Import data')}</span></h3>
|
||||
|
@ -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({
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in a new issue