2016-09-08 21:42:18 +02:00
|
|
|
import React from 'react';
|
|
|
|
|
2016-09-09 00:10:54 +02:00
|
|
|
// A wrapper around Mapbox GL style
|
|
|
|
export class Style {
|
|
|
|
constructor() {
|
|
|
|
this.styleHistory = [];
|
|
|
|
this.renderers = [];
|
2016-09-08 21:42:18 +02:00
|
|
|
}
|
2016-09-09 00:10:54 +02:00
|
|
|
|
|
|
|
load(style) {
|
|
|
|
this.currentStyle = style;
|
2016-09-08 21:42:18 +02:00
|
|
|
}
|
|
|
|
|
2016-09-09 00:10:54 +02:00
|
|
|
onRender(cb) {
|
|
|
|
this.renderers.push(cb);
|
2016-09-08 21:42:18 +02:00
|
|
|
}
|
|
|
|
|
2016-09-09 00:10:54 +02:00
|
|
|
update(style) {
|
|
|
|
this.styleHistory.push(this.currentStyle);
|
|
|
|
this.currentStyle = style;
|
|
|
|
this.renderers.forEach(r => r(this.currentStyle))
|
2016-09-08 21:42:18 +02:00
|
|
|
}
|
|
|
|
|
2016-09-09 00:10:54 +02:00
|
|
|
layers() {
|
|
|
|
return this.currentStyle.layers;
|
2016-09-08 21:42:18 +02:00
|
|
|
}
|
|
|
|
}
|