I am migrating map markers to AdvancedMarkerElement
And
I want to add custom properties to AdvancedMarkerElement
Like this:
new AdvancedMarkerElement({
map: this.map,
position: data.position,
dataWHD: data.data,
})
This produce following error:
Unknown property 'dataWHD' of AdvancedMarkerElement
How can i do this.
Thanks in advance..
2
Answers
You can’t add custom properties directly to the
AdvancedMarkerElement
.Instead, you can transfer your custom properties via the
AdvancedMarkerElement
content
property so you can build your own markers with whatever data you need.Below is an example from the official documentation.
AdvanceMarkerElement content is HTMLElement so you can use it’s function as Element.setAttribute and then get it with Element.getAttribute
here you have my use case of creating google maps Advance Markers following its documentation:
notice that you can only set string type in
Element.setAttribute
so you’ll need to proccess any other type to string and reverse.