Pass everything down as props

This commit is contained in:
lukasmartinelli
2016-09-09 23:25:06 +02:00
parent 416cf7e0af
commit b6dff4aa58
8 changed files with 214 additions and 167 deletions
+1 -67
View File
@@ -1,7 +1,7 @@
import React from 'react';
import randomColor from 'randomcolor'
function assignColorsToLayers(layers) {
export function colorizeLayers(layers) {
return layers.map(layer => {
if(!layer.metadata) {
layer.metadata = {}
@@ -12,69 +12,3 @@ function assignColorsToLayers(layers) {
return layer
})
}
// A wrapper around Mapbox GL style to publish
// and subscribe to map changes
export class StyleManager {
constructor(mapStyle) {
this.commandHistory = [];
this.subscribers = [];
this.mapStyle = mapStyle;
if(this.mapStyle) {
this.mapStyle.layers = assignColorsToLayers(this.mapStyle.layers)
}
}
onStyleChange(cb) {
this.subscribers.push(cb);
}
changeStyle(change) {
this.commandHistory.push(change)
this.subscribers.forEach(f => f(change))
console.log(change)
}
exportStyle() {
return JSON.stringify(this.mapStyle, null, 4)
}
settings() {
const { name, sprite, glyphs, owner } = this.mapStyle
return { name, sprite, glyphs, owner }
}
set name(val) {
this.mapStyle.name = val
}
set owner(val) {
this.mapStyle.owner = val
}
set glyphs(val) {
this.mapStyle.glyphs = val
this.changeStyle({
command: 'setStyle',
args: [this.mapStyle]
})
}
set sprite(val) {
this.mapStyle.sprite = val
this.changeStyle({
command: 'setStyle',
args: [this.mapStyle]
})
}
layer(layerId) {
return this.mapStyle.layers[layerId]
}
layers() {
if(this.mapStyle) return this.mapStyle.layers
return []
}
}