mirror of
https://github.com/umap-project/umap.git
synced 2025-04-29 11:52:38 +02:00
wip: add a basic importer for commune shapes
Mainly wanted to have two improters to play with, in order to better understand the common part, and thus the API we may define between them and the importer panel.
This commit is contained in:
parent
5b914c1bd2
commit
1e4de02694
2 changed files with 61 additions and 2 deletions
|
@ -257,7 +257,6 @@ export class BaseAjax extends BaseAutocomplete {
|
||||||
if (response && response.ok) {
|
if (response && response.ok) {
|
||||||
return await response.json()
|
return await response.json()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
60
umap/static/umap/js/modules/plugins/communes.js
Normal file
60
umap/static/umap/js/modules/plugins/communes.js
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
import { DomUtil, DomEvent, stamp } from '../../../vendors/leaflet/leaflet-src.esm.js'
|
||||||
|
import { translate } from '../i18n.js'
|
||||||
|
import { BaseAjax, SingleMixin } from '../autocomplete.js'
|
||||||
|
import { Request } from '../request.js'
|
||||||
|
import Alert from '../ui/alert.js'
|
||||||
|
import Dialog from '../ui/dialog.js'
|
||||||
|
|
||||||
|
class Autocomplete extends SingleMixin(BaseAjax) {
|
||||||
|
URL = 'https://geo.api.gouv.fr/communes?nom={q}&limit=5'
|
||||||
|
|
||||||
|
createResult(item) {
|
||||||
|
return super.createResult({
|
||||||
|
value: item.code,
|
||||||
|
label: `${item.nom} (${item.code})`,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class Plugin {
|
||||||
|
constructor(map) {
|
||||||
|
this.map = map
|
||||||
|
this.name = 'Communes'
|
||||||
|
this.type = 'importer'
|
||||||
|
this.dialog = new Dialog(this.map._controlContainer)
|
||||||
|
this.map.registerPlugin(this)
|
||||||
|
this.options = {
|
||||||
|
theme: null,
|
||||||
|
boundary: null,
|
||||||
|
aspoint: false,
|
||||||
|
}
|
||||||
|
const alert = new Alert(document.querySelector('header'))
|
||||||
|
this.request = new Request(alert)
|
||||||
|
}
|
||||||
|
|
||||||
|
addImporter() {
|
||||||
|
return {
|
||||||
|
name: this.name,
|
||||||
|
callback: this.open,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async open(importer) {
|
||||||
|
const container = DomUtil.create('div')
|
||||||
|
DomUtil.createTitle(container, this.name)
|
||||||
|
const options = {
|
||||||
|
on_select: (choice) => {
|
||||||
|
this.options.boundary = choice.item.value
|
||||||
|
importer.urlInput.value = `https://geo.api.gouv.fr/communes?code=${this.options.boundary}&format=geojson&geometry=contour`
|
||||||
|
importer.typeInput.value = 'geojson'
|
||||||
|
this.dialog.close()
|
||||||
|
},
|
||||||
|
}
|
||||||
|
this.autocomplete = new Autocomplete(container, options)
|
||||||
|
|
||||||
|
this.dialog.open({
|
||||||
|
content: container,
|
||||||
|
className: 'communes dark',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue