问题
I am trying to change the iconUrl of marker when it is clicked . I am using angular google maps. iconUrl I am setting using my local assets folder and not from service API.
<agm-marker *ngFor="let m of mapArrayList; let i = index" (markerClick)="clickedMarker(infowindow)"
[latitude]="m.geometry.location.lat()" [longitude]="m.geometry.location.lng()"
[iconUrl] ="
{
url: './assets/images/car.svg',
scaledSize: {
width: 40,
height: 60
}
}">
How can I change the above iconUrl when a marker is clicked.
回答1:
You could have a property on your array objects to know which state your object has. You would need to update this property from markerClick
event. I used isClicked
property on this example.
In this case you could check which SVG is needed to be loaded.
<agm-marker *ngFor="let m of mapArrayList; let i = index" (markerClick)="clickedMarker(infowindow)"
[latitude]="m.geometry.location.lat()" [longitude]="m.geometry.location.lng()"
[iconUrl] ="
{
url: m.isClicked ? './assets/images/car.svg' : './assets/images/bike.svg',
scaledSize: {
width: 40,
height: 60
}
}">
来源:https://stackoverflow.com/questions/52817841/agm-marker-iconurl-change-on-click-of-marker