Browse Source

global.allMapFeatures(): return all visible map features

master
parent
commit
346252a7d1
  1. 4
      src/CategoryBase.js
  2. 19
      src/CategoryIndex.js
  3. 8
      src/CategoryOverpass.js
  4. 4
      src/index.js

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

@ -490,5 +490,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

4
src/index.js

@ -168,6 +168,10 @@ function onload2 (initState) {
call_hooks('initFinish')
}
global.allMapFeatures = function (callback) {
global.baseCategory.allMapFeatures(callback)
}
window.setPath = function (path, state) {
currentPath = path

Loading…
Cancel
Save