diff --git a/umap/static/umap/css/importers.css b/umap/static/umap/css/importers.css index 50f7c1b8..5f6ac39d 100644 --- a/umap/static/umap/css/importers.css +++ b/umap/static/umap/css/importers.css @@ -43,6 +43,10 @@ .importers ul .communesfr:before { background-image: url(../img/importers/communesfr.svg); } +.importer.cadastrefr h3:before, +.importers ul .cadastrefr:before { + background-image: url(../img/importers/cadastrefr.svg); +} .importer.overpass h3:before, .importers ul .overpass:before { background-image: url(../img/importers/overpass.svg); diff --git a/umap/static/umap/img/importers/cadastrefr.svg b/umap/static/umap/img/importers/cadastrefr.svg new file mode 100644 index 00000000..c5027442 --- /dev/null +++ b/umap/static/umap/img/importers/cadastrefr.svg @@ -0,0 +1,23 @@ + + diff --git a/umap/static/umap/js/modules/importer.js b/umap/static/umap/js/modules/importer.js index 65069c09..036a372d 100644 --- a/umap/static/umap/js/modules/importer.js +++ b/umap/static/umap/js/modules/importer.js @@ -69,6 +69,9 @@ export default class Importer { case 'communesfr': import('./importers/communesfr.js').then(register) break + case 'cadastrefr': + import('./importers/cadastrefr.js').then(register) + break case 'overpass': import('./importers/overpass.js').then(register) break diff --git a/umap/static/umap/js/modules/importers/cadastrefr.js b/umap/static/umap/js/modules/importers/cadastrefr.js new file mode 100644 index 00000000..047e23ae --- /dev/null +++ b/umap/static/umap/js/modules/importers/cadastrefr.js @@ -0,0 +1,62 @@ +import { DomUtil } from '../../../vendors/leaflet/leaflet-src.esm.js' +import { BaseAjax, SingleMixin } from '../autocomplete.js' +import * as Util from '../utils.js' +import { AutocompleteCommunes } from './communesfr.js' + +const TEMPLATE = ` +
Importer les données cadastrales d’une commune française.
+ + +` + +export class Importer { + constructor(map, options) { + this.name = options.name || 'Cadastre' + this.id = 'cadastrefr' + } + + async open(importer) { + let boundary = null + let boundaryName = null + const container = DomUtil.create('div') + container.innerHTML = TEMPLATE + const select = container.querySelector('select') + const options = { + placeholder: 'Nom ou code INSEE…', + url: 'https://geo.api.gouv.fr/communes?nom={q}&limit=5', + on_select: (choice) => { + boundary = choice.item.value + boundaryName = choice.item.label + }, + } + this.autocomplete = new AutocompleteCommunes(container, options) + + const confirm = (form) => { + if (!boundary || !form.theme) { + Alert.error(translate('Please choose a theme and a boundary first.')) + return + } + importer.url = `https://cadastre.data.gouv.fr/bundler/cadastre-etalab/communes/${boundary}/geojson/${form.theme}` + importer.format = 'geojson' + importer.layerName = `${boundaryName} — ${select.options[select.selectedIndex].textContent}` + } + + importer.dialog + .open({ + template: container, + className: `${this.id} importer dark`, + }) + .then(confirm) + } +} diff --git a/umap/static/umap/js/modules/importers/communesfr.js b/umap/static/umap/js/modules/importers/communesfr.js index 75d889a1..3f901b1f 100644 --- a/umap/static/umap/js/modules/importers/communesfr.js +++ b/umap/static/umap/js/modules/importers/communesfr.js @@ -2,7 +2,7 @@ import { DomUtil } from '../../../vendors/leaflet/leaflet-src.esm.js' import { BaseAjax, SingleMixin } from '../autocomplete.js' import * as Util from '../utils.js' -class Autocomplete extends SingleMixin(BaseAjax) { +export class AutocompleteCommunes extends SingleMixin(BaseAjax) { createResult(item) { return super.createResult({ value: item.code, @@ -46,7 +46,7 @@ export class Importer { importer.dialog.close() }, } - this.autocomplete = new Autocomplete(container, options) + this.autocomplete = new AutocompleteCommunes(container, options) importer.dialog.open({ template: container,