Browse Source

OpenStreetBrowserLoader: convert to a ES6 class

master
parent
commit
eca9ee447a
  1. 46
      src/OpenStreetBrowserLoader.js

46
src/OpenStreetBrowserLoader.js

@ -2,26 +2,27 @@ var OverpassLayer = require('overpass-layer')
const Repository = require('./Repository')
function OpenStreetBrowserLoader () {
class OpenStreetBrowserLoader {
constructor () {
this.types = {}
this.categories = {}
this.repoCache = {}
this.repositories = {}
this.templates = {}
this._loadClash = {} // if a category is being loaded multiple times, collect callbacks
}
}
OpenStreetBrowserLoader.prototype.setMap = function (map) {
setMap (map) {
this.map = map
}
}
/**
/**
* @param string id ID of the category
* @param [object] options Options.
* @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 = {}
@ -66,15 +67,15 @@ OpenStreetBrowserLoader.prototype.getCategory = function (id, options, callback)
callback(err, category)
}.bind(this))
}.bind(this))
}
}
/**
/**
* @param string repo ID of the repository
* @parapm [object] options Options.
* @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]
}
@ -125,9 +126,9 @@ OpenStreetBrowserLoader.prototype.getRepo = function (repo, options, callback) {
req.addEventListener('load', reqListener.bind(this, req))
req.open('GET', 'repo.php' + param)
req.send()
}
}
OpenStreetBrowserLoader.prototype.getRepository = function (id, options, callback) {
getRepository (id, options, callback) {
if (id in this.repositories) {
return callback(null, this.repositories[id])
}
@ -139,15 +140,15 @@ OpenStreetBrowserLoader.prototype.getRepository = function (id, options, callbac
callback(null, this.repositories[id])
})
}
}
/**
/**
* @param string id ID of the template
* @parapm [object] options Options.
* @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 = {}
@ -185,9 +186,9 @@ OpenStreetBrowserLoader.prototype.getTemplate = function (id, options, callback)
callback(null, this.templates[ids.fullId])
}.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) {
@ -219,9 +220,9 @@ OpenStreetBrowserLoader.prototype.getCategoryFromData = function (id, options, d
} else {
callback(null, layer)
}
}
}
OpenStreetBrowserLoader.prototype.getFullId = function (id, options) {
getFullId (id, options) {
var result = {}
if (!id) {
@ -253,17 +254,18 @@ OpenStreetBrowserLoader.prototype.getFullId = function (id, options) {
result.fullId = result.repositoryId + '/' + (result.sublayerId ? result.sublayerId + ':' : '') + result.entityId
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()
Loading…
Cancel
Save