Skip to content

Commit

Permalink
Merge pull request #31 from openearth/Fix-mapboxlayers-array
Browse files Browse the repository at this point in the history
Fix mapboxlayers array
  • Loading branch information
avgils authored Aug 12, 2019
2 parents 7b98d32 + 1d452e8 commit 9b6921f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 202 deletions.
183 changes: 0 additions & 183 deletions api-mock/datasets-old.json

This file was deleted.

14 changes: 7 additions & 7 deletions api-mock/datasets.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"timeSpan": "Live",
"units": "N/A",
"vectorLayer": {
"mapboxLayer": [{
"mapboxLayers": [{
"filterIds": [
"Alert.level"
],
Expand Down Expand Up @@ -61,7 +61,7 @@
"timeSpan": "Live",
"units": "m",
"vectorLayer": {
"mapboxLayer": [{
"mapboxLayers": [{
"filterIds": [
"H.simulated"
],
Expand Down Expand Up @@ -91,7 +91,7 @@
"timeSpan": "Live",
"units": "m",
"vectorLayer": {
"mapboxLayer": [{
"mapboxLayers": [{
"filterIds": [
"H.surge.simulated"
],
Expand Down Expand Up @@ -121,7 +121,7 @@
"timeSpan": "Live",
"units": "m",
"vectorLayer": {
"mapboxLayer": [{
"mapboxLayers": [{
"filterIds": [
"H.astronomical.simulated"
],
Expand Down Expand Up @@ -150,7 +150,7 @@
"timeSpan": "Live",
"units": "m/s",
"vectorLayer": {
"mapboxLayer": [{
"mapboxLayers": [{
"filterIds": [
"Wind.speed",
"Wind.direction"
Expand Down Expand Up @@ -181,7 +181,7 @@
"timeSpan": "Live",
"units": "m",
"vectorLayer": {
"mapboxLayer": [{
"mapboxLayers": [{
"filterIds": [
"H.simulated"
],
Expand All @@ -205,7 +205,7 @@
"timeSpan": "Historic",
"units": "m",
"vectorLayer": {
"mapboxLayer": [
"mapboxLayers": [
{
"id": "shoreline-aggregatedpointsz0",
"type": "circle",
Expand Down
21 changes: 12 additions & 9 deletions components/v-mapbox-components/v-mapbox-vector-layer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,7 @@ export default {
watch: {
layers: {
handler(newValue) {
newValue.forEach((newLayer, index) => {
if (this.map.getLayer(this.layers[index].id)) {
this.map.setFilter(this.layers[index].id, newLayer.filter)
} else {
this.addToMap()
}
})
this.updateMap()
},
deep: true,
},
Expand All @@ -43,7 +37,7 @@ export default {
created() {
this.map = this.getMap()
if (this.map.loaded()) {
this.addToMap()
this.updateMap()
}
},
beforeDestroy() {
Expand All @@ -56,7 +50,16 @@ export default {
},
methods: {
deferredMountedTo(map) {
this.addToMap()
this.updateMap()
},
updateMap() {
this.layers.forEach((newLayer, index) => {
if (this.map.getLayer(this.layers[index].id)) {
this.map.setFilter(this.layers[index].id, newLayer.filter)
} else {
this.addToMap()
}
})
},
addToMap() {
this.layers.forEach(layer => {
Expand Down
2 changes: 1 addition & 1 deletion store/map/datasets.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const mutations = {

// TODO: make generic by looping over vectorLayer
const mergedVector = _.merge(
{ mapboxLayer: _.get(data, 'vectorLayer.mapboxLayer') },
{ mapboxLayer: _.get(data, 'vectorLayer.mapboxLayers') },
vectorData,
)
Vue.set(state[id], 'vector', mergedVector)
Expand Down
4 changes: 2 additions & 2 deletions test/unit/store/map/datasets/mutations.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { mutations } from '../../../../../store/map/datasets'
describe('addDatasetVector', () => {
test('updates state with payload', () => {
const state = { wl: { metadata: 'foo' } }
const data = { id: 'wl', vectorLayer: { mapboxLayer: 'bar' } }
const data = { id: 'wl', vectorLayer: { mapboxLayers: 'bar' } }

mutations.addDatasetVector(state, data)
expect(state).toMatchObject({
Expand Down Expand Up @@ -71,7 +71,7 @@ describe('addDatasetVector', () => {
},
}

const data = { id: 'wd', vectorLayer: { mapboxLayer: { bar: 'foo' } } }
const data = { id: 'wd', vectorLayer: { mapboxLayers: { bar: 'foo' } } }

mutations.addDatasetVector(state, data)
expect(state).toMatchObject({
Expand Down

0 comments on commit 9b6921f

Please sign in to comment.