@@ -3,7 +3,7 @@ import { LayerCommon } from '../mapbox.common';
3
3
4
4
export class LayerFactory {
5
5
static async createLayer ( style , source ) : Promise < LayerCommon > {
6
- const layerProperties = this . parseProperties ( style . type , Object . assign ( style . paint , style . layout ) ) ; // TODO: handle defaults
6
+ const layerProperties = this . parseProperties ( style . type , Object . assign ( style . paint || { } , style . layout || { } ) ) ; // TODO: handle defaults
7
7
8
8
const sourceId = source . getId ( ) ;
9
9
let nativeLayer : com . mapbox . mapboxsdk . style . layers . Layer ;
@@ -21,11 +21,14 @@ export class LayerFactory {
21
21
case 'symbol' :
22
22
nativeLayer = new com . mapbox . mapboxsdk . style . layers . SymbolLayer ( style . id , sourceId ) . withProperties ( layerProperties ) ;
23
23
break ;
24
+ case 'raster' :
25
+ nativeLayer = new com . mapbox . mapboxsdk . style . layers . RasterLayer ( style . id , sourceId ) . withProperties ( layerProperties ) ;
26
+ break ;
24
27
default :
25
28
throw new Error ( `Unknown layer type: ${ style . type } ` ) ;
26
29
}
27
30
28
- var layer = new Layer ( nativeLayer ) ;
31
+ const layer = new Layer ( nativeLayer ) ;
29
32
30
33
return layer ;
31
34
}
@@ -40,6 +43,8 @@ export class LayerFactory {
40
43
return this . parsePropertiesForFillLayer ( propertiesObject ) ;
41
44
case 'symbol' :
42
45
return this . parsePropertiesForSymbolLayer ( propertiesObject ) ;
46
+ case 'raster' :
47
+ return this . parsePropertiesForRasterLayer ( propertiesObject ) ;
43
48
default :
44
49
throw new Error ( `Unknown layer type: ${ layerType } ` ) ;
45
50
}
@@ -246,15 +251,7 @@ export class LayerFactory {
246
251
base = propertiesObject [ 'circle-radius' ] . stops . base ;
247
252
}
248
253
249
- circleProperties . push (
250
- PropertyFactory . circleRadius (
251
- Expression . interpolate (
252
- Expression . exponential ( new java . lang . Float ( base ) ) ,
253
- Expression . zoom ( ) ,
254
- stopArgs
255
- )
256
- )
257
- ) ;
254
+ circleProperties . push ( PropertyFactory . circleRadius ( Expression . interpolate ( Expression . exponential ( new java . lang . Float ( base ) ) , Expression . zoom ( ) , stopArgs ) ) ) ;
258
255
}
259
256
}
260
257
@@ -443,7 +440,76 @@ export class LayerFactory {
443
440
if ( propertiesObject [ 'visibility' ] ) {
444
441
symbolProperties . push ( PropertyFactory . visibility ( propertiesObject [ 'visibility' ] ) ) ;
445
442
}
446
-
443
+
447
444
return symbolProperties ;
448
445
}
446
+
447
+ private static parsePropertiesForRasterLayer ( propertiesObject ) {
448
+ const rasterProperties = [ ] ;
449
+
450
+ if ( ! propertiesObject ) {
451
+ return rasterProperties ;
452
+ }
453
+
454
+ /*
455
+ raster-brightness-max ✓
456
+ raster-brightness-min ✓
457
+ raster-contrast ✓
458
+ raster-fade-duration ✓
459
+ raster-hue-rotate ✓
460
+ raster-opacity ✓
461
+ raster-resampling ✓
462
+ raster-saturation ✓
463
+ visibility ✓
464
+ */
465
+
466
+ const PropertyFactory = com . mapbox . mapboxsdk . style . layers . PropertyFactory ;
467
+
468
+ if ( propertiesObject [ 'raster-brightness-max' ] ) {
469
+ rasterProperties . push ( PropertyFactory . rasterBrightnessMax ( new java . lang . Float ( propertiesObject [ 'raster-brightness-max' ] ) ) ) ;
470
+ }
471
+
472
+ if ( propertiesObject [ 'raster-brightness-min' ] ) {
473
+ rasterProperties . push ( PropertyFactory . rasterBrightnessMin ( new java . lang . Float ( propertiesObject [ 'raster-brightness-min' ] ) ) ) ;
474
+ }
475
+
476
+ if ( propertiesObject [ 'raster-contrast' ] ) {
477
+ rasterProperties . push ( PropertyFactory . rasterContrast ( new java . lang . Float ( propertiesObject [ 'raster-contrast' ] ) ) ) ;
478
+ }
479
+
480
+ if ( propertiesObject [ 'raster-fade-duration' ] ) {
481
+ rasterProperties . push ( PropertyFactory . rasterFadeDuration ( new java . lang . Float ( propertiesObject [ 'raster-fade-duration' ] ) ) ) ;
482
+ }
483
+
484
+ if ( propertiesObject [ 'raster-hue-rotate' ] ) {
485
+ rasterProperties . push ( PropertyFactory . rasterHueRotate ( new java . lang . Float ( propertiesObject [ 'raster-hue-rotate' ] ) ) ) ;
486
+ }
487
+
488
+ if ( propertiesObject [ 'raster-opacity' ] ) {
489
+ rasterProperties . push ( PropertyFactory . rasterOpacity ( new java . lang . Float ( propertiesObject [ 'raster-opacity' ] ) ) ) ;
490
+ }
491
+
492
+ if ( propertiesObject [ 'raster-resampling' ] ) {
493
+ switch ( propertiesObject [ 'raster-resampling' ] ) {
494
+ case 'linear' :
495
+ rasterProperties . push ( com . mapbox . mapboxsdk . style . layers . Property . RASTER_RESAMPLING_LINEAR ) ;
496
+ break ;
497
+ case 'nearest' :
498
+ rasterProperties . push ( com . mapbox . mapboxsdk . style . layers . Property . RASTER_RESAMPLING_NEAREST ) ;
499
+ break ;
500
+ default :
501
+ throw new Error ( 'Unknown raster resampling value.' ) ;
502
+ }
503
+ }
504
+
505
+ if ( propertiesObject [ 'raster-saturation' ] ) {
506
+ rasterProperties . push ( PropertyFactory . rasterSaturation ( new java . lang . Float ( propertiesObject [ 'raster-saturation' ] ) ) ) ;
507
+ }
508
+
509
+ if ( propertiesObject [ 'visibility' ] ) {
510
+ rasterProperties . push ( PropertyFactory . visibility ( propertiesObject [ 'visibility' ] ) ) ;
511
+ }
512
+
513
+ return rasterProperties ;
514
+ }
449
515
}
0 commit comments