-
-
Notifications
You must be signed in to change notification settings - Fork 226
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
<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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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 ?