Skip to content

Commit

Permalink
fix(Map): fitBounds values that are undefined/null
Browse files Browse the repository at this point in the history
fixes #1505
fixes #1504
  • Loading branch information
sebholstein authored Sep 24, 2018
1 parent 7d76659 commit f9afd4b
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions packages/core/directives/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,14 +475,11 @@ export class AgmMap implements OnChanges, OnInit, OnDestroy {
}

protected _updateBounds(bounds: LatLngBounds|LatLngBoundsLiteral) {
if (this._isLatLngBoundsLiteral(bounds)) {
if (this._isLatLngBoundsLiteral(bounds) && google && google.maps) {

This comment has been minimized.

Copy link
@gionkunz

gionkunz Nov 15, 2018

I have a problem here, when the map is loaded lazily, accessing google will cause a reference error. Wouldn't it make sense to resolve the promise of the loader here before accessing the google namespace?

This comment has been minimized.

Copy link
@gionkunz

gionkunz Nov 15, 2018

This problem can be reproduced when the fitBounds input is set to a LatLangBoundsLiteral on the map component and the standard lazy API loader is in control.

This comment has been minimized.

Copy link
@marchage

marchage May 2, 2019

I'm sorry, not the Github expert, but what happened to @gionkunz 's comment? I am experiencing that reference error now (my goal was to make it not "start"/"flash a map" on coordinate [0, 0]). I am also not the typescript expert, but what I remember from javascript was the endless list of typeof ... !== 'undefined's I was always keying in. So even to me this looks wrong, but I might be late to the party?

const newBounds = <LatLngBounds>google.maps.LatLngBounds();
newBounds.union(bounds);
bounds = newBounds;
}
if (bounds.isEmpty()) {
return;
}
if (this.usePanning) {
this._mapsWrapper.panToBounds(bounds);
return;
Expand All @@ -491,7 +488,7 @@ export class AgmMap implements OnChanges, OnInit, OnDestroy {
}

private _isLatLngBoundsLiteral(bounds: LatLngBounds|LatLngBoundsLiteral): bounds is LatLngBoundsLiteral {
return (<any>bounds).extend === undefined;
return bounds != null && (<any>bounds).extend === undefined;
}

private _handleMapCenterChange() {
Expand Down

0 comments on commit f9afd4b

Please sign in to comment.