component.html:
<google-map (mapClick)="click($event)"
[center]="center" [options]="options" height="500px" width="100%"
[zoom]="zoom">
<map-marker (mapClick)="openInfoWindow(marker)" [clickable]="true"
*ngFor="let marker of markers" [position]="marker.position" [label]="marker.label"
[title]="marker.title" [options]="marker.options">
</map-marker>
<map-info-window>Info Window content</map-info-window>
</google-map>
component.ts:
options: google.maps.MapOptions = {
zoomControl: true,
scrollwheel: false,
disableDoubleClickZoom: true,
maxZoom: 15,
minZoom: 8,
}
I've tried adding icon property with url value in options, passing input in map-marker but none worked
https://github.com/angular/components/tree/master/src/google-maps#readme
Click the name of the pin you've just added on the menu panel on the upper left corner of the web page, and click the paint bucket icon next to it. A small dialog box with a color picker will appear. Click "More Icons" on the box, and a larger dialog box labeled "Choose your icon" will show.
First, create a method that handles the asset path and receives a size (this can be either the width, height, or both, but using only one will preserve ratio). Then, just add it to your map using the right descriptor: final Uint8List markerIcon = await getBytesFromAsset('assets/images/flutter.
As for Angular Google Maps Marker (https://github.com/angular/components/tree/master/src/google-maps/map-marker) documentation, options includes all map-marker
object properties that are not "convenience inputs":
...this component offers an options input as well as convenience inputs for position, title, label, and clickable, and supports all google.maps.Marker events as outputs.
so any other property that's not a "convenience input" has to be passed inside a JSON object like so to each marker object on your array:
const markers =[
{...},
{...},
[{
position:{
lat: 24.1 + ((Math.random() - 0.5) * 2) / 100,
lng: 0.2 + ((Math.random() - 0.5) * 2) / 100,
},
visible: true,
opacity: 0.6,
label: {
color: '#333',
text: 'My Label',
},
title: 'My Title',
options = {
draggable: false,
icon: '../assets/icons/MyMarker.png'
}
}],
{...},
{...}
];
or, at least, it's what has to be inferred until documentation is completed.
Just past this code on your component and fill the ellipsis objects with needed data or just create an array with this structure from your own data.
A little digging into the node-modules of @angular/google-maps I found out the icons should be set in the options of map marker.
<map-marker (mapClick)="openInfoWindow(marker)" [clickable]="true"
*ngFor="let marker of markers" [position]="marker.position" [label]="marker.label"
[title]="marker.title" [options]="marker.options">
</map-marker>
for example the marker property should look like
const markers = [{
position:{
lat: 27 + ((Math.random() - 0.5) * 2) / 10,
lng: 80 + ((Math.random() - 0.5) * 2) / 10,
},
visible: false,
opacity: 0.1,
label: {
color: 'black',
text: 'Marker label ',
},
title: 'Marker title ',
options: {
animation: google.maps.Animation.DROP,
icon: 'https://developers.google.com/maps/documentation/javascript/examples/full/images/beachflag.png'
}
}]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With