jbdemonte / gmap3

jQuery plugin to create Google maps
http://gmap3.net
668 stars 198 forks source link

Change icon of specyfic marker #88

Closed pawelbrachaczek closed 8 years ago

pawelbrachaczek commented 8 years ago

Hi,

How can I change the icon of a specyfic marker?

I tried like this, but old icon dosn't dissapear:

$map.gmap3().marker({ position: [selecledMarker.lat, selecledMarker.lng] }).then(function(marker){ if(marker.icon == "/assets/img/pin-on.png"){ marker.setIcon("/assets/img/pin.png"); } });

jbdemonte commented 8 years ago

did you tried an absolute path?

pawelbrachaczek commented 8 years ago

How to do it?

jbdemonte commented 8 years ago

marker.setIcon("http://yourdomain.com/.../assets/img/pin.png");

pawelbrachaczek commented 8 years ago

Paths to images are correct. New icon is visible, but old icon not dissapar (it's bigger). So there are two icons in the same place.

jbdemonte commented 8 years ago

I never saw this kind of problem with google maps, I guess, you're creating another marker instead of updating one existing. Can you provide a piece of your code

pawelbrachaczek commented 8 years ago

Yes, probably I was creating a new marker in the same place. I fixed it like that:

for(var i=0; i < markersLength; i++){ if($map.gmap3().get(i).icon == "/assets/img/pin-on.png"){ $map.gmap3().get(i).setIcon("/assets/img/pin.png"); } }