10
10
'use strict' ;
11
11
12
12
var Lib = require ( '../../lib' ) ;
13
+ var convertTextOpts = require ( './convert_text_opts' ) ;
13
14
14
15
15
16
function MapboxLayer ( mapbox , index ) {
@@ -46,14 +47,17 @@ proto.update = function update(opts) {
46
47
47
48
proto . needsNewSource = function ( opts ) {
48
49
49
- // for some reason changing layer to 'fill' w/o changing the source
50
- // throws an exception in mapbox-gl 0.18
51
- var changesToFill = ( this . layerType !== 'fill' && opts . type === 'fill' ) ;
50
+ // for some reason changing layer to 'fill' or 'symbol'
51
+ // w/o changing the source throws an exception in mapbox-gl 0.18
52
+
53
+ var changesToFill = ( this . layerType !== 'fill' && opts . type === 'fill' ) ,
54
+ changesToSymbol = ( this . layerType !== 'symbol' && opts . type === 'symbol' ) ;
52
55
53
56
return (
54
57
this . sourceType !== opts . sourcetype ||
55
58
this . source !== opts . source ||
56
- changesToFill
59
+ changesToFill ||
60
+ changesToSymbol
57
61
) ;
58
62
} ;
59
63
@@ -101,10 +105,11 @@ proto.updateLayer = function(opts) {
101
105
} ;
102
106
103
107
proto . updateStyle = function ( opts ) {
104
- var paintOpts = convertPaintOpts ( opts ) ;
108
+ var convertedOpts = convertOpts ( opts ) ;
105
109
106
110
if ( isVisible ( opts ) ) {
107
- this . mapbox . setOptions ( this . idLayer , 'setPaintProperty' , paintOpts ) ;
111
+ this . mapbox . setOptions ( this . idLayer , 'setLayoutProperty' , convertedOpts . layout ) ;
112
+ this . mapbox . setOptions ( this . idLayer , 'setPaintProperty' , convertedOpts . paint ) ;
108
113
}
109
114
} ;
110
115
@@ -127,42 +132,63 @@ function isVisible(opts) {
127
132
) ;
128
133
}
129
134
130
- function convertPaintOpts ( opts ) {
131
- var paintOpts = { } ;
135
+ function convertOpts ( opts ) {
136
+ var layout = { } ,
137
+ paint = { } ;
132
138
133
139
switch ( opts . type ) {
134
140
135
141
case 'circle' :
136
- var circle = opts . circle ;
137
- Lib . extendFlat ( paintOpts , {
138
- 'circle-radius' : circle . radius ,
139
- 'circle-color' : circle . color ,
142
+ Lib . extendFlat ( paint , {
143
+ 'circle-radius' : opts . circle . radius ,
144
+ 'circle-color' : opts . color ,
140
145
'circle-opacity' : opts . opacity
141
146
} ) ;
142
147
break ;
143
148
144
149
case 'line' :
145
- var line = opts . line ;
146
- Lib . extendFlat ( paintOpts , {
147
- 'line-width' : line . width ,
148
- 'line-color' : line . color ,
150
+ Lib . extendFlat ( paint , {
151
+ 'line-width' : opts . line . width ,
152
+ 'line-color' : opts . color ,
149
153
'line-opacity' : opts . opacity
150
154
} ) ;
151
155
break ;
152
156
153
157
case 'fill' :
154
- var fill = opts . fill ;
155
- Lib . extendFlat ( paintOpts , {
156
- 'fill-color' : fill . color ,
157
- 'fill-outline-color' : fill . outlinecolor ,
158
+ Lib . extendFlat ( paint , {
159
+ 'fill-color' : opts . color ,
160
+ 'fill-outline-color' : opts . fill . outlinecolor ,
158
161
'fill-opacity' : opts . opacity
159
162
160
163
// no way to pass specify outline width at the moment
161
164
} ) ;
162
165
break ;
166
+
167
+ case 'symbol' :
168
+ var symbol = opts . symbol ,
169
+ textOpts = convertTextOpts ( symbol . textposition , symbol . size ) ;
170
+
171
+ Lib . extendFlat ( layout , {
172
+ 'icon-image' : symbol . icon + '-15' ,
173
+ 'icon-size' : symbol . iconsize / 10 ,
174
+
175
+ 'text-field' : symbol . text ,
176
+ 'text-size' : symbol . textfont . size ,
177
+ 'text-anchor' : textOpts . anchor ,
178
+ 'text-offset' : textOpts . offset
179
+
180
+ // TODO font family
181
+ //'text-font': symbol.textfont.family.split(', '),
182
+ } ) ;
183
+
184
+ Lib . extendFlat ( paint , {
185
+ 'text-color' : symbol . textfont . color ,
186
+ 'text-opacity' : opts . opacity
187
+ } ) ;
188
+ break ;
163
189
}
164
190
165
- return paintOpts ;
191
+ return { layout : layout , paint : paint } ;
166
192
}
167
193
168
194
function convertSourceOpts ( opts ) {
0 commit comments