单击标记时 agm-marker iconUrl 更改

agm-marker iconUrl change on click of marker

我试图在单击时更改标记的 iconUrl。我正在使用 angular google 地图。 iconUrl 我正在使用我的本地资产文件夹而不是来自服务 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
        }
    }">

如何在单击标记时更改上面的 iconUrl。

您可以在数组对象上设置 属性 以了解您的对象处于哪种状态。您需要从 markerClick 事件更新此 属性。我在这个例子中使用了 isClicked 属性。

在这种情况下,您可以检查需要加载哪个 SVG。

<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
    }
}">