@@ -142,28 +142,30 @@ export class MapRectangle implements OnInit, OnDestroy {
142142 constructor ( private readonly _map : GoogleMap , private readonly _ngZone : NgZone ) { }
143143
144144 ngOnInit ( ) {
145- const combinedOptionsChanges = this . _combineOptions ( ) ;
146-
147- combinedOptionsChanges . pipe ( take ( 1 ) ) . subscribe ( options => {
148- // Create the object outside the zone so its events don't trigger change detection.
149- // We'll bring it back in inside the `MapEventManager` only for the events that the
150- // user has subscribed to.
151- this . _ngZone . runOutsideAngular ( ( ) => {
152- this . _rectangle = new google . maps . Rectangle ( options ) ;
145+ if ( this . _map . _isBrowser ) {
146+ this . _combineOptions ( ) . pipe ( take ( 1 ) ) . subscribe ( options => {
147+ // Create the object outside the zone so its events don't trigger change detection.
148+ // We'll bring it back in inside the `MapEventManager` only for the events that the
149+ // user has subscribed to.
150+ this . _ngZone . runOutsideAngular ( ( ) => {
151+ this . _rectangle = new google . maps . Rectangle ( options ) ;
152+ } ) ;
153+ this . _rectangle . setMap ( this . _map . _googleMap ) ;
154+ this . _eventManager . setTarget ( this . _rectangle ) ;
153155 } ) ;
154- this . _rectangle . setMap ( this . _map . _googleMap ) ;
155- this . _eventManager . setTarget ( this . _rectangle ) ;
156- } ) ;
157156
158- this . _watchForOptionsChanges ( ) ;
159- this . _watchForBoundsChanges ( ) ;
157+ this . _watchForOptionsChanges ( ) ;
158+ this . _watchForBoundsChanges ( ) ;
159+ }
160160 }
161161
162162 ngOnDestroy ( ) {
163163 this . _eventManager . destroy ( ) ;
164164 this . _destroyed . next ( ) ;
165165 this . _destroyed . complete ( ) ;
166- this . _rectangle . setMap ( null ) ;
166+ if ( this . _rectangle ) {
167+ this . _rectangle . setMap ( null ) ;
168+ }
167169 }
168170
169171 /**
0 commit comments