1
- import { Application , Color , EventData , ImageSource , Utils , View } from "@nativescript/core" ;
1
+ import { Application , Color , EventData , ImageSource , Utils , View } from "@nativescript/core" ;
2
+ import { isNullOrUndefined } from "@nativescript/core/utils/types" ;
2
3
import {
3
4
ActiveBuildingEvent ,
4
5
ActiveLevelEvent ,
@@ -43,7 +44,7 @@ import {
43
44
Style ,
44
45
TileOverlayOptions
45
46
} from "." ;
46
- import { JointType , MapType , MapViewBase } from "./common" ;
47
+ import { bearingProperty , JointType , latProperty , lngProperty , MapType , MapViewBase , tiltProperty , zoomProperty } from "./common" ;
47
48
48
49
import {
49
50
intoNativeMarkerOptions ,
@@ -84,7 +85,7 @@ export class MapView extends MapViewBase {
84
85
createdBundle = null ;
85
86
savedBundle = null ;
86
87
#listener: com . google . android . gms . maps . OnMapReadyCallback ;
87
-
88
+ _map : com . google . android . gms . maps . GoogleMap ;
88
89
constructor ( ) {
89
90
super ( ) ;
90
91
const ref = new WeakRef ( this ) ;
@@ -158,6 +159,7 @@ export class MapView extends MapViewBase {
158
159
const ref = new WeakRef ( this ) ;
159
160
this . #listener = new com . google . android . gms . maps . OnMapReadyCallback ( {
160
161
onMapReady ( map : com . google . android . gms . maps . GoogleMap ) : void {
162
+ const owner = ref . get ?.( ) ;
161
163
( < any > org ) . nativescript . plugins . google_maps . GoogleMaps . registerMapListeners ( map , new ( < any > org ) . nativescript . plugins . google_maps . GoogleMaps . Callback ( {
162
164
onCameraEvent ( position : com . google . android . gms . maps . model . CameraPosition , event : string , isGesture : boolean ) {
163
165
if ( event === 'start' ) {
@@ -309,28 +311,42 @@ export class MapView extends MapViewBase {
309
311
310
312
} ,
311
313
onInfoWindowAdapterEvent ( marker : com . google . android . gms . maps . model . Marker , event : string ) {
312
- let info = < MarkerInfoEvent > {
313
- eventName : '' ,
314
- object : ref ?. get ?.( ) ,
315
- marker : Marker . fromNative ( marker ) ,
316
- view : null
317
- } ;
318
-
319
- if ( event === 'contents' ) {
320
- info . eventName = MapView . markerInfoContentsEvent ;
321
- } else if ( event === 'window' ) {
322
- info . eventName = MapView . markerInfoWindowEvent ;
323
- } else {
324
- info = null ;
325
- }
314
+ const owner : MapView = ref . get ?.( ) ;
315
+ if ( owner ) {
316
+ let info = < MarkerInfoEvent > {
317
+ eventName : '' ,
318
+ object : ref ?. get ?.( ) ,
319
+ marker : Marker . fromNative ( marker ) ,
320
+ view : null
321
+ } ;
322
+
323
+ if ( event === 'contents' ) {
324
+ info . eventName = MapView . markerInfoContentsEvent ;
325
+ } else if ( event === 'window' ) {
326
+ info . eventName = MapView . markerInfoWindowEvent ;
327
+ } else {
328
+ info = null ;
329
+ }
326
330
327
- if ( info ) {
328
- ref ?. get ?.( ) . notify ?.( info ) ;
329
- if ( info . view instanceof View ) {
330
- if ( ! info . view ?. nativeView ) {
331
- ref ?. get ?.( ) . _addView ?.( info . view ) ;
331
+ if ( info ) {
332
+ owner . notify ( info ) ;
333
+ if ( info . view instanceof View ) {
334
+ if ( ! info . view . parent && ! info . view ?. nativeView ) {
335
+ owner . _addView ( info . view ) ;
336
+ }
337
+ if ( info . view . nativeView && ! ( < any > marker ) . _view ) {
338
+ ( < any > marker ) . _view = new android . widget . RelativeLayout ( owner . _context ) ;
339
+ }
340
+ const parent = info . view . nativeView ?. getParent ?.( ) ;
341
+ if ( info . view . nativeView && parent !== ( < any > marker ) . _view ) {
342
+ if ( parent && parent . removeView ) {
343
+ parent . removeView ( info . view . nativeView ) ;
344
+ }
345
+ const container : android . widget . RelativeLayout = ( < any > marker ) . _view ;
346
+ container . addView ( info . view . nativeView ) ;
347
+ }
348
+ return ( < any > marker ) ?. _view ?? null ;
332
349
}
333
- return info . view ?. nativeView ?? null ;
334
350
}
335
351
}
336
352
@@ -355,6 +371,18 @@ export class MapView extends MapViewBase {
355
371
}
356
372
} ,
357
373
} ) ) ;
374
+
375
+ if ( owner ) {
376
+ owner . _map = map ;
377
+ owner . _updateCamera ( map , {
378
+ lat : owner . lat ,
379
+ lng : owner . lng ,
380
+ bearing : owner . bearing ,
381
+ tilt : owner . tilt ,
382
+ zoom : owner . zoom
383
+ } )
384
+ }
385
+
358
386
ref . get ?.( ) . notify ?.( {
359
387
eventName : 'ready' ,
360
388
object : ref . get ?.( ) ,
@@ -368,6 +396,99 @@ export class MapView extends MapViewBase {
368
396
nativeView . getMapAsync ( this . #listener) ;
369
397
return nativeView ;
370
398
}
399
+
400
+ [ latProperty . setNative ] ( value ) {
401
+ if ( this . _map ) {
402
+ this . _updateCamera ( this . _map , {
403
+ lat : value
404
+ } )
405
+ }
406
+ }
407
+
408
+ [ lngProperty . setNative ] ( value ) {
409
+ if ( this . _map ) {
410
+ this . _updateCamera ( this . _map , {
411
+ lng : value
412
+ } )
413
+ }
414
+ }
415
+
416
+
417
+ [ zoomProperty . setNative ] ( value ) {
418
+ if ( this . _map ) {
419
+ this . _updateCamera ( this . _map , {
420
+ zoom : value
421
+ } )
422
+ }
423
+ }
424
+
425
+ [ tiltProperty . setNative ] ( value ) {
426
+ if ( this . _map ) {
427
+ this . _updateCamera ( this . _map , {
428
+ tilt : value
429
+ } )
430
+ }
431
+ }
432
+
433
+
434
+ [ bearingProperty . setNative ] ( value ) {
435
+ if ( this . _map ) {
436
+ this . _updateCamera ( this . _map , {
437
+ bearing : value
438
+ } )
439
+ }
440
+ }
441
+
442
+
443
+ _updateCamera ( map , owner : {
444
+ lat ?,
445
+ lng ?,
446
+ zoom ?,
447
+ tilt ?,
448
+ bearing ?
449
+ } ) {
450
+ const googleMap = GoogleMap . fromNative ( map ) ;
451
+ if ( googleMap ) {
452
+ const position = CameraPosition . fromNative ( map . getCameraPosition ( ) ) ;
453
+
454
+ let changed = false ;
455
+ if ( ! isNullOrUndefined ( owner . lat ) ) {
456
+ position . target = {
457
+ lat : typeof owner . lat === 'string' ? parseFloat ( owner . lat ) : owner . lat ,
458
+ lng : position . target . lng
459
+ }
460
+ changed = true ;
461
+ }
462
+
463
+ if ( ! isNullOrUndefined ( owner . lng ) ) {
464
+ position . target = {
465
+ lat : position . target . lat ,
466
+ lng : typeof owner . lng === 'string' ? parseFloat ( owner . lng ) : owner . lng
467
+ }
468
+ changed = true ;
469
+ }
470
+
471
+ if ( ! isNullOrUndefined ( owner . zoom ) ) {
472
+ position . zoom = typeof owner . zoom === 'string' ? parseFloat ( owner . zoom ) : owner . zoom ;
473
+ changed = true ;
474
+ }
475
+
476
+ if ( ! isNullOrUndefined ( owner . tilt ) ) {
477
+ position . tilt = typeof owner . tilt === 'string' ? parseFloat ( owner . tilt ) : owner . tilt ;
478
+ changed = true ;
479
+ }
480
+
481
+ if ( ! isNullOrUndefined ( owner . bearing ) ) {
482
+ position . bearing = typeof owner . bearing === 'string' ? parseFloat ( owner . bearing ) : owner . bearing ;
483
+ changed = true ;
484
+ }
485
+
486
+ if ( changed ) {
487
+ googleMap . cameraPosition = position ;
488
+ }
489
+
490
+ }
491
+ }
371
492
}
372
493
373
494
export class IndoorLevel implements IIndoorLevel {
@@ -559,7 +680,7 @@ export class GoogleMap implements IGoogleMap {
559
680
560
681
set cameraPosition ( value ) {
561
682
this . native . moveCamera (
562
- CameraUpdate . fromCameraPosition ( value )
683
+ CameraUpdate . fromCameraPosition ( value ) . native
563
684
)
564
685
}
565
686
@@ -1055,6 +1176,13 @@ export class Marker implements IMarker {
1055
1176
this . native . setZIndex ( value ) ;
1056
1177
}
1057
1178
1179
+ hideInfoWindow ( ) {
1180
+ this . native . hideInfoWindow ( ) ;
1181
+ }
1182
+
1183
+ showInfoWindow ( ) {
1184
+ this . native . showInfoWindow ( ) ;
1185
+ }
1058
1186
}
1059
1187
1060
1188
export class Circle implements ICircle {
@@ -1817,7 +1945,7 @@ export class Projection implements IProjection {
1817
1945
coordinate . lng
1818
1946
)
1819
1947
) ;
1820
- return { x : point . x , y : point . y } ;
1948
+ return { x : point . x , y : point . y } ;
1821
1949
}
1822
1950
}
1823
1951
0 commit comments