Browse Source

OpenStreetBrowserLoader: load templates from repositories

master
Stephan Bösch-Plepelits 7 years ago
parent
commit
5dd387921d
  1. 45
      src/OpenStreetBrowserLoader.js

45
src/OpenStreetBrowserLoader.js

@ -120,37 +120,40 @@ OpenStreetBrowserLoader.prototype.getTemplate = function (id, options, callback)
options = {}
}
if (id in this.templates) {
callback.apply(this, this.templates[id])
return
var repo
var templateId
var m
if (m = id.match(/^(.*)\/([^\/]*)/)) {
repo = m[1]
templateId = m[2]
} else {
repo = 'default'
templateId = id
}
if (id in this._loadClash) {
this._loadClash[id].push(callback)
if (id in this.templates) {
callback.apply(this, this.templates[id])
return
}
this._loadClash[id] = []
this.getRepo(repo, options, function (err, repoData) {
// maybe loaded in the meantime?
if (id in this.templates) {
return callback(null, this.templates[id])
}
function reqListener (req) {
if (req.status !== 200) {
console.log(req)
this.templates[id] = [ req.statusText, null ]
} else {
this.templates[id] = [ null, OverpassLayer.twig.twig({ data: req.responseText, autoescape: true }) ]
if (err) {
return callback(err, null)
}
callback.apply(this, this.templates[id])
if (!repoData.templates || !(templateId in repoData.templates)) {
return callback(new Error('template not defined'), null)
}
this._loadClash[id].forEach(function (c) {
c.apply(this, this.templates[id])
}.bind(this))
}
this.templates[id] = OverpassLayer.twig.twig({ data: repoData.templates[templateId], autoescape: true })
var req = new XMLHttpRequest()
req.addEventListener('load', reqListener.bind(this, req))
req.open('GET', config.categoriesDir + '/' + id + '.html?' + config.categoriesRev)
req.send()
callback(null, this.templates[id])
}.bind(this))
}
OpenStreetBrowserLoader.prototype.getCategoryFromData = function (id, data, callback) {

Loading…
Cancel
Save