umap/umap/static/umap/js/modules/importers/cadastrefr.js
Yohan Boniface 8f7e5c7252
Some checks failed
Test & Docs / docs (push) Has been cancelled
Test & Docs / tests (postgresql, 3.10) (push) Has been cancelled
Test & Docs / tests (postgresql, 3.12) (push) Has been cancelled
Test & Docs / lint (push) Has been cancelled
chore: add missing import in cadastrefr
2024-12-03 18:07:26 +01:00

66 lines
2.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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'
import { translate } from '../i18n.js'
import { uMapAlert as Alert } from '../../components/alerts/alert.js'
const TEMPLATE = `
<h3>Cadastre</h3>
<p>Importer les données cadastrales dune commune française.</p>
<select name="theme">
<option value="batiments">Bâtiments</option>
<option value="communes">Communes</option>
<option value="feuilles">Feuilles</option>
<option value="lieux_dits">Lieux dits</option>
<option value="parcelles" selected>Parcelles</option>
<option value="prefixes_sections">Préfixes sections</option>
<option value="sections">Sections</option>
<option value="subdivisions_fiscales">Subdivisions fiscales</option>
</select>
<label id="boundary">
</label>
`
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`,
cancel: false,
accept: translate('Choose this data'),
})
.then(confirm)
}
}