Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add importer for French cadastre #2223

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions umap/static/umap/css/importers.css
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
23 changes: 23 additions & 0 deletions umap/static/umap/img/importers/cadastrefr.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions umap/static/umap/js/modules/importer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
62 changes: 62 additions & 0 deletions umap/static/umap/js/modules/importers/cadastrefr.js
Original file line number Diff line number Diff line change
@@ -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 = `
<h3>Cadastre</h3>
<p>Importer les données cadastrales d’une 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>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm tempted to put the selected choice at the top of the list, it is a more classic pattern (and I get that it's sorted alphabetically for now but still).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm tempted to think that given the list is small, the alphabetical order is more natural and convenient once open. Let's try that way and see ?

<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`,
})
.then(confirm)
}
}
4 changes: 2 additions & 2 deletions umap/static/umap/js/modules/importers/communesfr.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down