aboutsummaryrefslogtreecommitdiffstats
path: root/src/js
diff options
context:
space:
mode:
authorJakub Hampl <kopomir@gmail.com>2018-06-21 15:49:00 +0100
committerJakub Hampl <kopomir@gmail.com>2018-06-21 15:49:00 +0100
commit5b7ca1d3a6b608b1c31d6b06096771a1585bcbc8 (patch)
tree30dc4d82d2ad9df9ce62da24f845fdc406171c3d /src/js
parentebed6c06da9efa5b21a45432dfab7f2611b3882a (diff)
Add Mapbox 0.46 compatibility and features
Diffstat (limited to 'src/js')
-rw-r--r--src/js/main.js48
1 files changed, 47 insertions, 1 deletions
diff --git a/src/js/main.js b/src/js/main.js
index d105d3e..b1ec6fb 100644
--- a/src/js/main.js
+++ b/src/js/main.js
@@ -103,6 +103,50 @@ function wrapElmApplication(elmApp, settings = {}) {
this._pitch = value;
}
+ get featureState() {
+ return this._featureState;
+ }
+ set featureState(value) {
+ // TODO: Clean this up
+ function makeId({id, source, sourceLayer}) {
+ return `${id}::${source}::${sourceLayer}`;
+ }
+ if (this._map) {
+ const map = new Map(this._featureState.map(([feature, state]) => [makeId(feature), {feature, state}]));
+ value.forEach(([feature, state]) => {
+ const id = makeId(feature);
+ if (map.has(id)) {
+ const prevValue = map.get(id).state;
+ const keys = Object.keys(prevValue);
+ let newValue = {};
+ keys.forEach(k => {
+ if (state[k] === undefined) {
+ newValue[k] = undefined;
+ }
+ });
+ this._map.setFeatureState(
+ feature,
+ Object.assign(newValue, state)
+ );
+ } else {
+ this._map.setFeatureState(feature, state);
+ }
+ map.delete(id);
+ });
+
+ map.forEach(({feature, state}) => {
+ const keys = Object.keys(state);
+ let newValue = {};
+ keys.forEach(k => {
+ newValue[k] = undefined;
+ });
+ this._map.setFeatureState(feature, newValue);
+ });
+ }
+
+ this._featureState = value;
+ }
+
addEventListener(type, fn, ...args) {
if (this._map) {
var wrapped;
@@ -236,7 +280,9 @@ function wrapElmApplication(elmApp, settings = {}) {
if (elmApp.ports && elmApp.ports.elmMapboxOutgoing) {
function processOptions(opts) {
if (opts.easing) {
- return Object.assign({}, opts, {easing: options.easingFunctions[opts.easing]});
+ return Object.assign({}, opts, {
+ easing: options.easingFunctions[opts.easing]
+ });
}
return opts;
}