Browse Source

Prepare passing options to Categories

master
Stephan Bösch-Plepelits 7 years ago
parent
commit
2b3bfb0af7
  1. 11
      src/CategoryBase.js
  2. 8
      src/CategoryIndex.js
  3. 8
      src/CategoryOverpass.js
  4. 43
      src/OpenStreetBrowserLoader.js

11
src/CategoryBase.js

@ -2,8 +2,15 @@
var OpenStreetBrowserLoader = require('./OpenStreetBrowserLoader')
var tabs = require('modulekit-tabs')
function CategoryBase (id, data) {
this.id = id
function CategoryBase (options, data) {
if (typeof options === 'string') {
this.id = options
this.options = {}
}
else {
this.id = options.id
this.options = options
}
this.parentCategory = null
this.childrenLoadingCount = 0
this.data = data

8
src/CategoryIndex.js

@ -5,8 +5,8 @@ var CategoryBase = require('./CategoryBase')
CategoryIndex.prototype = Object.create(CategoryBase.prototype)
CategoryIndex.prototype.constructor = CategoryIndex
function CategoryIndex (id, data) {
CategoryBase.call(this, id, data)
function CategoryIndex (options, data) {
CategoryBase.call(this, options, data)
this.childrenDoms = {}
this.childrenCategories = null
@ -51,9 +51,9 @@ CategoryIndex.prototype._loadChildrenCategories = function (callback) {
this.childrenCategories[data.id] = null
if ('type' in data) {
OpenStreetBrowserLoader.getCategoryFromData(data.id, data, this._loadChildCategory.bind(this, callback))
OpenStreetBrowserLoader.getCategoryFromData(data.id, this.options, data, this._loadChildCategory.bind(this, callback))
} else {
OpenStreetBrowserLoader.getCategory(data.id, this._loadChildCategory.bind(this, callback))
OpenStreetBrowserLoader.getCategory(data.id, this.options, this._loadChildCategory.bind(this, callback))
}
}.bind(this),
function (err) {

8
src/CategoryOverpass.js

@ -26,10 +26,10 @@ var defaultValues = {
CategoryOverpass.prototype = Object.create(CategoryBase.prototype)
CategoryOverpass.prototype.constructor = CategoryOverpass
function CategoryOverpass (id, data) {
function CategoryOverpass (options, data) {
var p
CategoryBase.call(this, id, data)
CategoryBase.call(this, options, data)
data.id = this.id
@ -155,7 +155,7 @@ function CategoryOverpass (id, data) {
}
CategoryOverpass.prototype.load = function (callback) {
OpenStreetBrowserLoader.getTemplate('popupBody', function (err, template) {
OpenStreetBrowserLoader.getTemplate('popupBody', this.options, function (err, template) {
if (err) {
console.log("can't load popupBody.html")
} else {
@ -323,7 +323,7 @@ CategoryOverpass.prototype.updatePopupContent = function (object, popup) {
}
CategoryOverpass.prototype.renderTemplate = function (object, templateId, callback) {
OpenStreetBrowserLoader.getTemplate(templateId, function (err, template) {
OpenStreetBrowserLoader.getTemplate(templateId, this.options, function (err, template) {
if (err) {
err = "can't load " + templateId + ': ' + err
return callback(err, null)

43
src/OpenStreetBrowserLoader.js

@ -31,18 +31,23 @@ OpenStreetBrowserLoader.prototype.getCategory = function (id, options, callback)
repo = m[1]
categoryId = m[2]
} else {
repo = 'default'
repo = options.repositoryId || 'default'
categoryId = id
}
var fullId = repo + '/' + categoryId
if (id in this.categories) {
return callback(null, this.categories[id])
if (fullId in this.categories) {
return callback(null, this.categories[fullId])
}
this.getRepo(repo, options, function (err, repoData) {
var opt = JSON.parse(JSON.stringify(options))
opt.categoryId = categoryId
opt.repositoryId = repo
this.getRepo(repo, opt, function (err, repoData) {
// maybe loaded in the meantime?
if (id in this.categories) {
return callback(null, this.categories[id])
if (fullId in this.categories) {
return callback(null, this.categories[fullId])
}
if (err) {
@ -53,7 +58,7 @@ OpenStreetBrowserLoader.prototype.getCategory = function (id, options, callback)
return callback(new Error('category not defined'), null)
}
this.getCategoryFromData(id, repoData.categories[categoryId], function (err, category) {
this.getCategoryFromData(id, opt, repoData.categories[categoryId], function (err, category) {
if (category) {
category.setMap(this.map)
}
@ -127,19 +132,23 @@ OpenStreetBrowserLoader.prototype.getTemplate = function (id, options, callback)
repo = m[1]
templateId = m[2]
} else {
repo = 'default'
repo = options.repositoryId || 'default'
templateId = id
}
var fullId = repo + '/' + templateId
if (id in this.templates) {
callback.apply(this, this.templates[id])
return
if (fullId in this.templates) {
return callback(null, this.templates[fullId])
}
this.getRepo(repo, options, function (err, repoData) {
var opt = JSON.parse(JSON.stringify(options))
opt.templateId = templateId
opt.repositoryId = repo
this.getRepo(repo, opt, function (err, repoData) {
// maybe loaded in the meantime?
if (id in this.templates) {
return callback(null, this.templates[id])
if (fullId in this.templates) {
return callback(null, this.templates[fullId])
}
if (err) {
@ -156,7 +165,7 @@ OpenStreetBrowserLoader.prototype.getTemplate = function (id, options, callback)
}.bind(this))
}
OpenStreetBrowserLoader.prototype.getCategoryFromData = function (id, data, callback) {
OpenStreetBrowserLoader.prototype.getCategoryFromData = function (id, options, data, callback) {
if (id in this.categories) {
callback(null, this.categories[id])
return
@ -170,7 +179,9 @@ OpenStreetBrowserLoader.prototype.getCategoryFromData = function (id, data, call
return callback(new Error('unknown type'), null)
}
var layer = new this.types[data.type](id, data)
var opt = JSON.parse(JSON.stringify(options))
opt.id = id
var layer = new this.types[data.type](opt, data)
layer.setMap(this.map)

Loading…
Cancel
Save