agm-marker iconUrl change on click of marker

吃可爱长大的小学妹 提交于 2019-12-25 17:48:22

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!