Skip to content

Commit

Permalink
feat(AgmMap): fix fitBounds causing protractor timeout (#1611)
Browse files Browse the repository at this point in the history
Fix fitBounds input in map.ts directive causing timeout in protractor
tests. _fitBoundsSubscription is now run outside angular ngZone to
prevent protractor from waiting for sample and timer rxjs operators
to sync map bounds.

closes #1548
  • Loading branch information
marcin-j authored and doom777 committed Jun 2, 2019
1 parent 2ae382a commit 565b6a7
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions packages/core/directives/map.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, ElementRef, EventEmitter, OnChanges, OnDestroy, OnInit, SimpleChanges, Input, Output } from '@angular/core';
import { Component, ElementRef, EventEmitter, OnChanges, OnDestroy, OnInit, SimpleChanges, Input, Output, NgZone } from '@angular/core';
import {Subscription} from 'rxjs';

import {MouseEvent} from '../map-types';
Expand Down Expand Up @@ -329,7 +329,7 @@ export class AgmMap implements OnChanges, OnInit, OnDestroy {
*/
@Output() mapReady: EventEmitter<any> = new EventEmitter<any>();

constructor(private _elem: ElementRef, private _mapsWrapper: GoogleMapsAPIWrapper, protected _fitBoundsService: FitBoundsService) {}
constructor(private _elem: ElementRef, private _mapsWrapper: GoogleMapsAPIWrapper, protected _fitBoundsService: FitBoundsService, private _zone: NgZone) {}

/** @internal */
ngOnInit() {
Expand Down Expand Up @@ -478,7 +478,11 @@ export class AgmMap implements OnChanges, OnInit, OnDestroy {
}

private _subscribeToFitBoundsUpdates() {
this._fitBoundsSubscription = this._fitBoundsService.getBounds$().subscribe(b => this._updateBounds(b));
this._zone.runOutsideAngular(() => {
this._fitBoundsSubscription = this._fitBoundsService.getBounds$().subscribe(b => {
this._zone.run(() => this._updateBounds(b));
});
});
}

protected _updateBounds(bounds: LatLngBounds|LatLngBoundsLiteral) {
Expand Down

0 comments on commit 565b6a7

Please sign in to comment.