11/* eslint-disable react/react-in-jsx-scope */
22
3- import { storiesOf , addDecorator } from '@storybook/vue' ;
4- import { action } from '@storybook/addon-actions' ;
5- import { withKnobs , text , number , boolean , array , select , color , date , button } from '@storybook/addon-knobs' ;
6- import { linkTo } from '@storybook/addon-links' ;
3+ import { storiesOf } from '@storybook/vue' ;
4+ import { withKnobs , button } from '@storybook/addon-knobs' ;
75
86import 'mapbox-gl/dist/mapbox-gl.css'
97// needed for the v-mapbox-geocoder
@@ -32,7 +30,6 @@ const zoomTemplate = `
3230/>
3331`
3432
35-
3633const navigationTemplate = `
3734<v-mapbox
3835 map-style="mapbox://styles/mapbox/satellite-streets-v10"
@@ -88,7 +85,6 @@ const canvasTemplate = `
8885</div>
8986`
9087
91-
9288const injectTemplate = `
9389<v-mapbox
9490 map-style="mapbox://styles/mapbox/satellite-streets-v10"
@@ -128,6 +124,7 @@ const layerA = {
128124 'fill-opacity' : 1
129125 }
130126}
127+
131128const layerB = {
132129 'id' : 'b' ,
133130 'type' : 'fill' ,
@@ -166,7 +163,17 @@ const sortingTemplate = `
166163 <!-- green (we want this on top) -->
167164 <v-mapbox-layer :options="layerA"></v-mapbox-layer>
168165 <!-- red -->
169- <v-mapbox-layer before="a" :options="layerB"></v-mapbox-layer>
166+ <v-mapbox-layer :options="layerB"></v-mapbox-layer>
167+ </v-mapbox>
168+ `
169+
170+ const dynamicLayersTemplate = `
171+ <v-mapbox
172+ :map-style="style"
173+ access-token="pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4NXVycTA2emYycXBndHRqcmZ3N3gifQ.rJcFIG214AriISLbB6B5aw"
174+ style="height: 300px;"
175+ >
176+ <v-mapbox-layer v-for="layer in layers" :options="layer" :key="layer.id" />
170177</v-mapbox>
171178`
172179
@@ -177,13 +184,10 @@ const styleAndLayerTemplate = `
177184 style="height: 300px;"
178185 :center="[0, 0]"
179186>
180- <!-- green (we want this on top) -->
181- <v-mapbox-layer :options="layerA"></v-mapbox-layer>
187+ <v-mapbox-layer :options="layerA"></v-mapbox-layer>
182188</v-mapbox>
183189`
184190
185-
186-
187191storiesOf ( 'Map' , module )
188192 . add ( 'map' , ( ) => {
189193 return {
@@ -200,7 +204,7 @@ storiesOf('Map', module)
200204 } ,
201205 template : zoomTemplate ,
202206 mounted ( ) {
203- button ( 'random center' , ( ) => {
207+ button ( 'random center' , ( ) => {
204208 this . center = [ Math . random ( ) * 50 , Math . random ( ) * 50 ]
205209 } )
206210 }
@@ -225,7 +229,6 @@ storiesOf('Map', module)
225229 map . setPaintProperty ( 'a' , 'fill-opacity' , opacity )
226230 } )
227231 button ( 'toggle visibility' , ( ) => {
228- let opacity = Math . random ( )
229232 let visibility = map . getLayoutProperty ( 'a' , 'visibility' )
230233 if ( visibility === 'visible' ) {
231234 visibility = 'none'
@@ -237,6 +240,7 @@ storiesOf('Map', module)
237240 }
238241 }
239242 } )
243+
240244 . add ( 'map with navigation control' , ( ) => {
241245 return {
242246 template : navigationTemplate
@@ -330,6 +334,7 @@ storiesOf('Map', module)
330334 }
331335 }
332336 } )
337+
333338 . add ( 'layer order' , ( ) => {
334339 return {
335340 template : sortingTemplate ,
@@ -342,6 +347,33 @@ storiesOf('Map', module)
342347 } ,
343348 }
344349 } )
350+
351+ . add ( 'add and remove layers' , ( ) => {
352+ return {
353+ template : dynamicLayersTemplate ,
354+ data : ( ) => ( {
355+ style : 'mapbox://styles/global-data-viewer/cjtss3jfb05w71fmra13u4qqm' ,
356+ layers : [ ]
357+ } ) ,
358+ mounted ( ) {
359+ button ( 'Toggle layer A' , this . toggleLayerA ) ,
360+ button ( 'Toggle layer B' , this . toggleLayerB )
361+ } ,
362+ methods : {
363+ toggleLayerA ( ) {
364+ const hasLayerA = this . layers . some ( ( { id } ) => id === 'a' ) ;
365+ if ( hasLayerA ) this . layers = this . layers . filter ( ( { id } ) => id !== 'a' ) ;
366+ else this . layers = [ ...this . layers , layerA ] ;
367+ } ,
368+ toggleLayerB ( ) {
369+ const hasLayerB = this . layers . some ( ( { id } ) => id === 'b' ) ;
370+ if ( hasLayerB ) this . layers = this . layers . filter ( ( { id } ) => id !== 'b' ) ;
371+ else this . layers = [ ...this . layers , layerB ] ;
372+ }
373+ }
374+ }
375+ } )
376+
345377 . add ( 'preserve drawing buffer order' , ( ) => {
346378 return {
347379 template : canvasTemplate ,
0 commit comments