|
|
@ -2,7 +2,8 @@ var OverpassLayer = require('overpass-layer') |
|
|
|
|
|
|
|
const Repository = require('./Repository') |
|
|
|
|
|
|
|
function OpenStreetBrowserLoader () { |
|
|
|
class OpenStreetBrowserLoader { |
|
|
|
constructor () { |
|
|
|
this.types = {} |
|
|
|
this.categories = {} |
|
|
|
this.repoCache = {} |
|
|
@ -11,7 +12,7 @@ function OpenStreetBrowserLoader () { |
|
|
|
this._loadClash = {} // if a category is being loaded multiple times, collect callbacks
|
|
|
|
} |
|
|
|
|
|
|
|
OpenStreetBrowserLoader.prototype.setMap = function (map) { |
|
|
|
setMap (map) { |
|
|
|
this.map = map |
|
|
|
} |
|
|
|
|
|
|
@ -21,7 +22,7 @@ OpenStreetBrowserLoader.prototype.setMap = function (map) { |
|
|
|
* @waram {boolean} [options.force=false] Whether repository should be reload or not. |
|
|
|
* @param function callback Callback which will be called with (err, category) |
|
|
|
*/ |
|
|
|
OpenStreetBrowserLoader.prototype.getCategory = function (id, options, callback) { |
|
|
|
getCategory (id, options, callback) { |
|
|
|
if (typeof options === 'function') { |
|
|
|
callback = options |
|
|
|
options = {} |
|
|
@ -74,7 +75,7 @@ OpenStreetBrowserLoader.prototype.getCategory = function (id, options, callback) |
|
|
|
* @waram {boolean} [options.force=false] Whether repository should be reload or not. |
|
|
|
* @param function callback Callback which will be called with (err, repoData) |
|
|
|
*/ |
|
|
|
OpenStreetBrowserLoader.prototype.getRepo = function (repo, options, callback) { |
|
|
|
getRepo (repo, options, callback) { |
|
|
|
if (options.force) { |
|
|
|
delete this.repoCache[repo] |
|
|
|
} |
|
|
@ -127,7 +128,7 @@ OpenStreetBrowserLoader.prototype.getRepo = function (repo, options, callback) { |
|
|
|
req.send() |
|
|
|
} |
|
|
|
|
|
|
|
OpenStreetBrowserLoader.prototype.getRepository = function (id, options, callback) { |
|
|
|
getRepository (id, options, callback) { |
|
|
|
if (id in this.repositories) { |
|
|
|
return callback(null, this.repositories[id]) |
|
|
|
} |
|
|
@ -147,7 +148,7 @@ OpenStreetBrowserLoader.prototype.getRepository = function (id, options, callbac |
|
|
|
* @waram {boolean} [options.force=false] Whether repository should be reload or not. |
|
|
|
* @param function callback Callback which will be called with (err, template) |
|
|
|
*/ |
|
|
|
OpenStreetBrowserLoader.prototype.getTemplate = function (id, options, callback) { |
|
|
|
getTemplate (id, options, callback) { |
|
|
|
if (typeof options === 'function') { |
|
|
|
callback = options |
|
|
|
options = {} |
|
|
@ -187,7 +188,7 @@ OpenStreetBrowserLoader.prototype.getTemplate = function (id, options, callback) |
|
|
|
}.bind(this)) |
|
|
|
} |
|
|
|
|
|
|
|
OpenStreetBrowserLoader.prototype.getCategoryFromData = function (id, options, data, callback) { |
|
|
|
getCategoryFromData (id, options, data, callback) { |
|
|
|
var ids = this.getFullId(id, options) |
|
|
|
|
|
|
|
if (ids.fullId in this.categories) { |
|
|
@ -221,7 +222,7 @@ OpenStreetBrowserLoader.prototype.getCategoryFromData = function (id, options, d |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
OpenStreetBrowserLoader.prototype.getFullId = function (id, options) { |
|
|
|
getFullId (id, options) { |
|
|
|
var result = {} |
|
|
|
|
|
|
|
if (!id) { |
|
|
@ -255,15 +256,16 @@ OpenStreetBrowserLoader.prototype.getFullId = function (id, options) { |
|
|
|
return result |
|
|
|
} |
|
|
|
|
|
|
|
OpenStreetBrowserLoader.prototype.forget = function (id) { |
|
|
|
forget (id) { |
|
|
|
var ids = this.getFullId(id, options) |
|
|
|
|
|
|
|
this.categories[ids.fullId].remove() |
|
|
|
delete this.categories[ids.fullId] |
|
|
|
} |
|
|
|
|
|
|
|
OpenStreetBrowserLoader.prototype.registerType = function (type, classObject) { |
|
|
|
registerType (type, classObject) { |
|
|
|
this.types[type] = classObject |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
module.exports = new OpenStreetBrowserLoader() |