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.
});
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');
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