Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Manage the size of icon using agm-marker

I am trying to apply the css for height and width to icon.

The code which I used for icon with agm-marker is below:-

<agm-marker *ngFor="let m of mapData; let i = index"
    [latitude]="m.lat"
    [longitude]="m.lng"
    [label]="labelOptions"
    [iconUrl]="iconUrl">
</agm-marker>

.ts

public iconUrl = 'http://developerdrive.developerdrive.netdna-cdn.com/wp-content/uploads/2013/08/ddrive.png';

Please let me know how can I manipulate the size of this icon. This is custom icon which I added

like image 976
sah Avatar asked Dec 18 '17 21:12

sah


2 Answers

You can pass an Icon object as parameter to IconURL. Icon has an scaledSize parameter that you can modify. This could be an example:

    icon = {
              url: 'http://developerdrive.developerdrive.netdna-cdn.com/wp-content/uploads/2013/08/ddrive.png',
              scaledSize: {
                width: desiredWidthScale,
                height: desiredHeightScale
              }
}

So you can just use:

<agm-marker *ngFor="let m of mapData; let i = index"
    [latitude]="m.lat"
    [longitude]="m.lng"
    [label]="labelOptions"
    [iconUrl]="icon">
</agm-marker>

Take into account that you are modifying the scale of the image and not the actual size.

like image 60
zolastro Avatar answered Nov 04 '22 15:11

zolastro


To build on zolastro answer. You can feed a google.map.Icon object into the iconUrl attribute of agm-marker. But your compiler may complain about it not being assignable to the expected type "string". To bypass that you can simply encapsulate your icon object into $any

.ts

icon = {
  url: 'http://developerdrive.developerdrive.netdna-cdn.com/wp-content/uploads/2013/08/ddrive.png',
  scaledSize: {
    width: desiredWidthScale,
    height: desiredHeightScale
  }
}

.html

<agm-marker *ngFor="let m of mapData; let i = index"
    [latitude]="m.lat"
    [longitude]="m.lng"
    [label]="labelOptions"
    [iconUrl]="$any(icon)">
</agm-marker>
like image 6
ouvreboite Avatar answered Nov 04 '22 15:11

ouvreboite