@@ -426,12 +426,31 @@ export class HelloWorldModel extends Observable {
426
426
source : {
427
427
type : 'geojson' ,
428
428
data : {
429
- type : 'Feature' ,
430
- properties : { } ,
431
- geometry : {
432
- type : 'Point' ,
433
- coordinates : [ 4.823684692382513 , 52.3701494345567 ] ,
434
- } ,
429
+ type : 'FeatureCollection' ,
430
+ features : [
431
+ {
432
+ id : '1' ,
433
+ type : 'Feature' ,
434
+ properties : {
435
+ querySample : '1' ,
436
+ } ,
437
+ geometry : {
438
+ type : 'Point' ,
439
+ coordinates : [ 4.823684692382513 , 52.3701494345567 ] ,
440
+ } ,
441
+ } ,
442
+ {
443
+ id : '2' ,
444
+ type : 'Feature' ,
445
+ properties : {
446
+ querySample : '2' ,
447
+ } ,
448
+ geometry : {
449
+ type : 'Point' ,
450
+ coordinates : [ 4.823684692382513 , 52.3701494345567 ] ,
451
+ } ,
452
+ } ,
453
+ ] ,
435
454
} ,
436
455
} ,
437
456
paint : {
@@ -444,7 +463,25 @@ export class HelloWorldModel extends Observable {
444
463
'circle-stroke-opacity' : 0.75 ,
445
464
} ,
446
465
} )
447
- . then ( ( ) => console . log ( 'circle-with-source-object added' ) ) ;
466
+ . then ( ( ) => {
467
+ console . log ( 'circle-with-source-object added' ) ;
468
+ this . mapbox . onMapEvent ( 'click' , 'circle-with-source-object' , ( features ) => {
469
+ console . log ( 'clicked' , 'circle-with-source-object' , features ) ;
470
+ } ) ;
471
+
472
+ setTimeout ( ( ) => {
473
+ this . mapbox
474
+ . queryRenderedFeatures ( {
475
+ point : {
476
+ lat : 52.3701494345567 ,
477
+ lng : 4.823684692382513
478
+ } ,
479
+ layers : [ 'circle-with-source-object' ] ,
480
+ filter : [ 'all' , [ '==' , '$id' , '2' ] ] ,
481
+ } )
482
+ . then ( ( result ) => console . log ( 'query rendered features' , JSON . stringify ( result ) ) ) ;
483
+ } , 3000 ) ;
484
+ } ) ;
448
485
449
486
this . mapbox
450
487
. addLayer ( {
@@ -476,7 +513,12 @@ export class HelloWorldModel extends Observable {
476
513
'line-dash-array' : [ 1 , 1 , 1 , 1 ] ,
477
514
} ,
478
515
} )
479
- . then ( ( ) => console . log ( 'line-with-source-object added' ) ) ;
516
+ . then ( ( ) => {
517
+ console . log ( 'line-with-source-object added' ) ;
518
+ this . mapbox . onMapEvent ( 'click' , 'line-with-source-object' , ( features ) => {
519
+ console . log ( 'clicked' , 'line-with-source-object' , features ) ;
520
+ } ) ;
521
+ } ) ;
480
522
481
523
this . mapbox
482
524
. addLayer ( {
@@ -510,7 +552,12 @@ export class HelloWorldModel extends Observable {
510
552
'fill-translate-anchor' : 'map' ,
511
553
} ,
512
554
} )
513
- . then ( ( ) => console . log ( 'fill-with-source-object added' ) ) ;
555
+ . then ( ( ) => {
556
+ console . log ( 'fill-with-source-object added' ) ;
557
+ this . mapbox . onMapEvent ( 'click' , 'fill-with-source-object' , ( features ) => {
558
+ console . log ( 'clicked' , 'fill-with-source-object' , features ) ;
559
+ } ) ;
560
+ } ) ;
514
561
515
562
await this . mapbox . addImage ( 'bee' , 'res://bee' ) ;
516
563
await this . mapbox . addImage ( 'pizza' , '~/assets/pizza-slice.png' ) ;
@@ -532,7 +579,12 @@ export class HelloWorldModel extends Observable {
532
579
'text-color' : '#d6c80d' ,
533
580
} ,
534
581
} )
535
- . then ( ( ) => console . log ( 'symbol-with-source-object added' ) ) ;
582
+ . then ( ( ) => {
583
+ console . log ( 'symbol-with-source-object added' ) ;
584
+ this . mapbox . onMapEvent ( 'click' , 'symbol-with-source-object' , ( features ) => {
585
+ console . log ( 'clicked' , 'symbol-with-source-object' , features ) ;
586
+ } ) ;
587
+ } ) ;
536
588
537
589
this . mapbox
538
590
. addLayer ( {
@@ -567,10 +619,10 @@ export class HelloWorldModel extends Observable {
567
619
568
620
public doRemoveLayerAndSource ( ) : void {
569
621
Promise . all ( [
570
- this . mapbox . removeLayer ( 'circle-with-source-object' ) ,
571
- this . mapbox . removeLayer ( 'line-with-source-object' ) ,
572
- this . mapbox . removeLayer ( 'fill-with-source-object' ) ,
573
- this . mapbox . removeLayer ( 'symbol-with-source-object' ) ,
622
+ this . mapbox . removeLayer ( 'circle-with-source-object' ) . then ( ( ) => this . mapbox . offMapEvent ( 'click' , 'circle-with-source-object' ) ) ,
623
+ this . mapbox . removeLayer ( 'line-with-source-object' ) . then ( ( ) => this . mapbox . offMapEvent ( 'click' , 'line-with-source-object' ) ) ,
624
+ this . mapbox . removeLayer ( 'fill-with-source-object' ) . then ( ( ) => this . mapbox . offMapEvent ( 'click' , 'fill-with-source-object' ) ) ,
625
+ this . mapbox . removeLayer ( 'symbol-with-source-object' ) . then ( ( ) => this . mapbox . offMapEvent ( 'click' , 'symbol-with-source-object' ) ) ,
574
626
this . mapbox . removeLayer ( 'symbol-with-source-object2' ) ,
575
627
] ) . then ( ( ) => {
576
628
return Promise . all ( [
0 commit comments