mirror of
https://github.com/maputnik/editor.git
synced 2026-06-15 03:37:27 +00:00
Open style from url #34
This commit is contained in:
+2
-12
@@ -1,5 +1,6 @@
|
||||
import { colorizeLayers } from './style.js'
|
||||
import style from './style.js'
|
||||
import { loadStyleUrl } from './urlopen'
|
||||
import publicSources from '../config/styles.json'
|
||||
import request from 'request'
|
||||
|
||||
@@ -14,18 +15,7 @@ const defaultStyleUrl = publicSources[0].url
|
||||
|
||||
// Fetch a default style via URL and return it or a fallback style via callback
|
||||
export function loadDefaultStyle(cb) {
|
||||
console.log('Falling back to default style')
|
||||
request({
|
||||
url: defaultStyleUrl,
|
||||
withCredentials: false,
|
||||
}, (error, response, body) => {
|
||||
if (!error && response.statusCode == 200) {
|
||||
cb(style.ensureStyleValidity(JSON.parse(body)))
|
||||
} else {
|
||||
console.warn('Could not fetch default style', styleUrl)
|
||||
cb(style.emptyStyle)
|
||||
}
|
||||
})
|
||||
loadStyleUrl(defaultStyleUrl, cb)
|
||||
}
|
||||
|
||||
// Return style ids and dates of all styles stored in local storage
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
import request from 'request'
|
||||
import url from 'url'
|
||||
import style from './style.js'
|
||||
|
||||
export function initialStyleUrl() {
|
||||
const initialUrl = url.parse(window.location.href, true)
|
||||
console.log(initialUrl)
|
||||
return (initialUrl.query || {}).style
|
||||
}
|
||||
|
||||
export function loadStyleUrl(styleUrl, cb) {
|
||||
console.log('Loading style', styleUrl)
|
||||
request({
|
||||
url: styleUrl,
|
||||
withCredentials: false,
|
||||
}, (error, response, body) => {
|
||||
if (!error && response.statusCode == 200) {
|
||||
cb(style.ensureStyleValidity(JSON.parse(body)))
|
||||
} else {
|
||||
console.warn('Could not fetch default style', styleUrl)
|
||||
cb(style.emptyStyle)
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user