[GIS] How to change a marker on click with OpenLayers 2

javascriptopenlayers-2

I've created a map and tried, but it doesn't change until another event is caught or zooming map or by switching the browser tabs. What is the reason for this?

Please help me, I've fiddled the code here http://jsfiddle.net/HMFLf/.

This is what I've done to change marker:

vectorLayer.events.on({
                featureselected: function (event) {
                    var fixer = confirm("Are you want to change clolor this marker");
                    if (fixer == true) {
                        size = new OpenLayers.Size(21, 25);
                        event.feature.style = { externalGraphic: "http://www.openlayers.org/dev/img/marker.png", graphicHeight: 25, graphicWidth: 21, graphicXOffset: -((size.w / 2) - 2), graphicYOffset: -(size.h - 2) };
                    }                    
                }
            });

Best Answer

You need to call the redraw method after changing the style.

And you are close. Redraw gets called for you when you zoom, but you have to force it manually when changing style or feature properties.