Skip to content

Commit cc618b4

Browse files
committed
fix(google-maps): advanced marker not destroyed
Fixes that the advanced marker wasn't being removed from the map on destroy. Fixes #28609.
1 parent 5269e0f commit cc618b4

File tree

3 files changed

+36
-8
lines changed

3 files changed

+36
-8
lines changed

src/dev-app/google-map/google-map-demo.html

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,25 @@
2020
(mapClick)="clickMarker(marker)"></map-marker>
2121
}
2222
</map-marker-clusterer>
23-
<map-advanced-marker
24-
#secondMarker="mapAdvancedMarker"
25-
(mapClick)="clickAdvancedMarker(secondMarker)"
26-
title="Advanced Marker"
27-
[gmpDraggable]="false"
28-
[position]="mapAdvancedMarkerPosition"
29-
></map-advanced-marker>
23+
@if (hasAdvancedMarker) {
24+
<map-advanced-marker
25+
#secondMarker="mapAdvancedMarker"
26+
(mapClick)="clickAdvancedMarker(secondMarker)"
27+
title="Advanced Marker"
28+
[gmpDraggable]="false"
29+
[content]="advancedMarkerContent"
30+
[position]="mapAdvancedMarkerPosition">
31+
32+
<svg #advancedMarkerContent fill="oklch(69.02% .277 332.77)" viewBox="0 0 960 960" width="50px" height="50px" xml:space="preserve">
33+
<g>
34+
<polygon points="562.6,109.8 804.1,629.5 829.2,233.1 "/>
35+
<polygon points="624.9,655.9 334.3,655.9 297.2,745.8 479.6,849.8 662,745.8 "/>
36+
<polygon points="384.1,539.3 575.2,539.3 479.6,307 "/>
37+
<polygon points="396.6,109.8 130,233.1 155.1,629.5 "/>
38+
</g>
39+
</svg>
40+
</map-advanced-marker>
41+
}
3042
<map-info-window>Testing 1 2 3</map-info-window>
3143
@if (isPolylineDisplayed) {
3244
<map-polyline [options]="polylineOptions"></map-polyline>
@@ -194,6 +206,13 @@
194206
</label>
195207
</div>
196208

209+
<div>
210+
<label>
211+
Toggle Advanced Marker
212+
<input type="checkbox" (click)="toggleAdvancedMarker()">
213+
</label>
214+
</div>
215+
197216
<div>
198217
<button mat-button (click)="calculateDirections()">
199218
Calculate directions between first two markers

src/dev-app/google-map/google-map-demo.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export class GoogleMapDemo {
8989
@ViewChild(MapCircle) circle: MapCircle;
9090

9191
center = {lat: 24, lng: 12};
92-
mapAdvancedMarkerPosition = {lat: 24, lng: 16};
92+
mapAdvancedMarkerPosition = {lat: 22, lng: 21};
9393
markerOptions = {draggable: false};
9494
markerPositions: google.maps.LatLngLiteral[] = [];
9595
zoom = 4;
@@ -145,6 +145,7 @@ export class GoogleMapDemo {
145145
isTrafficLayerDisplayed = false;
146146
isTransitLayerDisplayed = false;
147147
isBicyclingLayerDisplayed = false;
148+
hasAdvancedMarker = false;
148149

149150
mapTypeId: google.maps.MapTypeId;
150151
mapTypeIds = ['hybrid', 'roadmap', 'satellite', 'terrain'] as google.maps.MapTypeId[];
@@ -264,6 +265,10 @@ export class GoogleMapDemo {
264265
this.isBicyclingLayerDisplayed = !this.isBicyclingLayerDisplayed;
265266
}
266267

268+
toggleAdvancedMarker() {
269+
this.hasAdvancedMarker = !this.hasAdvancedMarker;
270+
}
271+
267272
calculateDirections() {
268273
if (this.markerPositions.length >= 2) {
269274
const request: google.maps.DirectionsRequest = {

src/google-maps/map-advanced-marker/map-advanced-marker.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,10 @@ export class MapAdvancedMarker implements OnInit, OnChanges, OnDestroy {
225225
ngOnDestroy() {
226226
this.markerInitialized.complete();
227227
this._eventManager.destroy();
228+
229+
if (this.advancedMarker) {
230+
this.advancedMarker.map = null;
231+
}
228232
}
229233

230234
/** Creates a combined options object using the passed-in options and the individual inputs. */

0 commit comments

Comments
 (0)