wip: rename presets to datasets

This commit is contained in:
Yohan Boniface 2024-06-11 11:01:42 +02:00
parent 2c9623aff6
commit a70307ea29
4 changed files with 15 additions and 11 deletions

View file

@ -260,6 +260,7 @@ UMAP_DEFAULT_EDIT_STATUS = None
UMAP_DEFAULT_FEATURES_HAVE_OWNERS = False UMAP_DEFAULT_FEATURES_HAVE_OWNERS = False
UMAP_HOME_FEED = "latest" UMAP_HOME_FEED = "latest"
UMAP_EXPERIMENTAL_IMPORTERS = { UMAP_EXPERIMENTAL_IMPORTERS = {
# "overpass": {"url": "https://overpass-api.de/api/interpreter"},
# "geodatamine": {}, # "geodatamine": {},
# "communesfr": {}, # "communesfr": {},
# "presets": { # "presets": {

View file

@ -10,9 +10,10 @@ class Autocomplete extends SingleMixin(BaseAjax) {
} }
} }
export class Importer { export class Importer {
constructor() { constructor(map, options) {
this.name = 'Communes' this.name = options.name || 'Communes'
} }
async open(importer) { async open(importer) {
@ -24,6 +25,7 @@ export class Importer {
textContent: "Importer les contours d'une commune française.", textContent: "Importer les contours d'une commune française.",
}) })
const options = { const options = {
placeholder: 'Commune…',
url: 'https://geo.api.gouv.fr/communes?nom={q}&limit=5', url: 'https://geo.api.gouv.fr/communes?nom={q}&limit=5',
on_select: (choice) => { on_select: (choice) => {
importer.url = `https://geo.api.gouv.fr/communes?code=${choice.item.value}&format=geojson&geometry=contour` importer.url = `https://geo.api.gouv.fr/communes?code=${choice.item.value}&format=geojson&geometry=contour`

View file

@ -3,24 +3,25 @@ import { translate } from '../i18n.js'
export class Importer { export class Importer {
constructor(map, options) { constructor(map, options) {
this.name = 'Presets' this.name = options.name || 'Datasets'
this.choices = options?.choices this.choices = options?.choices
} }
async open(importer) { async open(importer) {
const container = DomUtil.create('div', 'formbox') const container = DomUtil.create('div', 'formbox')
DomUtil.element({tagName: 'h3', textContent: this.name, parent: container})
const select = DomUtil.create('select', '', container) const select = DomUtil.create('select', '', container)
const noPreset = DomUtil.element({ const noPreset = DomUtil.element({
tagName: 'option', tagName: 'option',
parent: select, parent: select,
value: '', value: '',
textContent: translate('Choose a preset'), textContent: translate('Choose a dataset'),
}) })
for (const preset of this.choices) { for (const dataset of this.choices) {
const option = DomUtil.create('option', '', select) const option = DomUtil.create('option', '', select)
option.value = preset.url option.value = dataset.url
option.textContent = preset.label option.textContent = dataset.label
option.dataset.format = preset.format || 'geojson' option.dataset.format = dataset.format || 'geojson'
} }
const confirm = () => { const confirm = () => {
if (select.value) { if (select.value) {
@ -29,11 +30,11 @@ export class Importer {
} }
importer.dialog.close() importer.dialog.close()
} }
L.DomUtil.createButton('', container, 'OK', confirm) L.DomUtil.createButton('', container, translate('Choose this dataset'), confirm)
importer.dialog.open({ importer.dialog.open({
content: container, content: container,
className: 'presets dark', className: 'datasets dark',
}) })
} }
} }

View file

@ -139,7 +139,7 @@ L.DomUtil.createButtonIcon = (parent, className, title, size = 16) => {
L.DomUtil.createTitle = (parent, text, className, tag = 'h3') => { L.DomUtil.createTitle = (parent, text, className, tag = 'h3') => {
const title = L.DomUtil.create(tag, '', parent) const title = L.DomUtil.create(tag, '', parent)
L.DomUtil.createIcon(title, className) if (className) L.DomUtil.createIcon(title, className)
L.DomUtil.add('span', '', title, text) L.DomUtil.add('span', '', title, text)
return title return title
} }