mirror of
https://github.com/umap-project/umap.git
synced 2025-05-06 06:21:49 +02:00
Turn the importer into a module
This commit is contained in:
parent
773546d57c
commit
8c7f80c17f
4 changed files with 34 additions and 26 deletions
|
@ -1,10 +1,20 @@
|
||||||
import * as L from '../../vendors/leaflet/leaflet-src.esm.js'
|
import * as L from '../../vendors/leaflet/leaflet-src.esm.js'
|
||||||
import URLs from './urls.js'
|
import URLs from './urls.js'
|
||||||
import Browser from './browser.js'
|
import Browser from './browser.js'
|
||||||
|
import Importer from './importer.js'
|
||||||
import { Request, ServerRequest, RequestError, HTTPError, NOKError } from './request.js'
|
import { Request, ServerRequest, RequestError, HTTPError, NOKError } from './request.js'
|
||||||
// Import modules and export them to the global scope.
|
// Import modules and export them to the global scope.
|
||||||
// For the not yet module-compatible JS out there.
|
// For the not yet module-compatible JS out there.
|
||||||
|
|
||||||
// Copy the leaflet module, it's expected by leaflet plugins to be writeable.
|
// Copy the leaflet module, it's expected by leaflet plugins to be writeable.
|
||||||
window.L = { ...L }
|
window.L = { ...L }
|
||||||
window.U = { URLs, Request, ServerRequest, RequestError, HTTPError, NOKError, Browser }
|
window.U = {
|
||||||
|
URLs,
|
||||||
|
Request,
|
||||||
|
ServerRequest,
|
||||||
|
RequestError,
|
||||||
|
HTTPError,
|
||||||
|
NOKError,
|
||||||
|
Browser,
|
||||||
|
Importer,
|
||||||
|
}
|
||||||
|
|
|
@ -1,41 +1,41 @@
|
||||||
U.Importer = L.Class.extend({
|
export default class Importer {
|
||||||
initialize: function (map) {
|
constructor(map) {
|
||||||
this.map = map
|
this.map = map
|
||||||
this.presets = map.options.importPresets
|
this.presets = map.options.importPresets
|
||||||
},
|
}
|
||||||
|
|
||||||
_buildDatalayerOptions: function (element) {
|
#buildDatalayerOptions(layerSelect) {
|
||||||
let option
|
let option
|
||||||
this.map.eachDataLayerReverse((datalayer) => {
|
this.map.eachDataLayerReverse((datalayer) => {
|
||||||
if (datalayer.isLoaded() && !datalayer.isRemoteLayer()) {
|
if (datalayer.isLoaded() && !datalayer.isRemoteLayer()) {
|
||||||
const id = L.stamp(datalayer)
|
const id = L.stamp(datalayer)
|
||||||
option = L.DomUtil.add('option', '', element, datalayer.options.name)
|
option = L.DomUtil.add('option', '', layerSelect, datalayer.options.name)
|
||||||
option.value = id
|
option.value = id
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
L.DomUtil.element(
|
L.DomUtil.element(
|
||||||
'option',
|
'option',
|
||||||
{ value: '', textContent: L._('Import in a new layer') },
|
{ value: '', textContent: L._('Import in a new layer') },
|
||||||
element
|
layerSelect
|
||||||
)
|
)
|
||||||
},
|
}
|
||||||
|
|
||||||
_buildPresetsOptions: function (element) {
|
#buildPresetsOptions(presetSelect) {
|
||||||
if (this.presets.length) {
|
if (this.presets.length) {
|
||||||
const presetBox = this.form.querySelector('#preset-box')
|
const presetBox = this.form.querySelector('#preset-box')
|
||||||
presetBox.removeAttribute('hidden')
|
presetBox.removeAttribute('hidden')
|
||||||
const noPreset = L.DomUtil.create('option', '', element)
|
const noPreset = L.DomUtil.create('option', '', presetSelect)
|
||||||
noPreset.value = noPreset.textContent = L._('Choose a preset')
|
noPreset.value = noPreset.textContent = L._('Choose a preset')
|
||||||
for (const preset of this.presets) {
|
for (const preset of this.presets) {
|
||||||
option = L.DomUtil.create('option', '', this.presetSelect)
|
option = L.DomUtil.create('option', '', presetSelect)
|
||||||
option.value = preset.url
|
option.value = preset.url
|
||||||
option.textContent = preset.label
|
option.textContent = preset.label
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
build: function () {
|
build() {
|
||||||
template = document.querySelector('#umap-upload')
|
const template = document.querySelector('#umap-upload')
|
||||||
this.form = template.content.firstElementChild.cloneNode(true)
|
this.form = template.content.firstElementChild.cloneNode(true)
|
||||||
this.presetSelect = this.form.querySelector('[name="preset-select"]')
|
this.presetSelect = this.form.querySelector('[name="preset-select"]')
|
||||||
this.fileInput = this.form.querySelector('[name="file-input"]')
|
this.fileInput = this.form.querySelector('[name="file-input"]')
|
||||||
|
@ -46,8 +46,8 @@ U.Importer = L.Class.extend({
|
||||||
this.formatSelect = this.form.querySelector('[name="format"]')
|
this.formatSelect = this.form.querySelector('[name="format"]')
|
||||||
this.layerSelect = this.form.querySelector('[name="datalayer"]')
|
this.layerSelect = this.form.querySelector('[name="datalayer"]')
|
||||||
this.submitInput = this.form.querySelector('[name="submit-input"]')
|
this.submitInput = this.form.querySelector('[name="submit-input"]')
|
||||||
this._buildDatalayerOptions(this.layerSelect)
|
this.#buildDatalayerOptions(this.layerSelect)
|
||||||
this._buildPresetsOptions(this.presetSelect)
|
this.#buildPresetsOptions(this.presetSelect)
|
||||||
|
|
||||||
this.submitInput.addEventListener('click', this.submit.bind(this))
|
this.submitInput.addEventListener('click', this.submit.bind(this))
|
||||||
this.fileInput.addEventListener('change', (e) => {
|
this.fileInput.addEventListener('change', (e) => {
|
||||||
|
@ -65,22 +65,22 @@ U.Importer = L.Class.extend({
|
||||||
}
|
}
|
||||||
this.formatSelect.value = type
|
this.formatSelect.value = type
|
||||||
})
|
})
|
||||||
},
|
}
|
||||||
|
|
||||||
open: function () {
|
open() {
|
||||||
if (!this.form) this.build()
|
if (!this.form) this.build()
|
||||||
this.map.ui.openPanel({
|
this.map.ui.openPanel({
|
||||||
data: { html: this.form },
|
data: { html: this.form },
|
||||||
className: 'dark',
|
className: 'dark',
|
||||||
})
|
})
|
||||||
},
|
}
|
||||||
|
|
||||||
openFiles: function () {
|
openFiles() {
|
||||||
this.open()
|
this.open()
|
||||||
this.fileInput.showPicker()
|
this.fileInput.showPicker()
|
||||||
},
|
}
|
||||||
|
|
||||||
submit: function () {
|
submit() {
|
||||||
const urlInputValue = this.form.querySelector('[name="url-input"]').value
|
const urlInputValue = this.form.querySelector('[name="url-input"]').value
|
||||||
const rawInputValue = this.form.querySelector('[name="raw-input"]').value
|
const rawInputValue = this.form.querySelector('[name="raw-input"]').value
|
||||||
const clearFlag = this.form.querySelector('[name="clear"]')
|
const clearFlag = this.form.querySelector('[name="clear"]')
|
||||||
|
@ -120,5 +120,5 @@ U.Importer = L.Class.extend({
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
})
|
}
|
|
@ -44,7 +44,6 @@
|
||||||
<script src="../js/umap.controls.js" defer></script>
|
<script src="../js/umap.controls.js" defer></script>
|
||||||
<script src="../js/umap.slideshow.js" defer></script>
|
<script src="../js/umap.slideshow.js" defer></script>
|
||||||
<script src="../js/umap.tableeditor.js" defer></script>
|
<script src="../js/umap.tableeditor.js" defer></script>
|
||||||
<script src="../js/umap.importer.js" defer></script>
|
|
||||||
<script src="../js/umap.share.js" defer></script>
|
<script src="../js/umap.share.js" defer></script>
|
||||||
<script src="../js/umap.js" defer></script>
|
<script src="../js/umap.js" defer></script>
|
||||||
<script src="../js/umap.ui.js" defer></script>
|
<script src="../js/umap.ui.js" defer></script>
|
||||||
|
|
|
@ -45,7 +45,6 @@
|
||||||
<script src="{% static 'umap/js/umap.controls.js' %}" defer></script>
|
<script src="{% static 'umap/js/umap.controls.js' %}" defer></script>
|
||||||
<script src="{% static 'umap/js/umap.slideshow.js' %}" defer></script>
|
<script src="{% static 'umap/js/umap.slideshow.js' %}" defer></script>
|
||||||
<script src="{% static 'umap/js/umap.tableeditor.js' %}" defer></script>
|
<script src="{% static 'umap/js/umap.tableeditor.js' %}" defer></script>
|
||||||
<script src="{% static 'umap/js/umap.importer.js' %}" defer></script>
|
|
||||||
<script src="{% static 'umap/js/umap.share.js' %}" defer></script>
|
<script src="{% static 'umap/js/umap.share.js' %}" defer></script>
|
||||||
<script src="{% static 'umap/js/umap.js' %}" defer></script>
|
<script src="{% static 'umap/js/umap.js' %}" defer></script>
|
||||||
<script src="{% static 'umap/js/umap.ui.js' %}" defer></script>
|
<script src="{% static 'umap/js/umap.ui.js' %}" defer></script>
|
||||||
|
|
Loading…
Reference in a new issue