Skip to content

Commit

Permalink
feat(AgmMap): recentering for triggerResize
Browse files Browse the repository at this point in the history
When you call the triggerResize method of AgmMap, the map gets recentered
automaticaly.

Closes #789
Closes #976

BREAKING CHANGES

Recentering of the map after triggerResize call is now the default behavoir.
You can have the previous behavoir with triggerResize(false).
  • Loading branch information
sebholstein committed Apr 12, 2017
1 parent 64cad8f commit 245e453
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/core/directives/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -395,15 +395,22 @@ export class AgmMap implements OnChanges, OnInit, OnDestroy {

/**
* Triggers a resize event on the google map instance.
* When setCenter is true, the setCenter method of the google map gets called with the current lat/lng values.
* Returns a promise that gets resolved after the event was triggered.
*/
triggerResize(): Promise<void> {
triggerResize(setCenter: boolean = true): Promise<void> {
// Note: When we would trigger the resize event and show the map in the same turn (which is a
// common case for triggering a resize event), then the resize event would not
// work (to show the map), so we trigger the event in a timeout.
return new Promise<void>((resolve) => {
setTimeout(
() => { return this._mapsWrapper.triggerMapEvent('resize').then(() => resolve()); });
setTimeout(() => {
return this._mapsWrapper.triggerMapEvent('resize').then(() => {
if (setCenter) {
this._mapsWrapper.setCenter({lat: this.latitude, lng: this.longitude});
}
resolve();
});
});
});
}

Expand Down

0 comments on commit 245e453

Please sign in to comment.