@@ -22,6 +22,7 @@ import {
22
22
DownloadOfflineRegionOptions ,
23
23
Feature ,
24
24
LatLng ,
25
+ LayerCommon ,
25
26
ListOfflineRegionsOptions ,
26
27
MapStyle ,
27
28
MapboxApi ,
@@ -4249,6 +4250,71 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
4249
4250
4250
4251
// ---------------------------------------------------------------
4251
4252
4253
+ getLayer ( name : string , nativeMap ?: any ) : Promise < LayerCommon > {
4254
+ return new Promise ( ( resolve , reject ) => {
4255
+ try {
4256
+ const theMap = nativeMap || this . _mapboxMapInstance ;
4257
+
4258
+ if ( ! theMap ) {
4259
+ reject ( 'No map has been loaded' ) ;
4260
+ return ;
4261
+ }
4262
+
4263
+ const styleLoadedCallback = new com . mapbox . mapboxsdk . maps . Style . OnStyleLoaded ( {
4264
+ onStyleLoaded : ( style ) => {
4265
+ const layer = style . getLayer ( name ) ;
4266
+ console . log ( 'layer :' , layer ) ;
4267
+ resolve ( layer ? new Layer ( layer ) : null ) ;
4268
+ } ,
4269
+ } ) ;
4270
+
4271
+ theMap . getStyle ( styleLoadedCallback ) ;
4272
+ } catch ( ex ) {
4273
+ if ( Trace . isEnabled ( ) ) {
4274
+ CLog ( CLogTypes . info , 'Error in mapbox.getLayer: ' + ex ) ;
4275
+ }
4276
+ reject ( ex ) ;
4277
+ }
4278
+ } ) ;
4279
+ }
4280
+
4281
+ // ----------------------------------------------------------------------------------
4282
+
4283
+ getLayers ( nativeMap ?: any ) : Promise < Array < LayerCommon > > {
4284
+ return new Promise ( ( resolve , reject ) => {
4285
+ try {
4286
+ const theMap = nativeMap || this . _mapboxMapInstance ;
4287
+
4288
+ if ( ! theMap ) {
4289
+ reject ( 'No map has been loaded' ) ;
4290
+ return ;
4291
+ }
4292
+
4293
+ const styleLoadedCallback = new com . mapbox . mapboxsdk . maps . Style . OnStyleLoaded ( {
4294
+ onStyleLoaded : ( style ) => {
4295
+ const layers = style . getLayers ( ) ;
4296
+ const result : Layer [ ] = [ ] ;
4297
+
4298
+ for ( let i = 0 ; i < layers . size ( ) ; i ++ ) {
4299
+ result . push ( new Layer ( layers . get ( i ) ) ) ;
4300
+ }
4301
+
4302
+ resolve ( result ) ;
4303
+ } ,
4304
+ } ) ;
4305
+
4306
+ theMap . getStyle ( styleLoadedCallback ) ;
4307
+ } catch ( ex ) {
4308
+ if ( Trace . isEnabled ( ) ) {
4309
+ CLog ( CLogTypes . info , 'Error in mapbox.getLayers: ' + ex ) ;
4310
+ }
4311
+ reject ( ex ) ;
4312
+ }
4313
+ } ) ;
4314
+ }
4315
+
4316
+ // ---------------------------------------------------------------
4317
+
4252
4318
_getClickedMarkerDetails ( clicked ) {
4253
4319
for ( const m in this . _markers ) {
4254
4320
const cached = this . _markers [ m ] ;
@@ -4666,4 +4732,26 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
4666
4732
}
4667
4733
} // end of class Mapbox
4668
4734
4735
+ export class Layer implements LayerCommon {
4736
+ public id : string ;
4737
+ private instance : any ;
4738
+
4739
+ constructor ( instance : any ) {
4740
+ this . instance = instance ;
4741
+ this . id = instance . getId ( ) ;
4742
+ }
4743
+
4744
+ public visibility ( ) : boolean {
4745
+ return this . instance . getVisibility ( ) . getValue ( ) === 'visible' ? true : false ;
4746
+ }
4747
+
4748
+ public show ( ) : void {
4749
+ this . instance . setProperties ( [ new com . mapbox . mapboxsdk . style . layers . PropertyValue ( 'visibility' , 'visible' ) ] ) ;
4750
+ }
4751
+
4752
+ public hide ( ) : void {
4753
+ this . instance . setProperties ( [ new com . mapbox . mapboxsdk . style . layers . PropertyValue ( 'visibility' , 'none' ) ] ) ;
4754
+ }
4755
+ }
4756
+
4669
4757
// END
0 commit comments