maputnik/src/libs/style.js

31 lines
664 B
JavaScript
Raw Normal View History

2016-09-08 21:42:18 +02:00
import React from 'react';
import spec from 'mapbox-gl-style-spec/reference/latest.min.js'
2016-09-09 18:53:57 +02: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({
version: 8,
sources: {},
layers: [],
2016-12-20 16:08:49 +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) {
return ensureHasId(ensureHasTimestamp(style))
2016-09-20 16:49:02 +02:00
}
export default {
ensureMetadataExists,
emptyStyle,
}