File tree 2 files changed +57
-3
lines changed
2 files changed +57
-3
lines changed Original file line number Diff line number Diff line change 6
6
* LICENSE file in the root directory of this source tree.
7
7
*/
8
8
9
-
10
9
'use strict' ;
11
10
12
11
var Lib = require ( '../../lib' ) ;
@@ -52,6 +51,8 @@ function handleLayerDefaults(layerIn, layerOut) {
52
51
var visible = coerce ( 'visible' ) ;
53
52
if ( visible ) {
54
53
var sourceType = coerce ( 'sourcetype' ) ;
54
+ var mustBeRasterLayer = sourceType === 'raster' || sourceType === 'image' ;
55
+
55
56
coerce ( 'source' ) ;
56
57
57
58
if ( sourceType === 'vector' ) {
@@ -62,8 +63,15 @@ function handleLayerDefaults(layerIn, layerOut) {
62
63
coerce ( 'coordinates' ) ;
63
64
}
64
65
65
- // maybe add smart default based off GeoJSON geometry?
66
- var type = coerce ( 'type' ) ;
66
+ var typeDflt ;
67
+ if ( mustBeRasterLayer ) typeDflt = 'raster' ;
68
+
69
+ var type = coerce ( 'type' , typeDflt ) ;
70
+
71
+ if ( mustBeRasterLayer && type !== 'raster' ) {
72
+ type = layerOut . type = 'raster' ;
73
+ Lib . log ( 'Source types *raster* and *image* must drawn *raster* layer type.' ) ;
74
+ }
67
75
68
76
coerce ( 'below' ) ;
69
77
coerce ( 'color' ) ;
Original file line number Diff line number Diff line change @@ -184,6 +184,52 @@ describe('mapbox defaults', function() {
184
184
expect ( layoutOut . mapbox . layers [ 3 ] . circle ) . toBeUndefined ( ) ;
185
185
} ) ;
186
186
187
+ it ( 'should not allow to set layer type other than *raster* for sourcetype value *raster* and *image*' , function ( ) {
188
+ spyOn ( Lib , 'log' ) ;
189
+
190
+ layoutIn = {
191
+ mapbox : {
192
+ layers : [ {
193
+ sourcetype : 'raster' ,
194
+ source : 'url' ,
195
+ type : 'circle'
196
+ } , {
197
+ sourcetype : 'image' ,
198
+ source : 'url' ,
199
+ type : 'fill'
200
+ } ]
201
+ }
202
+ } ;
203
+ supplyLayoutDefaults ( layoutIn , layoutOut , fullData ) ;
204
+
205
+ expect ( Lib . log ) . toHaveBeenCalledTimes ( 2 ) ;
206
+ expect ( Lib . log ) . toHaveBeenCalledWith ( 'Source types *raster* and *image* must drawn *raster* layer type.' ) ;
207
+
208
+ expect ( layoutOut . mapbox . layers [ 0 ] . type ) . toBe ( 'raster' ) ;
209
+ expect ( layoutOut . mapbox . layers [ 1 ] . type ) . toBe ( 'raster' ) ;
210
+ } ) ;
211
+
212
+ it ( 'should default layer with sourcetype *raster* and *image* to type *raster' , function ( ) {
213
+ spyOn ( Lib , 'log' ) ;
214
+
215
+ layoutIn = {
216
+ mapbox : {
217
+ layers : [ {
218
+ sourcetype : 'raster' ,
219
+ source : 'url'
220
+ } , {
221
+ sourcetype : 'image' ,
222
+ source : 'url'
223
+ } ]
224
+ }
225
+ } ;
226
+ supplyLayoutDefaults ( layoutIn , layoutOut , fullData ) ;
227
+
228
+ expect ( Lib . log ) . toHaveBeenCalledTimes ( 0 ) ;
229
+ expect ( layoutOut . mapbox . layers [ 0 ] . type ) . toBe ( 'raster' ) ;
230
+ expect ( layoutOut . mapbox . layers [ 1 ] . type ) . toBe ( 'raster' ) ;
231
+ } ) ;
232
+
187
233
it ( 'should set *layout.dragmode* to pan while zoom is not available' , function ( ) {
188
234
var gd = {
189
235
data : fullData ,
You can’t perform that action at this time.
0 commit comments