2016-09-08 21:42:18 +02:00
|
|
|
import React from 'react';
|
2016-09-10 21:29:18 +02:00
|
|
|
import spec from 'mapbox-gl-style-spec/reference/latest.min.js'
|
2016-09-09 18:53:57 +02:00
|
|
|
|
2016-12-16 14:49:25 +01:00
|
|
|
// Empty style is always used if no style could be restored or fetched
|
2016-12-20 16:08:49 +01:00
|
|
|
const emptyStyle = ensureMetadataExists({
|
2016-12-16 14:49:25 +01:00
|
|
|
version: 8,
|
|
|
|
sources: {},
|
|
|
|
layers: [],
|
2016-12-20 16:08:49 +01:00
|
|
|
})
|
2016-12-16 14:49:25 +01:00
|
|
|
|
2016-09-20 16:49:02 +02:00
|
|
|
function ensureHasId(style) {
|
2016-12-20 16:08:49 +01:00
|
|
|
if('id' in style) return style
|
|
|
|
style.id = Math.random().toString(36).substr(2, 9)
|
|
|
|
return style
|
2016-09-20 16:49:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function ensureHasTimestamp(style) {
|
2016-12-20 16:08:49 +01:00
|
|
|
if('created' in style) return style
|
|
|
|
style.created = new Date().toJSON()
|
|
|
|
return style
|
2016-09-20 16:49:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function ensureMetadataExists(style) {
|
2016-12-16 14:49:25 +01:00
|
|
|
return ensureHasId(ensureHasTimestamp(style))
|
2016-09-20 16:49:02 +02:00
|
|
|
}
|
|
|
|
|
2016-09-10 21:29:18 +02:00
|
|
|
export default {
|
2016-12-16 14:49:25 +01:00
|
|
|
ensureMetadataExists,
|
|
|
|
emptyStyle,
|
2016-09-10 21:29:18 +02:00
|
|
|
}
|