Dynamically changing marker icon

5,013 views
Skip to first unread message

Yuvi Panda

unread,
Feb 27, 2012, 9:37:48 AM2/27/12
to leafl...@googlegroups.com
Is it possible to dynamically change a marker's icon? Something like
marker.setOption({icon: i}); ?

The use case I am looking for is this: double tap on marker makes it
draggable(?) and changes icon to differentiate. Double tap again saves
new position.

Suggestions on doing this? Would 'remove marker, use a new marker' be
the only solution?

Thanks!

--
Yuvi Panda T
http://yuvi.in/blog

Vladimir Agafonkin

unread,
Feb 27, 2012, 10:24:25 AM2/27/12
to leafl...@googlegroups.com
Hi,

There's a marker.setIcon(icon) method.

2012/2/27 Yuvi Panda <yuvi...@gmail.com>

Yuvi Panda

unread,
Feb 27, 2012, 10:26:49 AM2/27/12
to leafl...@googlegroups.com
Aha! Wasn't in the docs, but is there in the code :)

Is there a similar method for enabling dragging?

Vladimir Agafonkin

unread,
Feb 27, 2012, 10:31:56 AM2/27/12
to leafl...@googlegroups.com
Yep, I'll add setIcon to the docs. Enabling dragging is documented though. :) marker.dragging.enable()

2012/2/27 Yuvi Panda <yuvi...@gmail.com>

Chris

unread,
Feb 27, 2012, 10:35:20 AM2/27/12
to Leaflet
That doesn't seem to be documented. Can that be sorted out please.

Cheers, Chris

On Feb 27, 3:24 pm, Vladimir Agafonkin <agafon...@gmail.com> wrote:
> Hi,
>
> There's a marker.setIcon(icon) method.
>
> 2012/2/27 Yuvi Panda <yuvipa...@gmail.com>
>
>
>
>
>
>
>
>
>
> > Is it possible to dynamically change a marker's icon? Something like
> > marker.setOption({icon: i}); ?
>
> > The use case I am looking for is this: double tap on marker makes it
> > draggable(?) and changes icon to differentiate. Double tap again saves
> > new position.
>
> > Suggestions on doing this? Would 'remove marker, use a new marker' be
> > the only solution?
>
> > Thanks!
>
> > --
> > Yuvi Panda T
> >http://yuvi.in/blog
>
> --
> Vladimir Agafonkinhttp://agafonkin.com/en

Vannevar Bush

unread,
Jan 12, 2013, 11:02:08 PM1/12/13
to leafl...@googlegroups.com, yuvi...@gmail.com
May I ask a seeming trivial question that I can't get past?
I have a large number of markers, marker001 through marker230. When I try to change just one marker's icon using an off-map link-click such as
onClick="google.maps.marker227.setIcon('pink_Marker.png');return false;"

  I get an error message:
TypeError: google.maps.marker227 is undefined

And yet, Marker227 definitely does exist. I've tried it with various marker numbers, etc.
I can't figure out how to refer to a single marker within the DOM or the google map structure. Any help?
TIA !
Reply all
Reply to author
Forward
0 new messages