1010'use strict' ;
1111
1212var Lib = require ( '../../lib' ) ;
13+ var convertTextOpts = require ( './convert_text_opts' ) ;
1314
1415
1516function MapboxLayer ( mapbox , index ) {
@@ -46,14 +47,17 @@ proto.update = function update(opts) {
4647
4748proto . needsNewSource = function ( opts ) {
4849
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' ) ;
5255
5356 return (
5457 this . sourceType !== opts . sourcetype ||
5558 this . source !== opts . source ||
56- changesToFill
59+ changesToFill ||
60+ changesToSymbol
5761 ) ;
5862} ;
5963
@@ -101,10 +105,11 @@ proto.updateLayer = function(opts) {
101105} ;
102106
103107proto . updateStyle = function ( opts ) {
104- var paintOpts = convertPaintOpts ( opts ) ;
108+ var convertedOpts = convertOpts ( opts ) ;
105109
106110 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 ) ;
108113 }
109114} ;
110115
@@ -127,42 +132,63 @@ function isVisible(opts) {
127132 ) ;
128133}
129134
130- function convertPaintOpts ( opts ) {
131- var paintOpts = { } ;
135+ function convertOpts ( opts ) {
136+ var layout = { } ,
137+ paint = { } ;
132138
133139 switch ( opts . type ) {
134140
135141 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 ,
140145 'circle-opacity' : opts . opacity
141146 } ) ;
142147 break ;
143148
144149 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 ,
149153 'line-opacity' : opts . opacity
150154 } ) ;
151155 break ;
152156
153157 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 ,
158161 'fill-opacity' : opts . opacity
159162
160163 // no way to pass specify outline width at the moment
161164 } ) ;
162165 break ;
166+
167+ case 'symbol' :
168+ var symbol = opts . symbol ,
169+ textOpts = convertTextOpts ( symbol . textposition , symbol . iconsize ) ;
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 ;
163189 }
164190
165- return paintOpts ;
191+ return { layout : layout , paint : paint } ;
166192}
167193
168194function convertSourceOpts ( opts ) {
0 commit comments