@@ -4,6 +4,7 @@ import { ContentView } from '@nativescript/core/ui/content-view';
4
4
import { AlertOptions , alert } from '@nativescript/core/ui/dialogs' ;
5
5
import { DownloadProgress , LatLng , MapStyle , Mapbox , MapboxMarker , MapboxView , OfflineRegion , Viewport } from '@nativescript-community/ui-mapbox' ;
6
6
import { SETTINGS } from '../../mapbox_config' ;
7
+ import { AmsterdamHoneyBees } from './sample-data' ;
7
8
8
9
const isIOS = platform . Device . os === platform . platformNames . ios ;
9
10
@@ -416,104 +417,151 @@ export class HelloWorldModel extends Observable {
416
417
) ;
417
418
}
418
419
419
- public doAddLayerAndSource ( ) : void {
420
+ public async doAddLayerAndSource ( ) : Promise < void > {
420
421
try {
421
-
422
- this . mapbox
423
- . addLayer ( {
424
- id : 'circle-with-source-object ' ,
425
- type : 'circle' ,
426
- source : {
427
- type : 'geojson' ,
428
- data : {
429
- type : 'Feature' ,
430
- properties : { } ,
431
- geometry : {
432
- type : 'Point' ,
433
- coordinates : [ 4.823684692382513 , 52.3701494345567 ] ,
422
+ this . mapbox
423
+ . addLayer ( {
424
+ id : 'circle-with-source-object' ,
425
+ type : 'circle' ,
426
+ source : {
427
+ type : 'geojson' ,
428
+ data : {
429
+ type : 'Feature' ,
430
+ properties : { } ,
431
+ geometry : {
432
+ type : 'Point' ,
433
+ coordinates : [ 4.823684692382513 , 52.3701494345567 ] ,
434
+ } ,
434
435
} ,
435
436
} ,
436
- } ,
437
- paint : {
438
- 'circle-blur' : 0.2 ,
439
- 'circle-radius' : 10 ,
440
- 'circle-opacity' : 0.65 ,
441
- 'circle-color' : '#ed6498' ,
442
- 'circle-stroke-width' : 4 ,
443
- 'circle-stroke-color' : '#3b0619' ,
444
- 'circle-stroke-opacity' : 0.75 ,
445
- } ,
446
- } )
447
- . then ( ( ) => console . log ( 'circle-with-source-object added' ) ) ;
437
+ paint : {
438
+ 'circle-blur' : 0.2 ,
439
+ 'circle-radius' : 10 ,
440
+ 'circle-opacity' : 0.65 ,
441
+ 'circle-color' : '#ed6498' ,
442
+ 'circle-stroke-width' : 4 ,
443
+ 'circle-stroke-color' : '#3b0619' ,
444
+ 'circle-stroke-opacity' : 0.75 ,
445
+ } ,
446
+ } )
447
+ . then ( ( ) => console . log ( 'circle-with-source-object added' ) ) ;
448
448
449
- this . mapbox
450
- . addLayer ( {
451
- id : 'line-with-source-object' ,
452
- type : 'line' ,
453
- source : {
454
- type : 'geojson' ,
455
- data : {
456
- type : 'Feature' ,
457
- properties : { } ,
458
- geometry : {
459
- type : 'LineString' ,
460
- coordinates : [
461
- [ 4.80926513671875 , 52.27403984182285 ] ,
462
- [ 4.9383544921875 , 52.30931825948968 ] ,
463
- ] ,
449
+ this . mapbox
450
+ . addLayer ( {
451
+ id : 'line-with-source-object' ,
452
+ type : 'line' ,
453
+ source : {
454
+ type : 'geojson' ,
455
+ data : {
456
+ type : 'Feature' ,
457
+ properties : { } ,
458
+ geometry : {
459
+ type : 'LineString' ,
460
+ coordinates : [
461
+ [ 4.80926513671875 , 52.27403984182285 ] ,
462
+ [ 4.9383544921875 , 52.30931825948968 ] ,
463
+ ] ,
464
+ } ,
464
465
} ,
465
466
} ,
466
- } ,
467
- layout : {
468
- 'line-cap' : 'round' ,
469
- 'line-join' : 'round' ,
470
- 'line-blur' : 0.2 ,
471
- } ,
472
- paint : {
473
- 'line-color' : '#ab111b' ,
474
- 'line-width' : 5 ,
475
- 'line-opacity' : 0.7 ,
476
- 'line-dash-array' : [ 1 , 1 , 1 , 1 ] ,
477
- } ,
478
- } )
479
- . then ( ( ) => console . log ( 'line-with-source-object added' ) ) ;
480
-
481
- this . mapbox . addLayer ( {
482
- id : 'fill-with-source-object' ,
483
- type : 'fill' ,
484
- source : {
485
- type : 'geojson' ,
486
- data : {
487
- type : 'Feature' ,
488
- properties : { } ,
489
- geometry : {
490
- type : 'Polygon' ,
491
- coordinates : [
492
- [
493
- [ 4.864797592163086 , 52.346980527061895 ] ,
494
- [ 4.923677444458008 , 52.346980527061895 ] ,
495
- [ 4.923677444458008 , 52.36742431104005 ] ,
496
- [ 4.864797592163086 , 52.36742431104005 ] ,
497
- [ 4.864797592163086 , 52.346980527061895 ] ,
467
+ layout : {
468
+ 'line-cap' : 'round' ,
469
+ 'line-join' : 'round' ,
470
+ 'line-blur' : 0.2 ,
471
+ } ,
472
+ paint : {
473
+ 'line-color' : '#ab111b' ,
474
+ 'line-width' : 5 ,
475
+ 'line-opacity' : 0.7 ,
476
+ 'line-dash-array' : [ 1 , 1 , 1 , 1 ] ,
477
+ } ,
478
+ } )
479
+ . then ( ( ) => console . log ( 'line-with-source-object added' ) ) ;
480
+
481
+ this . mapbox
482
+ . addLayer ( {
483
+ id : 'fill-with-source-object' ,
484
+ type : 'fill' ,
485
+ source : {
486
+ type : 'geojson' ,
487
+ data : {
488
+ type : 'Feature' ,
489
+ properties : { } ,
490
+ geometry : {
491
+ type : 'Polygon' ,
492
+ coordinates : [
493
+ [
494
+ [ 4.864797592163086 , 52.346980527061895 ] ,
495
+ [ 4.923677444458008 , 52.346980527061895 ] ,
496
+ [ 4.923677444458008 , 52.36742431104005 ] ,
497
+ [ 4.864797592163086 , 52.36742431104005 ] ,
498
+ [ 4.864797592163086 , 52.346980527061895 ] ,
499
+ ] ,
498
500
] ,
499
- ] ,
501
+ } ,
500
502
} ,
501
503
} ,
502
- } ,
503
- paint : {
504
- 'fill-antialias' : 'true' ,
505
- 'fill-color' : '#5dbcd2' ,
506
- 'fill-opacity' : 0.65 ,
507
- 'fill-outline-color' : '#23474f' ,
508
- 'fill-translate' : [ 0 , 0 ] ,
509
- 'fill-translate-anchor' : 'map' ,
510
- } ,
511
- } )
512
- . then ( ( ) => console . log ( 'fill-with-source-object added' ) ) ;
504
+ paint : {
505
+ 'fill-antialias' : 'true' ,
506
+ 'fill-color' : '#5dbcd2' ,
507
+ 'fill-opacity' : 0.65 ,
508
+ 'fill-outline-color' : '#23474f' ,
509
+ 'fill-translate' : [ 0 , 0 ] ,
510
+ 'fill-translate-anchor' : 'map' ,
511
+ } ,
512
+ } )
513
+ . then ( ( ) => console . log ( 'fill-with-source-object added' ) ) ;
514
+
515
+ await this . mapbox . addImage ( 'bee' , 'res://bee' ) ;
516
+ await this . mapbox . addImage ( 'pizza' , '~/assets/pizza-slice.png' ) ;
517
+
518
+ this . mapbox
519
+ . addLayer ( {
520
+ id : 'symbol-with-source-object' ,
521
+ type : 'symbol' ,
522
+ source : {
523
+ type : 'geojson' ,
524
+ data : AmsterdamHoneyBees ,
525
+ } ,
526
+ layout : {
527
+ 'text-field' : 'Honey' ,
528
+ 'icon-size' : 0.2 ,
529
+ 'icon-image' : 'bee' ,
530
+ } ,
531
+ paint : {
532
+ 'text-color' : '#d6c80d' ,
533
+ } ,
534
+ } )
535
+ . then ( ( ) => console . log ( 'symbol-with-source-object added' ) ) ;
513
536
537
+ this . mapbox
538
+ . addLayer ( {
539
+ id : 'symbol-with-source-object2' ,
540
+ type : 'symbol' ,
541
+ source : {
542
+ type : 'geojson' ,
543
+ data : {
544
+ type : 'Feature' ,
545
+ properties : { } ,
546
+ geometry : {
547
+ type : 'Point' ,
548
+ coordinates : [ 4.8916793 , 52.3690958 ]
549
+ } ,
550
+ } ,
551
+ } ,
552
+ layout : {
553
+ 'text-field' : 'New York Pizza' ,
554
+ 'icon-size' : 0.99 ,
555
+ 'icon-image' : 'pizza' ,
556
+ 'icon-rotate' : 180
557
+ } ,
558
+ paint : {
559
+ 'text-color' : '#d6c80d'
560
+ }
561
+ } )
562
+ . then ( ( ) => console . log ( 'symbol-with-source-object2 added' ) ) ;
514
563
} catch ( error ) {
515
564
console . error ( 'Mapbox doAddLayerAndSource error :' , error ) ;
516
-
517
565
}
518
566
}
519
567
@@ -522,14 +570,18 @@ export class HelloWorldModel extends Observable {
522
570
this . mapbox . removeLayer ( 'circle-with-source-object' ) ,
523
571
this . mapbox . removeLayer ( 'line-with-source-object' ) ,
524
572
this . mapbox . removeLayer ( 'fill-with-source-object' ) ,
573
+ this . mapbox . removeLayer ( 'symbol-with-source-object' ) ,
574
+ this . mapbox . removeLayer ( 'symbol-with-source-object2' ) ,
525
575
] ) . then ( ( ) => {
526
576
return Promise . all ( [
527
577
this . mapbox . removeSource ( 'custom-collection-1' ) ,
528
578
this . mapbox . removeSource ( 'line-with-source-object_source' ) ,
529
579
this . mapbox . removeSource ( 'circle-with-source-object_source' ) ,
530
580
this . mapbox . removeSource ( 'fill-with-source-object_source' ) ,
581
+ this . mapbox . removeSource ( 'symbol-with-source-object_source' ) ,
582
+ this . mapbox . removeSource ( 'symbol-with-source-object2_source' ) ,
531
583
] ) ;
532
- } )
584
+ } ) ;
533
585
}
534
586
535
587
public doListOfflineRegions ( ) : void {
0 commit comments