Browse Source

exportAll(): use sub modules ExportGeoJSON() and ExportOSMXML()

master
parent
commit
41844a28be
  1. 3
      lang/ast.json
  2. 3
      lang/ca.json
  3. 3
      lang/cs.json
  4. 3
      lang/da.json
  5. 3
      lang/de.json
  6. 3
      lang/el.json
  7. 4
      lang/en.json
  8. 3
      lang/es.json
  9. 3
      lang/et.json
  10. 3
      lang/fr.json
  11. 3
      lang/hu.json
  12. 3
      lang/it.json
  13. 3
      lang/ja.json
  14. 3
      lang/nl.json
  15. 3
      lang/pl.json
  16. 3
      lang/pt-br.json
  17. 3
      lang/pt.json
  18. 3
      lang/ro.json
  19. 3
      lang/ru.json
  20. 3
      lang/sr.json
  21. 3
      lang/template.json
  22. 3
      lang/uk.json
  23. 34
      src/ExportGeoJSON.js
  24. 20
      src/ExportOSMXML.js
  25. 65
      src/exportAll.js

3
lang/ast.json

@ -3,9 +3,10 @@
"category-info-tooltip": "",
"closed": "",
"default": "",
"download:geojson": "",
"edit": "",
"error": "",
"export:GeoJSON": "",
"export:OSMXML": null,
"facilities": "",
"header:attributes": "",
"header:export": "",

3
lang/ca.json

@ -3,9 +3,10 @@
"category-info-tooltip": "",
"closed": "",
"default": "",
"download:geojson": "",
"edit": "",
"error": "",
"export:GeoJSON": "",
"export:OSMXML": null,
"facilities": "",
"header:attributes": "",
"header:export": "",

3
lang/cs.json

@ -3,9 +3,10 @@
"category-info-tooltip": "",
"closed": "",
"default": "",
"download:geojson": "",
"edit": "",
"error": "",
"export:GeoJSON": "",
"export:OSMXML": null,
"facilities": "",
"header:attributes": "",
"header:export": "",

3
lang/da.json

@ -3,9 +3,10 @@
"category-info-tooltip": "",
"closed": "",
"default": "",
"download:geojson": "",
"edit": "",
"error": "",
"export:GeoJSON": "",
"export:OSMXML": null,
"facilities": "",
"header:attributes": "",
"header:export": "",

3
lang/de.json

@ -3,12 +3,13 @@
"category-info-tooltip": "Info & Legende",
"closed": "geschlossen",
"default": "Standard",
"download:geojson": "Als GeoJSON runterladen",
"edit": "bearbeiten",
"error": {
"message": "Fehler",
"!=1": "Fehler"
},
"export:GeoJSON": "Als GeoJSON runterladen",
"export:OSMXML": null,
"facilities": "Einrichtungen",
"header:attributes": "Attribute",
"header:export": "Export",

3
lang/el.json

@ -3,9 +3,10 @@
"category-info-tooltip": "",
"closed": "",
"default": "",
"download:geojson": "",
"edit": "",
"error": "",
"export:GeoJSON": "",
"export:OSMXML": null,
"facilities": "",
"header:attributes": "",
"header:export": "",

4
lang/en.json

@ -3,8 +3,6 @@
"category-info-tooltip": "Info & Map key",
"closed": "closed",
"default": "default",
"download:geojson": "Download as GeoJSON",
"download:osmxml": "Download as OSMXML",
"edit": "edit",
"error": {
"message": "Error",
@ -12,6 +10,8 @@
},
"export-all": "Export all visible map features",
"export-prepare": "Prepare download",
"export:GeoJSON": "Download as GeoJSON",
"export:OSMXML": "Download as OSMXML",
"facilities": "Facilities",
"header:attributes": "Attributes",
"header:export": "Export",

3
lang/es.json

@ -3,9 +3,10 @@
"category-info-tooltip": "",
"closed": "",
"default": "",
"download:geojson": "",
"edit": "",
"error": "",
"export:GeoJSON": "",
"export:OSMXML": null,
"facilities": "",
"header:attributes": "",
"header:export": "",

3
lang/et.json

@ -3,9 +3,10 @@
"category-info-tooltip": "",
"closed": "",
"default": "",
"download:geojson": "",
"edit": "",
"error": "",
"export:GeoJSON": "",
"export:OSMXML": null,
"facilities": "",
"header:attributes": "",
"header:export": "",

3
lang/fr.json

@ -3,9 +3,10 @@
"category-info-tooltip": "Info & Légende",
"closed": "Fermé",
"default": "Par défaut",
"download:geojson": "Télécharger comme GeoJSON",
"edit": "éditer",
"error": "Erreur",
"export:GeoJSON": "Télécharger comme GeoJSON",
"export:OSMXML": null,
"facilities": "Aménagements",
"header:attributes": "Attributs",
"header:export": "Export",

3
lang/hu.json

@ -3,9 +3,10 @@
"category-info-tooltip": "Információk és jelmagyarázat",
"closed": "Lezárva",
"default": "Alapértelmezett",
"download:geojson": "Letöltés GeoJSON formátumban",
"edit": "Szerkesztés",
"error": "Hiba",
"export:GeoJSON": "Letöltés GeoJSON formátumban",
"export:OSMXML": null,
"facilities": "Létesítmények",
"header:attributes": "Tulajdonságok",
"header:export": "Exportálás",

3
lang/it.json

@ -3,9 +3,10 @@
"category-info-tooltip": "",
"closed": "",
"default": "",
"download:geojson": "",
"edit": "",
"error": "",
"export:GeoJSON": "",
"export:OSMXML": null,
"facilities": "",
"header:attributes": "",
"header:export": "",

3
lang/ja.json

@ -3,9 +3,10 @@
"category-info-tooltip": "",
"closed": "",
"default": "",
"download:geojson": "",
"edit": "",
"error": "",
"export:GeoJSON": "",
"export:OSMXML": null,
"facilities": "",
"header:attributes": "",
"header:export": "",

3
lang/nl.json

@ -3,9 +3,10 @@
"category-info-tooltip": "",
"closed": "",
"default": "",
"download:geojson": "",
"edit": "",
"error": "",
"export:GeoJSON": "",
"export:OSMXML": null,
"facilities": "",
"header:attributes": "",
"header:export": "",

3
lang/pl.json

@ -3,9 +3,10 @@
"category-info-tooltip": "",
"closed": "",
"default": "",
"download:geojson": "",
"edit": "",
"error": "",
"export:GeoJSON": "",
"export:OSMXML": null,
"facilities": "",
"header:attributes": "",
"header:export": "",

3
lang/pt-br.json

@ -3,12 +3,13 @@
"category-info-tooltip": "Info & Legenda",
"closed": "fechado",
"default": "padrão",
"download:geojson": "Baixar como GeoJSON",
"edit": "editar",
"error": {
"message": "Erro",
"!=1": "Erros"
},
"export:GeoJSON": "Baixar como GeoJSON",
"export:OSMXML": null,
"facilities": "Instalações",
"header:attributes": "Atributos",
"header:export": "Exportar",

3
lang/pt.json

@ -3,12 +3,13 @@
"category-info-tooltip": "Info & Legenda",
"closed": "fechado",
"default": "padrão",
"download:geojson": "Descarregar como GeoJSON",
"edit": "editar",
"error": {
"message": "Erro",
"!=1": "Erros"
},
"export:GeoJSON": "Descarregar como GeoJSON",
"export:OSMXML": null,
"facilities": "Instalações",
"header:attributes": "Atributos",
"header:export": "Exportar",

3
lang/ro.json

@ -3,9 +3,10 @@
"category-info-tooltip": "",
"closed": "",
"default": "",
"download:geojson": "",
"edit": "",
"error": "",
"export:GeoJSON": "",
"export:OSMXML": null,
"facilities": "",
"header:attributes": "",
"header:export": "",

3
lang/ru.json

@ -3,9 +3,10 @@
"category-info-tooltip": "",
"closed": "",
"default": "",
"download:geojson": "",
"edit": "",
"error": "",
"export:GeoJSON": "",
"export:OSMXML": null,
"facilities": "",
"header:attributes": "",
"header:export": "",

3
lang/sr.json

@ -3,9 +3,10 @@
"category-info-tooltip": "",
"closed": "",
"default": "",
"download:geojson": "",
"edit": "",
"error": "",
"export:GeoJSON": "",
"export:OSMXML": null,
"facilities": "",
"header:attributes": "",
"header:export": "",

3
lang/template.json

@ -3,9 +3,10 @@
"category-info-tooltip": "",
"closed": "",
"default": "",
"download:geojson": "",
"edit": "",
"error": "",
"export:GeoJSON": "",
"export:OSMXML": null,
"facilities": "",
"header:attributes": "",
"header:export": "",

3
lang/uk.json

@ -3,9 +3,10 @@
"category-info-tooltip": "",
"closed": "",
"default": "",
"download:geojson": "",
"edit": "",
"error": "",
"export:GeoJSON": "",
"export:OSMXML": null,
"facilities": "",
"header:attributes": "",
"header:export": "",

34
src/ExportGeoJSON.js

@ -0,0 +1,34 @@
class ExportGeoJSON {
constructor (conf) {
this.conf = conf
}
each (ob, callback) {
callback(null, ob.object.GeoJSON(this.conf))
}
finishOne (object) {
return {
content: JSON.stringify(object, null, ' '),
fileType: 'application/json',
extension: 'geojson'
}
}
finish (list) {
if (list.length) {
list = {
type: 'FeatureCollection',
features: list
}
}
return {
content: JSON.stringify(list, null, ' '),
fileType: 'application/json',
extension: 'geojson'
}
}
}
module.exports = ExportGeoJSON

20
src/ExportOSMXML.js

@ -0,0 +1,20 @@
class ExportOSMXML {
constructor (conf) {
this.conf = conf
this.parentNode = document.createElement('osm')
}
each (ob, callback) {
ob.object.exportOSMXML(this.conf, this.parentNode, callback)
}
finish (list) {
return {
content: '<?xml version="1.0" encoding="UTF-8"?><osm version="0.6" generator="OpenStreetBrowser">' + this.parentNode.innerHTML + '</osm>',
fileType: 'application/xml',
extension: 'osm.xml'
}
}
}
module.exports = ExportOSMXML

65
src/exportAll.js

@ -4,6 +4,11 @@ const FileSaver = require('file-saver')
const chunkSplit = require('./chunkSplit')
const types = {
GeoJSON: require('./ExportGeoJSON'),
OSMXML: require('./ExportOSMXML')
}
let tab
let formExport
@ -11,65 +16,35 @@ function prepareDownload (callback) {
let conf = formExport.get_data()
let fileType
let extension
let type = types[conf.type]
let exportFun = new type(conf)
global.baseCategory.allMapFeatures((err, data) => {
let chunks = chunkSplit(data, 1000)
let parentNode
switch (conf.type) {
case 'geojson':
break
case 'osmxml':
parentNode = document.createElement('osm')
break
}
async.mapLimit(
chunks,
1,
(chunk, done) => {
async.map(chunk,
(ob, done) => {
switch (conf.type) {
case 'geojson':
done(null, ob.object.GeoJSON(conf))
break
case 'osmxml':
ob.object.exportOSMXML(conf, parentNode, done)
break
default:
done('wrong type')
}
},
(ob, done) => exportFun.each(ob, done),
(err, result) => {
global.setTimeout(() => done(err, result), 0)
}
)
},
(err, result) => {
(err, data) => {
if (err) {
return callback(err)
}
switch (conf.type) {
case 'geojson':
result = {
type: 'FeatureCollection',
features: result
}
result = JSON.stringify(result, null, ' ')
fileType = 'application/json'
extension = 'geojson'
break
case 'osmxml':
result = '<?xml version="1.0" encoding="UTF-8"?><osm version="0.6" generator="OpenStreetBrowser">' + parentNode.innerHTML + '</osm>'
fileType = 'application/xml'
extension = 'osm.xml'
break
}
data = data.reduce((all, chunk) => all.concat(chunk))
let result = exportFun.finish(data)
var blob = new Blob([ result ], { type: fileType + ';charset=utf-8' })
FileSaver.saveAs(blob, 'openstreetbrowser.' + extension)
var blob = new Blob([ result.content ], { type: result.fileType + ';charset=utf-8' })
FileSaver.saveAs(blob, 'openstreetbrowser.' + result.extension)
callback()
}
@ -86,15 +61,17 @@ register_hook('init', function () {
tab.header.innerHTML = '<i class="fa fa-download" aria-hidden="true"></i>'
tab.content.innerHTML = lang('export-all')
let values = {}
Object.keys(types).forEach(type =>
values[type] = lang('export:' + type)
)
formExport = new form('export', {
type: {
name: 'Type',
type: 'radio',
values: {
geojson: lang('download:geojson'),
osmxml: lang('download:osmxml')
},
default: 'geojson'
values,
default: Object.keys(types)[0]
}
})

Loading…
Cancel
Save