Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to change openlayers marker icon?

Tags:

map

openlayers

I am using Openlayers to my application.

i have succeeded in showing marker when i click on the map, but now i want to change the marker icon when i click on that, how to do this. I didn't find any method like marker.setIcon();

i am really confusing here.

map.events.register("click", map , function(e){
   var opx = map.getLonLatFromPixel(e.xy) ;
   var marker = new OpenLayers.Marker(opx);
   markers.addMarker(marker);
   marker.events.register("click", marker, function(e){
    //here i want to change the icon to some other 
    popup = new OpenLayers.Popup.FramedCloud("chicken",
                         marker.lonlat,
                         new OpenLayers.Size(200, 200),
                         "example popup",
                         null, true);

     map.addPopup(popup);
       }); 
    // here i want to change to default.
  });
like image 707
Ramesh Kotha Avatar asked Dec 13 '22 03:12

Ramesh Kotha


1 Answers

The documentation at OpenLayers 2:

http://dev.openlayers.org/docs/files/OpenLayers/Marker-js.html

mentions the method setUrl to set the icon image. This should work:

marker.setUrl('marker.png');
like image 99
jjrv Avatar answered Feb 19 '23 08:02

jjrv