Support TileJSON sources for OL3

This commit is contained in:
Lukas Martinelli
2017-01-10 14:24:35 +01:00
parent 104d6311ec
commit 3a3e90c3dc
2 changed files with 76 additions and 26 deletions

View File

@@ -21,3 +21,22 @@ export function loadStyleUrl(styleUrl, cb) {
}
})
}
export 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.error('Can not load JSON from ' + url)
cb(defaultValue)
}
})
}