mirror of
https://github.com/a-nyx/maputnik-with-pmtiles.git
synced 2024-12-28 01:55:28 +01:00
Add missing metadata lib
This commit is contained in:
parent
b470885263
commit
f5256cf80a
1 changed files with 32 additions and 0 deletions
32
src/libs/metadata.js
Normal file
32
src/libs/metadata.js
Normal file
|
@ -0,0 +1,32 @@
|
|||
import request from 'request'
|
||||
|
||||
function loadJSON(url, defaultValue, cb) {
|
||||
request({
|
||||
url: url,
|
||||
withCredentials: false,
|
||||
}, (error, response, body) => {
|
||||
if (!error && body && response.statusCode == 200) {
|
||||
try {
|
||||
cb(JSON.parse(body))
|
||||
} catch(err) {
|
||||
console.error(err)
|
||||
cb(defaultValue)
|
||||
}
|
||||
} else {
|
||||
console.warn('Can not metadata for ' + url)
|
||||
cb(defaultValue)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export function downloadGlyphsMetadata(urlTemplate, cb) {
|
||||
if(!urlTemplate) return cb([])
|
||||
const url = urlTemplate.replace('{fontstack}/{range}.pbf', 'fontstacks.json')
|
||||
loadJSON(url, [], cb)
|
||||
}
|
||||
|
||||
export function downloadSpriteMetadata(baseUrl, cb) {
|
||||
if(!baseUrl) return cb([])
|
||||
const url = baseUrl + '.json'
|
||||
loadJSON(url, {}, glyphs => cb(Object.keys(glyphs)))
|
||||
}
|
Loading…
Reference in a new issue