Button to download umap backup from backend url
This commit is contained in:
parent
0be42d39cb
commit
207c47d078
2 changed files with 16 additions and 42 deletions
|
@ -924,15 +924,6 @@ L.U.Map.include({
|
|||
ext: '.csv',
|
||||
filetype: 'text/csv',
|
||||
},
|
||||
umap: {
|
||||
name: L._('Full map data'),
|
||||
formatter: function (map) {
|
||||
return map.serialize()
|
||||
},
|
||||
ext: '.umap',
|
||||
filetype: 'application/json',
|
||||
selected: true,
|
||||
},
|
||||
},
|
||||
|
||||
renderEditToolbar: function () {
|
||||
|
@ -1140,6 +1131,20 @@ L.U.Map.include({
|
|||
shortUrl.value = this.options.shortUrl
|
||||
}
|
||||
L.DomUtil.create('hr', '', container)
|
||||
L.DomUtil.add('h4', '', container, L._('Backup data'))
|
||||
const downloadUrl = L.Util.template(this.options.urls.map_download, {
|
||||
map_id: this.options.umap_id,
|
||||
})
|
||||
const link = L.DomUtil.createLink(
|
||||
'button',
|
||||
container,
|
||||
L._('Download uMap backup format'),
|
||||
downloadUrl
|
||||
)
|
||||
let name = this.options.name || 'data'
|
||||
name = name.replace(/[^a-z0-9]/gi, '_').toLowerCase()
|
||||
link.setAttribute('download', `${name}.umap`)
|
||||
L.DomUtil.create('hr', '', container)
|
||||
L.DomUtil.add('h4', '', container, L._('Download data'))
|
||||
const typeInput = L.DomUtil.create('select', '', container)
|
||||
typeInput.name = 'format'
|
||||
|
@ -1149,12 +1154,6 @@ L.U.Map.include({
|
|||
container,
|
||||
L._('Only visible features will be downloaded.')
|
||||
)
|
||||
exportCaveat.id = 'export_caveat_text'
|
||||
const toggleCaveat = () => {
|
||||
if (typeInput.value === 'umap') exportCaveat.style.display = 'none'
|
||||
else exportCaveat.style.display = 'inherit'
|
||||
}
|
||||
L.DomEvent.on(typeInput, 'change', toggleCaveat)
|
||||
for (const key in this.EXPORT_TYPES) {
|
||||
if (this.EXPORT_TYPES.hasOwnProperty(key)) {
|
||||
option = L.DomUtil.create('option', '', typeInput)
|
||||
|
@ -1163,18 +1162,11 @@ L.U.Map.include({
|
|||
if (this.EXPORT_TYPES[key].selected) option.selected = true
|
||||
}
|
||||
}
|
||||
toggleCaveat()
|
||||
L.DomUtil.createButton(
|
||||
'button',
|
||||
container,
|
||||
L._('Download data'),
|
||||
() => {
|
||||
if (typeInput.value === 'umap') {
|
||||
this.fullDownload()
|
||||
} else {
|
||||
this.download(typeInput.value)
|
||||
}
|
||||
},
|
||||
() => this.download(typeInput.value),
|
||||
this
|
||||
)
|
||||
this.ui.openPanel({ data: { html: container } })
|
||||
|
|
|
@ -831,7 +831,7 @@ L.U.Map.include({
|
|||
},
|
||||
|
||||
format: function (mode) {
|
||||
const type = this.EXPORT_TYPES[mode || 'umap']
|
||||
const type = this.EXPORT_TYPES[mode || 'TODISCUSS']
|
||||
const content = type.formatter(this)
|
||||
let name = this.options.name || 'data'
|
||||
name = name.replace(/[^a-z0-9]/gi, '_').toLowerCase()
|
||||
|
@ -1074,24 +1074,6 @@ L.U.Map.include({
|
|||
return properties
|
||||
},
|
||||
|
||||
serialize: function () {
|
||||
// Do not use local path during unit tests
|
||||
const uri = window.location.protocol === 'file:' ? null : window.location.href
|
||||
const umapfile = {
|
||||
type: 'umap',
|
||||
uri: uri,
|
||||
properties: this.exportOptions(),
|
||||
geometry: this.geometry(),
|
||||
layers: [],
|
||||
}
|
||||
|
||||
this.eachDataLayer((datalayer) => {
|
||||
umapfile.layers.push(datalayer.umapGeoJSON())
|
||||
})
|
||||
|
||||
return JSON.stringify(umapfile, null, 2)
|
||||
},
|
||||
|
||||
saveSelf: function () {
|
||||
const geojson = {
|
||||
type: 'Feature',
|
||||
|
|
Loading…
Reference in a new issue