@@ -28,6 +28,7 @@ export class MapGroundOverlay implements OnInit, OnDestroy {
2828 private _eventManager = new MapEventManager ( this . _ngZone ) ;
2929
3030 private readonly _opacity = new BehaviorSubject < number > ( 1 ) ;
31+ private readonly _url = new BehaviorSubject < string > ( '' ) ;
3132 private readonly _destroyed = new Subject < void > ( ) ;
3233
3334 /**
@@ -37,13 +38,19 @@ export class MapGroundOverlay implements OnInit, OnDestroy {
3738 */
3839 groundOverlay ?: google . maps . GroundOverlay ;
3940
40- @Input ( ) url ! : string ; // Asserted in ngOnInit.
41-
41+ /** URL of the image that will be shown in the overlay. */
4242 @Input ( )
43- bounds ! : google . maps . LatLngBounds | google . maps . LatLngBoundsLiteral ; // Asserted in ngOnInit.
43+ set url ( url : string ) {
44+ this . _url . next ( url ) ;
45+ }
4446
45- @Input ( ) clickable = false ;
47+ /** Bounds for the overlay. */
48+ @Input ( ) bounds : google . maps . LatLngBounds | google . maps . LatLngBoundsLiteral ;
4649
50+ /** Whether the overlay is clickable */
51+ @Input ( ) clickable : boolean = false ;
52+
53+ /** Opacity of the overlay. */
4754 @Input ( )
4855 set opacity ( opacity : number ) {
4956 this . _opacity . next ( opacity ) ;
@@ -69,9 +76,6 @@ export class MapGroundOverlay implements OnInit, OnDestroy {
6976 constructor ( private readonly _map : GoogleMap , private readonly _ngZone : NgZone ) { }
7077
7178 ngOnInit ( ) {
72- if ( ! this . url ) {
73- throw Error ( 'An image url is required' ) ;
74- }
7579 if ( ! this . bounds ) {
7680 throw Error ( 'Image bounds are required' ) ;
7781 }
@@ -81,14 +85,16 @@ export class MapGroundOverlay implements OnInit, OnDestroy {
8185 // We'll bring it back in inside the `MapEventManager` only for the events that the
8286 // user has subscribed to.
8387 this . _ngZone . runOutsideAngular ( ( ) => {
84- this . groundOverlay = new google . maps . GroundOverlay ( this . url , this . bounds , options ) ;
88+ this . groundOverlay =
89+ new google . maps . GroundOverlay ( this . _url . getValue ( ) , this . bounds , options ) ;
8590 } ) ;
8691 this . _assertInitialized ( ) ;
8792 this . groundOverlay . setMap ( this . _map . googleMap ! ) ;
8893 this . _eventManager . setTarget ( this . groundOverlay ) ;
8994 } ) ;
9095
9196 this . _watchForOpacityChanges ( ) ;
97+ this . _watchForUrlChanges ( ) ;
9298 }
9399 }
94100
@@ -150,6 +156,18 @@ export class MapGroundOverlay implements OnInit, OnDestroy {
150156 } ) ;
151157 }
152158
159+ private _watchForUrlChanges ( ) {
160+ this . _url . pipe ( takeUntil ( this . _destroyed ) ) . subscribe ( url => {
161+ this . _assertInitialized ( ) ;
162+ const overlay = this . groundOverlay ;
163+ overlay . set ( 'url' , url ) ;
164+
165+ // Google Maps only redraws the overlay if we re-set the map.
166+ overlay . setMap ( null ) ;
167+ overlay . setMap ( this . _map . googleMap ! ) ;
168+ } ) ;
169+ }
170+
153171 private _assertInitialized ( ) : asserts this is { groundOverlay : google . maps . GroundOverlay } {
154172 if ( ! this . _map . googleMap ) {
155173 throw Error (
0 commit comments