Reputation: 23
<agm-map
[zoom]="mapConfig.zoom" [styles]="mapConfig.styles"
[latitude]="currLate" [longitude]="currLongi"
>
<agm-direction *ngIf="path"
[origin]="path.origin"
[destination]="path.destination"
[waypoints]="waypoints"
></agm-direction>
</agm-map>
This is my code for implementing directions using Angular Google maps. I gave origin,destination and array of waypoints, the problem is that when i create new route, both old and new routes stays on the maps. But I want to reset/clear the directions so that i can show only the new direction route on the map.
Upvotes: 1
Views: 1422
Reputation: 2599
Typically when you implement the directions, you'll have a DirectionsRenderer instance (from instantiating a new google.maps.DirectionsRenderer). To attach this to your map, you'll do something like
_directionsRenderer.setMap(this.map)
So to get rid of the directions, you'll need to "unset" the map. Best way to do this is:
_directionsRenderer.setMap(null)
Really, anywhere you have a setMap, any time things update you'll want to setMap(null) on it.
Upvotes: 1