@@ -17,27 +17,40 @@ function ScatterMapbox(mapbox, uid) {
17
17
this . map = mapbox . map ;
18
18
19
19
this . uid = uid ;
20
- this . idSourceMarkers = uid + '-source-markers' ;
20
+
21
+ this . idSourceFill = uid + '-source-fill' ;
21
22
this . idSourceLines = uid + '-source-lines' ;
22
- this . idLayerMarkers = uid + '-layer-markers' ;
23
+ this . idSourceMarkers = uid + '-source-markers' ;
24
+
25
+ this . idLayerFill = uid + '-layer-fill' ;
23
26
this . idLayerLines = uid + '-layer-lines' ;
27
+ this . idLayerMarkers = uid + '-layer-markers' ;
28
+
29
+ this . sourceFill = mapbox . createGeoJSONSource ( ) ;
30
+ this . map . addSource ( this . idSourceFill , this . sourceFill ) ;
24
31
25
32
this . sourceLines = mapbox . createGeoJSONSource ( ) ;
26
33
this . map . addSource ( this . idSourceLines , this . sourceLines ) ;
34
+
35
+ this . sourceMarkers = mapbox . createGeoJSONSource ( ) ;
36
+ this . map . addSource ( this . idSourceMarkers , this . sourceMarkers ) ;
37
+
38
+ this . map . addLayer ( {
39
+ id : this . idLayerFill ,
40
+ source : this . idSourceFill ,
41
+ type : 'fill'
42
+ } ) ;
43
+
27
44
this . map . addLayer ( {
28
45
id : this . idLayerLines ,
29
46
source : this . idSourceLines ,
30
- type : 'line' ,
31
- interactive : true
47
+ type : 'line'
32
48
} ) ;
33
49
34
- this . sourceMarkers = mapbox . createGeoJSONSource ( ) ;
35
- this . map . addSource ( this . idSourceMarkers , this . sourceMarkers ) ;
36
50
this . map . addLayer ( {
37
51
id : this . idLayerMarkers ,
38
52
source : this . idSourceMarkers ,
39
- type : 'circle' ,
40
- interactive : true
53
+ type : 'circle'
41
54
} ) ;
42
55
43
56
// how to add 'symbol' layer ???
@@ -49,29 +62,38 @@ function ScatterMapbox(mapbox, uid) {
49
62
var proto = ScatterMapbox . prototype ;
50
63
51
64
proto . update = function update ( trace ) {
52
- var opts = convert ( trace ) ;
65
+ var map = this . map ,
66
+ opts = convert ( trace ) ;
53
67
54
- setOptions ( this . map , this . idLayerLines , 'setLayoutProperty' , opts . layoutLines ) ;
55
- setOptions ( this . map , this . idLayerMarkers , 'setLayoutProperty' , opts . layoutMarkers ) ;
68
+ setOptions ( map , this . idLayerFill , 'setLayoutProperty' , opts . fill . layout ) ;
69
+ setOptions ( map , this . idLayerLines , 'setLayoutProperty' , opts . lines . layout ) ;
70
+ setOptions ( map , this . idLayerMarkers , 'setLayoutProperty' , opts . markers . layout ) ;
56
71
57
- if ( opts . layoutLines . visibility === 'visible' ) {
58
- this . sourceLines . setData ( opts . geojsonLines ) ;
59
- setOptions ( this . map , this . idLayerLines , 'setPaintProperty' , opts . paintLines ) ;
72
+ if ( isVisible ( opts . fill ) ) {
73
+ this . sourceFill . setData ( opts . fill . geojson ) ;
74
+ setOptions ( map , this . idLayerFill , 'setPaintProperty' , opts . fill . paint ) ;
60
75
}
61
76
62
- if ( opts . layoutMarkers . visibility === 'visible' ) {
63
- this . sourceMarkers . setData ( opts . geojsonMarkers ) ;
64
- setOptions ( this . map , this . idLayerMarkers , 'setPaintProperty' , opts . paintMarkers ) ;
77
+ if ( isVisible ( opts . lines ) ) {
78
+ this . sourceLines . setData ( opts . lines . geojson ) ;
79
+ setOptions ( map , this . idLayerLines , 'setPaintProperty' , opts . lines . paint ) ;
80
+ }
81
+
82
+ if ( isVisible ( opts . markers ) ) {
83
+ this . sourceMarkers . setData ( opts . markers . geojson ) ;
84
+ setOptions ( map , this . idLayerMarkers , 'setPaintProperty' , opts . markers . paint ) ;
65
85
}
66
86
} ;
67
87
68
88
proto . dispose = function dispose ( ) {
69
89
var map = this . map ;
70
90
71
- map . removeLayer ( this . idLayerMarkers ) ;
72
- map . removeSource ( this . idSourceMarkers ) ;
91
+ map . removeLayer ( this . idLayerFill ) ;
73
92
map . removeLayer ( this . idLayerLines ) ;
93
+ map . removeLayer ( this . idLayerMarkers ) ;
94
+
74
95
map . removeSource ( this . idSourceLines ) ;
96
+ map . removeSource ( this . idSourceMarkers ) ;
75
97
} ;
76
98
77
99
function setOptions ( map , id , methodName , opts ) {
@@ -84,6 +106,10 @@ function setOptions(map, id, methodName, opts) {
84
106
}
85
107
}
86
108
109
+ function isVisible ( layerOpts ) {
110
+ return layerOpts . layout . visibility === 'visible' ;
111
+ }
112
+
87
113
module . exports = function createScatterMapbox ( mapbox , trace ) {
88
114
var scatterMapbox = new ScatterMapbox ( mapbox , trace . uid ) ;
89
115
scatterMapbox . update ( trace ) ;
0 commit comments