mirror of
https://github.com/umap-project/umap.git
synced 2025-04-28 19:42:36 +02:00
wip: add aspoint attribute to geodatamine URL
This commit is contained in:
parent
4e3228d114
commit
d35e72dab9
3 changed files with 24 additions and 11 deletions
|
@ -262,6 +262,7 @@ ul.umap-autocomplete {
|
|||
}
|
||||
.umap-singleresult {
|
||||
margin-bottom: 10px;
|
||||
clear: both;
|
||||
}
|
||||
.umap-singleresult div,
|
||||
.umap-multiresult li {
|
||||
|
|
|
@ -103,7 +103,7 @@ export default class Importer {
|
|||
() => plugin.open(this)
|
||||
)
|
||||
}
|
||||
this.qs('.importers').toggleAttribute('hidden', true)
|
||||
this.qs('.importers').toggleAttribute('hidden', false)
|
||||
}
|
||||
for (const type of this.TYPES) {
|
||||
DomUtil.element({
|
||||
|
@ -123,7 +123,10 @@ export default class Importer {
|
|||
}
|
||||
|
||||
onChange() {
|
||||
this.qs('[name=link]').toggleAttribute('hidden', !this.url || this.format === 'umap')
|
||||
this.qs('[name=link]').toggleAttribute(
|
||||
'hidden',
|
||||
!this.url || this.format === 'umap'
|
||||
)
|
||||
this.qs('[name=full]').toggleAttribute('hidden', this.format !== 'umap')
|
||||
this.qs('[name=copy]').toggleAttribute('hidden', this.format === 'umap')
|
||||
this.qs('.destination').toggleAttribute('hidden', this.format === 'umap')
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import { DomUtil } from '../../../vendors/leaflet/leaflet-src.esm.js'
|
||||
import { BaseAjax, SingleMixin } from '../autocomplete.js'
|
||||
import { translate } from '../i18n.js'
|
||||
|
||||
const BOUNDARY_TYPES = {
|
||||
admin_6: 'département',
|
||||
|
@ -10,6 +11,15 @@ const BOUNDARY_TYPES = {
|
|||
local_authority: 'EPCI',
|
||||
}
|
||||
|
||||
const TEMPLATE = `
|
||||
<h3>GeoDataMine</h3>
|
||||
<select name="theme"></select>
|
||||
<label>
|
||||
<input type="checkbox" name="aspoint" />
|
||||
${translate('Convert all geometries to points')}
|
||||
</label>
|
||||
`
|
||||
|
||||
class Autocomplete extends SingleMixin(BaseAjax) {
|
||||
URL = 'https://geodatamine.fr/boundaries/search?text={q}'
|
||||
|
||||
|
@ -25,18 +35,14 @@ export class Importer {
|
|||
constructor() {
|
||||
this.name = 'GeoDataMine'
|
||||
this.baseUrl = 'https://geodatamine.fr'
|
||||
this.options = {
|
||||
theme: null,
|
||||
boundary: null,
|
||||
aspoint: false,
|
||||
}
|
||||
}
|
||||
|
||||
async open(importer) {
|
||||
let boundary = null
|
||||
const container = DomUtil.create('div')
|
||||
DomUtil.createTitle(container, this.name)
|
||||
container.innerHTML = TEMPLATE
|
||||
const response = await importer.map.request.get(`${this.baseUrl}/themes`)
|
||||
const select = DomUtil.element({ tagName: 'select', parent: container })
|
||||
const select = container.querySelector('select')
|
||||
if (response && response.ok) {
|
||||
const { themes } = await response.json()
|
||||
for (const theme of themes) {
|
||||
|
@ -50,11 +56,14 @@ export class Importer {
|
|||
} else {
|
||||
console.error(response)
|
||||
}
|
||||
const asPoint = container.querySelector('[name=aspoint]')
|
||||
this.autocomplete = new Autocomplete(container, {
|
||||
on_select: (choice) => (this.options.boundary = choice.item.value),
|
||||
on_select: (choice) => {
|
||||
boundary = choice.item.value
|
||||
},
|
||||
})
|
||||
const confirm = () => {
|
||||
importer.url = `${this.baseUrl}/data/${select.value}/${this.options.boundary}?format=geojson`
|
||||
importer.url = `${this.baseUrl}/data/${select.value}/${boundary}?format=geojson&aspoint=${asPoint.checked}`
|
||||
importer.format = 'geojson'
|
||||
importer.dialog.close()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue