Browse Source

Merge branch 'export-all'

master
parent
commit
7b79ea46c8
  1. 1
      index.php
  2. 3
      lang/ast.json
  3. 3
      lang/ca.json
  4. 3
      lang/cs.json
  5. 3
      lang/da.json
  6. 3
      lang/de.json
  7. 3
      lang/el.json
  8. 5
      lang/en.json
  9. 3
      lang/es.json
  10. 3
      lang/et.json
  11. 3
      lang/fr.json
  12. 3
      lang/hu.json
  13. 3
      lang/it.json
  14. 3
      lang/ja.json
  15. 3
      lang/nl.json
  16. 3
      lang/pl.json
  17. 3
      lang/pt-br.json
  18. 3
      lang/pt.json
  19. 3
      lang/ro.json
  20. 3
      lang/ru.json
  21. 3
      lang/sr.json
  22. 3
      lang/template.json
  23. 3
      lang/uk.json
  24. 2
      lib/modulekit/form
  25. 1
      package.json
  26. 4
      src/CategoryBase.js
  27. 19
      src/CategoryIndex.js
  28. 8
      src/CategoryOverpass.js
  29. 34
      src/ExportGeoJSON.js
  30. 24
      src/ExportOSMJSON.js
  31. 20
      src/ExportOSMXML.js
  32. 9
      src/chunkSplit.js
  33. 148
      src/exportAll.js
  34. 21
      src/index.js
  35. 5
      style.css

1
index.php

@ -65,6 +65,7 @@ html_export_var(array(
<img src='img/osb_logo.png'>
<div id='title'>OpenStreet <span class='large'>Browser</span><div class='version' title='<?=$modulekit['version']?>'><?php print substr($modulekit['version'], 0, strpos($modulekit['version'], '+')); ?></div></div>
</div>
<div id='globalTabs'></div>
<div id='content' class='list'>
<div id='contentList'></div>
<div id='contentDetails'></div>

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": "",

5
lang/en.json

@ -3,12 +3,15 @@
"category-info-tooltip": "Info & Map key",
"closed": "closed",
"default": "default",
"download:geojson": "Download as GeoJSON",
"edit": "edit",
"error": {
"message": "Error",
"!=1": "Errors"
},
"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": "",

2
lib/modulekit/form

@ -1 +1 @@
Subproject commit 8a2d3015ec181b14441037a79e7db3869453b135
Subproject commit 5d39b2f61b7eda9a635414acaeb3c4e0dc524490

1
package.json

@ -16,6 +16,7 @@
"babel-core": "^6.26.0",
"babel-preset-env": "^1.6.1",
"color-interpolate": "^1.0.2",
"file-saver": "^2.0.0",
"i18next-client": "^1.11.4",
"ip-location": "^1.0.1",
"json-multiline-strings": "^0.1.0",

4
src/CategoryBase.js

@ -204,4 +204,8 @@ CategoryBase.prototype.notifyChildLoadEnd = function (category) {
}
}
CategoryBase.prototype.allMapFeatures = function (callback) {
callback(null, [])
}
module.exports = CategoryBase

19
src/CategoryIndex.js

@ -106,5 +106,24 @@ CategoryIndex.prototype.toggleCategory = function (id) {
}.bind(this))
}
CategoryIndex.prototype.allMapFeatures = function (callback) {
let result = []
async.each(this.childrenCategories,
(category, done) => category.allMapFeatures(
(err, data) => {
if (err) {
return done(err)
}
result = result.concat(data)
global.setTimeout(done, 0)
}
),
(err) => callback(err, result)
)
}
OpenStreetBrowserLoader.registerType('index', CategoryIndex)
module.exports = CategoryIndex

8
src/CategoryOverpass.js

@ -491,5 +491,13 @@ CategoryOverpass.prototype.renderTemplate = function (object, templateId, callba
})
}
CategoryOverpass.prototype.allMapFeatures = function (callback) {
if (!this.isOpen) {
return callback(null, [])
}
callback(null, Object.values(this.layer.mainlayer.visibleFeatures))
}
OpenStreetBrowserLoader.registerType('overpass', CategoryOverpass)
module.exports = CategoryOverpass

34
src/ExportGeoJSON.js

@ -0,0 +1,34 @@
class ExportGeoJSON {
constructor (conf) {
this.conf = conf
}
each (ob, callback) {
ob.object.exportGeoJSON(this.conf, callback)
}
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

24
src/ExportOSMJSON.js

@ -0,0 +1,24 @@
class ExportOSMXML {
constructor (conf) {
this.conf = conf
this.elements = {}
}
each (ob, callback) {
ob.object.exportOSMJSON(this.conf, this.elements, callback)
}
finish (list) {
return {
content: JSON.stringify({
version: '0.6',
generator: 'OpenStreetBrowser',
elements: Object.values(this.elements)
}, null, ' '),
fileType: 'application/json',
extension: 'osm.json'
}
}
}
module.exports = ExportOSMXML

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

9
src/chunkSplit.js

@ -0,0 +1,9 @@
module.exports = function chunkSplit (data, size=1000) {
let result = []
for (let i = 0; i < data.length; i += size) {
result.push(data.slice(i, i + size))
}
return result
}

148
src/exportAll.js

@ -0,0 +1,148 @@
const tabs = require('modulekit-tabs')
const async = require('async')
const FileSaver = require('file-saver')
const chunkSplit = require('./chunkSplit')
const types = {
GeoJSON: require('./ExportGeoJSON'),
OSMXML: require('./ExportOSMXML'),
OSMJSON: require('./ExportOSMJSON')
}
let tab
let formExport
function prepareDownload (callback) {
let conf = formExport.get_data()
global.baseCategory.allMapFeatures((err, data) => {
if (err) {
return callback(err)
}
createDownload(conf, data, callback)
})
}
function createDownload (conf, data, callback) {
let type = types[conf.type]
let exportFun = new type(conf)
let chunks = chunkSplit(data, 1000)
let parentNode
async.mapLimit(
chunks,
1,
(chunk, done) => {
async.map(chunk,
(ob, done) => exportFun.each(ob, done),
(err, result) => {
global.setTimeout(() => done(err, result), 0)
}
)
},
(err, data) => {
if (err) {
return callback(err)
}
data = data.reduce((all, chunk) => all.concat(chunk))
let result = exportFun.finish(data)
var blob = new Blob([ result.content ], { type: result.fileType + ';charset=utf-8' })
FileSaver.saveAs(blob, 'openstreetbrowser.' + result.extension)
callback()
}
)
}
function formDef () {
let values = {}
Object.keys(types).forEach(type =>
values[type] = lang('export:' + type)
)
return {
type: {
name: 'Type',
type: 'radio',
values,
default: Object.keys(types)[0]
}
}
}
register_hook('init', function () {
tab = new tabs.Tab({
id: 'export'
})
global.tabs.add(tab)
tab.header.innerHTML = '<i class="fa fa-download" aria-hidden="true"></i>'
tab.header.title = lang('export-all')
tab.content.innerHTML = '<h3>' + lang('export-all') + '</h3>'
formExport = new form('export', formDef())
let domForm = document.createElement('form')
tab.content.appendChild(domForm)
formExport.show(domForm)
let submit = document.createElement('input')
submit.type = 'submit'
submit.value = lang('export-prepare')
submit.onclick = () => {
let progressIndicator = document.createElement('div')
progressIndicator.innerHTML = '<i class="fa fa-spinner fa-pulse fa-fw"></i> ' + lang('loading')
tab.content.appendChild(progressIndicator)
submit.style.display = 'none'
prepareDownload((err) => {
if (err) {
alert(err)
}
submit.style.display = 'block'
tab.content.removeChild(progressIndicator)
tab.unselect()
})
}
tab.content.appendChild(submit)
tab.on('select', () => {
formExport.resize()
})
})
module.exports = (data, div) => {
let formExport = new form('exportOne', formDef())
let domForm = document.createElement('form')
div.appendChild(domForm)
formExport.show(domForm)
let submit = document.createElement('input')
submit.type = 'submit'
submit.value = lang('export-prepare')
submit.onclick = () => {
let progressIndicator = document.createElement('div')
progressIndicator.innerHTML = '<i class="fa fa-spinner fa-pulse fa-fw"></i> ' + lang('loading')
div.appendChild(progressIndicator)
submit.style.display = 'none'
let conf = formExport.get_data()
createDownload(conf, [ data ], (err) => {
if (err) {
alert(err)
}
submit.style.display = 'block'
div.removeChild(progressIndicator)
})
}
div.appendChild(submit)
}

21
src/index.js

@ -1,6 +1,7 @@
/* globals map:true, overpassFrontend:true, currentPath:true, options:true, baseCategory:true, overpassUrl:true showDetails */
var LeafletGeoSearch = require('leaflet-geosearch')
const tabs = require('modulekit-tabs')
var OverpassFrontend = require('overpass-frontend')
var OpenStreetBrowserLoader = require('./OpenStreetBrowserLoader')
@ -17,6 +18,7 @@ global.baseCategory = null
global.overpassUrl = null
global.overpassFrontend = null
global.currentPath = null
global.tabs = null
var lastPopupClose = 0
// Optional modules
@ -31,6 +33,7 @@ require('./categories')
require('./wikipedia')
require('./image')
require('./addCategories')
let exportAll = require('./exportAll')
window.onload = function () {
var initState = config.defaultView
@ -42,6 +45,8 @@ window.onload = function () {
options = {}
}
global.tabs = new tabs.Tabs(document.getElementById('globalTabs'))
call_hooks('init')
call_hooks_callback('init_callback', initState, onload2.bind(this, initState))
@ -163,6 +168,10 @@ function onload2 (initState) {
call_hooks('initFinish')
}
global.allMapFeatures = function (callback) {
global.baseCategory.allMapFeatures(callback)
}
window.setPath = function (path, state) {
currentPath = path
@ -285,17 +294,9 @@ window.showDetails = function (data, category) {
h.innerHTML = lang('header:export')
dom.appendChild(h)
div = document.createElement('ul')
div = document.createElement('div')
dom.appendChild(div)
li = document.createElement('li')
div.appendChild(li)
a = document.createElement('a')
a.download = data.id + '.json'
a.href = 'data:application/json;charset=UTF-8,' + encodeURIComponent(JSON.stringify(data.object.GeoJSON(), null, ' '))
a.innerHTML = lang('download:geojson')
li.appendChild(a)
exportAll(data, div)
h = document.createElement('h3')
h.innerHTML = lang('header:attributes')

5
style.css

@ -77,6 +77,11 @@ a:active {
font-size: 16px;
}
#sidebar > #globalTabs {
padding-left: 10px;
padding-right: 10px;
}
#sidebar > #content {
flex: 1;
flex-shrink: 0;

Loading…
Cancel
Save