Reputation: 9084
I am building a vehicle tracking application and i am using agm-map-marker to display the vehicles that were located like this in the image,
And Livetracking.component.html code is,
<agm-map #gm [latitude]="lat" [longitude]="lng" [(zoom)]="zoom" [mapTypeControl]="true">
<agm-marker class="mapMarker" *ngFor="let device of devices;"
[latitude]="device.latitude" [longitude]="device.longitude"
(markerClick)="gm.lastOpen?.close(); gm.lastOpen = infoWindow;mapMarkerInfo(m);">
</agm-marker>
</agm-map>
Here i need to replace the marker into arrows, exactly as like in this image,
I am in the need of changing the marker to arrow as like in the second image..Kindly help me to achieve the desired result..
Upvotes: 16
Views: 33682
Reputation: 1
You just have to add iconUrl object in html file.
<agm-marker
[latitude]="latitude"
[longitude]="longitude"
[markerDraggable]="true"
(dragEnd)="markerDragEnd($event)"
[iconUrl]="iconUrl" >
</agm-marker>
In ts file you have to add this:
public iconUrl = "http://maps.google.com/mapfiles/ms/icons/red-dot.png";
Upvotes: 0
Reputation: 1518
You have to include agm-overlays in project then you can draw overly and it also provide support to add custom div on map.
<agm-overlay
*ngFor="let driver of driversList"
[latitude]="driver.latitude"
[longitude]="driver.longitude"
>
<div>
<img
style="cursor: pointer;"
[ngClass]="{
online: driver.status === 'online',
offline: driver.status === 'offline'
}"
src="{{
driver.profileImageURL
}}"
/>
</div>
</agm-overlay>
Add this in css file
.online { border: 3px solid black }
Upvotes: 3
Reputation: 716
The accepted answer will not work because those aren't properties of the agm-marker
.
Inside iconUrl
property you can use any of these types:
string
Icon
: https://developers.google.com/maps/documentation/javascript/reference/3.exp/marker#Icon
Symbol
: https://developers.google.com/maps/documentation/javascript/reference/3.exp/marker#Symbol
For example, to use a custom image marker (SVG in this case) with desired size you can use this object in the [iconUrl]
property:
{
url: './assets/images/blue-marker.svg',
scaledSize: {
width: 40,
height: 60
}
}
Upvotes: 26
Reputation: 222710
You can use the existing api and set the iconUrl
<agm-marker
[latitude]="location.latitude"
[longitude]="location.longitude"
[iconAnchorX]="10"
[iconAnchorY]="10"
[iconHeight]="20"
[iconWidth]="20">
[iconUrl]="location.icon">
</agm-marker>
Upvotes: 14