@@ -190,7 +190,7 @@ export class GoogleMap implements OnChanges, OnInit, OnDestroy {
190
190
@Output ( ) zoomChanged = new EventEmitter < void > ( ) ;
191
191
192
192
private _mapEl : HTMLElement ;
193
- _googleMap ! : UpdatedGoogleMap ;
193
+ _googleMap : UpdatedGoogleMap | undefined ;
194
194
195
195
/** Whether we're currently rendering inside a browser. */
196
196
private _isBrowser : boolean ;
@@ -244,8 +244,7 @@ export class GoogleMap implements OnChanges, OnInit, OnDestroy {
244
244
this . _googleMapChanges = this . _initializeMap ( combinedOptionsChanges ) ;
245
245
this . _googleMapChanges . subscribe ( ( googleMap : google . maps . Map ) => {
246
246
this . _googleMap = googleMap as UpdatedGoogleMap ;
247
-
248
- this . _initializeEventHandlers ( ) ;
247
+ this . _initializeEventHandlers ( this . _googleMap ) ;
249
248
} ) ;
250
249
251
250
this . _watchForOptionsChanges ( ) ;
@@ -267,23 +266,29 @@ export class GoogleMap implements OnChanges, OnInit, OnDestroy {
267
266
fitBounds (
268
267
bounds : google . maps . LatLngBounds | google . maps . LatLngBoundsLiteral ,
269
268
padding ?: number | google . maps . Padding ) {
270
- this . _googleMap . fitBounds ( bounds , padding ) ;
269
+ if ( this . _googleMap ) {
270
+ this . _googleMap . fitBounds ( bounds , padding ) ;
271
+ }
271
272
}
272
273
273
274
/**
274
275
* See
275
276
* https://developers.google.com/maps/documentation/javascript/reference/map#Map.panBy
276
277
*/
277
278
panBy ( x : number , y : number ) {
278
- this . _googleMap . panBy ( x , y ) ;
279
+ if ( this . _googleMap ) {
280
+ this . _googleMap . panBy ( x , y ) ;
281
+ }
279
282
}
280
283
281
284
/**
282
285
* See
283
286
* https://developers.google.com/maps/documentation/javascript/reference/map#Map.panTo
284
287
*/
285
288
panTo ( latLng : google . maps . LatLng | google . maps . LatLngLiteral ) {
286
- this . _googleMap . panTo ( latLng ) ;
289
+ if ( this . _googleMap ) {
290
+ this . _googleMap . panTo ( latLng ) ;
291
+ }
287
292
}
288
293
289
294
/**
@@ -293,111 +298,125 @@ export class GoogleMap implements OnChanges, OnInit, OnDestroy {
293
298
panToBounds (
294
299
latLngBounds : google . maps . LatLngBounds | google . maps . LatLngBoundsLiteral ,
295
300
padding ?: number | google . maps . Padding ) {
296
- this . _googleMap . panToBounds ( latLngBounds , padding ) ;
301
+ if ( this . _googleMap ) {
302
+ this . _googleMap . panToBounds ( latLngBounds , padding ) ;
303
+ }
297
304
}
298
305
299
306
/**
300
307
* See
301
308
* https://developers.google.com/maps/documentation/javascript/reference/map#Map.getBounds
302
309
*/
303
310
getBounds ( ) : google . maps . LatLngBounds | null {
304
- return this . _googleMap . getBounds ( ) || null ;
311
+ const googleMap = this . _googleMap ;
312
+ return ( googleMap ? googleMap . getBounds ( ) : null ) || null ;
305
313
}
306
314
307
315
/**
308
316
* See
309
317
* https://developers.google.com/maps/documentation/javascript/reference/map#Map.getCenter
318
+ * @deprecated Type to be changed to `google.maps.LatLng|null`.
319
+ * @breaking -change 10.0.0
310
320
*/
311
321
getCenter ( ) : google . maps . LatLng {
312
- return this . _googleMap . getCenter ( ) ;
322
+ return this . _googleMap ? this . _googleMap . getCenter ( ) : null ! ;
313
323
}
314
324
315
325
/**
316
326
* See
317
327
* https://developers.google.com/maps/documentation/javascript/reference/map#Map.getClickableIcons
318
328
*/
319
329
getClickableIcons ( ) : boolean {
320
- return this . _googleMap . getClickableIcons ( ) ;
330
+ return this . _googleMap ? this . _googleMap . getClickableIcons ( ) : false ;
321
331
}
322
332
323
333
/**
324
334
* See
325
335
* https://developers.google.com/maps/documentation/javascript/reference/map#Map.getHeading
326
336
*/
327
337
getHeading ( ) : number {
328
- return this . _googleMap . getHeading ( ) ;
338
+ return this . _googleMap ? this . _googleMap . getHeading ( ) : 0 ;
329
339
}
330
340
331
341
/**
332
342
* See
333
343
* https://developers.google.com/maps/documentation/javascript/reference/map#Map.getMapTypeId
334
344
*/
335
345
getMapTypeId ( ) : google . maps . MapTypeId | string {
336
- return this . _googleMap . getMapTypeId ( ) ;
346
+ return this . _googleMap ? this . _googleMap . getMapTypeId ( ) : '' ;
337
347
}
338
348
339
349
/**
340
350
* See
341
351
* https://developers.google.com/maps/documentation/javascript/reference/map#Map.getProjection
342
352
*/
343
353
getProjection ( ) : google . maps . Projection | null {
344
- return this . _googleMap . getProjection ( ) ;
354
+ return this . _googleMap ? this . _googleMap . getProjection ( ) : null ;
345
355
}
346
356
347
357
/**
348
358
* See
349
359
* https://developers.google.com/maps/documentation/javascript/reference/map#Map.getStreetView
360
+ *
361
+ * @deprecated Return type to be changed to `google.maps.StreetViewPanorama|null`.
362
+ * @breaking -change 10.0.0
350
363
*/
351
364
getStreetView ( ) : google . maps . StreetViewPanorama {
352
- return this . _googleMap . getStreetView ( ) ;
365
+ return this . _googleMap ! . getStreetView ( ) ;
353
366
}
354
367
355
368
/**
356
369
* See
357
370
* https://developers.google.com/maps/documentation/javascript/reference/map#Map.getTilt
358
371
*/
359
372
getTilt ( ) : number {
360
- return this . _googleMap . getTilt ( ) ;
373
+ return this . _googleMap ? this . _googleMap . getTilt ( ) : 0 ;
361
374
}
362
375
363
376
/**
364
377
* See
365
378
* https://developers.google.com/maps/documentation/javascript/reference/map#Map.getZoom
366
379
*/
367
380
getZoom ( ) : number {
368
- return this . _googleMap . getZoom ( ) ;
381
+ return this . _googleMap ? this . _googleMap . getZoom ( ) : 0 ;
369
382
}
370
383
371
384
/**
372
385
* See
373
386
* https://developers.google.com/maps/documentation/javascript/reference/map#Map.controls
374
387
*/
375
388
get controls ( ) : Array < google . maps . MVCArray < Node > > {
376
- return this . _googleMap . controls ;
389
+ return this . _googleMap ? this . _googleMap . controls : [ ] ;
377
390
}
378
391
379
392
/**
380
393
* See
381
394
* https://developers.google.com/maps/documentation/javascript/reference/map#Map.data
395
+ * @deprecated Type to be changed to `google.maps.StreetViewPanorama|null`.
396
+ * @breaking -change 10.0.0
382
397
*/
383
398
get data ( ) : google . maps . Data {
384
- return this . _googleMap . data ;
399
+ return this . _googleMap ? this . _googleMap . data : null ! ;
385
400
}
386
401
387
402
/**
388
403
* See
389
404
* https://developers.google.com/maps/documentation/javascript/reference/map#Map.mapTypes
405
+ * @deprecated Return type to be changed to `google.maps.MapTypeRegistry|null`.
406
+ * @breaking -change 10.0.0
390
407
*/
391
408
get mapTypes ( ) : google . maps . MapTypeRegistry {
392
- return this . _googleMap . mapTypes ;
409
+ return this . _googleMap ? this . _googleMap . mapTypes : null ! ;
393
410
}
394
411
395
412
/**
396
413
* See
397
414
* https://developers.google.com/maps/documentation/javascript/reference/map#Map.overlayMapTypes
415
+ * @deprecated Return type to be changed to `google.maps.MVCArray<google.maps.MapType>|null`.
416
+ * @breaking -change 10.0.0
398
417
*/
399
418
get overlayMapTypes ( ) : google . maps . MVCArray < google . maps . MapType > {
400
- return this . _googleMap . overlayMapTypes ;
419
+ return this . _googleMap ? this . _googleMap . overlayMapTypes : null ! ;
401
420
}
402
421
403
422
private _setSize ( ) {
@@ -423,9 +442,8 @@ export class GoogleMap implements OnChanges, OnInit, OnDestroy {
423
442
private _initializeMap ( optionsChanges : Observable < google . maps . MapOptions > ) :
424
443
Observable < google . maps . Map > {
425
444
return optionsChanges . pipe (
426
- take ( 1 ) , map ( options => {
427
- return new google . maps . Map ( this . _mapEl , options ) ;
428
- } ) ,
445
+ take ( 1 ) ,
446
+ map ( options => new google . maps . Map ( this . _mapEl , options ) ) ,
429
447
shareReplay ( 1 ) ) ;
430
448
}
431
449
@@ -457,7 +475,7 @@ export class GoogleMap implements OnChanges, OnInit, OnDestroy {
457
475
} ) ;
458
476
}
459
477
460
- private _initializeEventHandlers ( ) {
478
+ private _initializeEventHandlers ( googleMap : UpdatedGoogleMap ) {
461
479
// Ensure that we don't leak if called multiple times.
462
480
this . _clearListeners ( ) ;
463
481
@@ -484,7 +502,7 @@ export class GoogleMap implements OnChanges, OnInit, OnDestroy {
484
502
] ) ;
485
503
eventHandlers . forEach ( ( eventHandler : EventEmitter < void > , name : string ) => {
486
504
if ( eventHandler . observers . length > 0 ) {
487
- this . _listeners . push ( this . _googleMap . addListener ( name , ( ) => {
505
+ this . _listeners . push ( googleMap . addListener ( name , ( ) => {
488
506
eventHandler . emit ( ) ;
489
507
} ) ) ;
490
508
}
@@ -493,13 +511,13 @@ export class GoogleMap implements OnChanges, OnInit, OnDestroy {
493
511
( eventHandler : EventEmitter < google . maps . MouseEvent > , name : string ) => {
494
512
if ( eventHandler . observers . length > 0 ) {
495
513
this . _listeners . push (
496
- this . _googleMap . addListener ( name , ( event : google . maps . MouseEvent ) => {
514
+ googleMap . addListener ( name , ( event : google . maps . MouseEvent ) => {
497
515
eventHandler . emit ( event ) ;
498
516
} ) ) ;
499
517
}
500
518
} ) ;
501
519
if ( this . mapClick . observers . length > 0 ) {
502
- this . _listeners . push ( this . _googleMap . addListener (
520
+ this . _listeners . push ( googleMap . addListener (
503
521
'click' , ( event : google . maps . MouseEvent | google . maps . IconMouseEvent ) => {
504
522
this . mapClick . emit ( event ) ;
505
523
} ) ) ;
0 commit comments