2016-09-08 21:42:18 +02:00
|
|
|
import React from 'react';
|
|
|
|
|
2016-09-09 15:49:23 +02:00
|
|
|
// 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;
|
2016-09-08 21:42:18 +02:00
|
|
|
}
|
2016-09-09 00:10:54 +02:00
|
|
|
|
2016-09-09 15:49:23 +02:00
|
|
|
onStyleChange(cb) {
|
|
|
|
this.subscribers.push(cb);
|
2016-09-08 21:42:18 +02:00
|
|
|
}
|
|
|
|
|
2016-09-09 15:49:23 +02:00
|
|
|
changeStyle(command) {
|
|
|
|
this.commandHistory.push(command)
|
|
|
|
this.subscribers.forEach(f => f(command))
|
|
|
|
console.log(command)
|
2016-09-08 21:42:18 +02:00
|
|
|
}
|
|
|
|
|
2016-09-09 16:58:48 +02:00
|
|
|
exportStyle() {
|
|
|
|
return JSON.stringify(this.mapStyle, null, 4)
|
|
|
|
}
|
|
|
|
|
2016-09-09 15:49:23 +02:00
|
|
|
layer(layerId) {
|
|
|
|
console.log(this.mapStyle)
|
|
|
|
return this.mapStyle.layers[layerId]
|
2016-09-08 21:42:18 +02:00
|
|
|
}
|
|
|
|
|
2016-09-09 00:10:54 +02:00
|
|
|
layers() {
|
2016-09-09 15:49:23 +02:00
|
|
|
if(this.mapStyle) return this.mapStyle.layers
|
|
|
|
return []
|
2016-09-08 21:42:18 +02:00
|
|
|
}
|
|
|
|
}
|