Actually I figured out some problems and corrected it. I declared the overlay just outside the init function. So now I got the 'featureselected' event working properly. But 'featureunselected' event is still not working.

//Vehicle Overlay
      var  vmarkers = new OpenLayers.Layer.Vector("Vehicle Overlay",
                    eventListeners: {
                        'featureselected': function(evt) {
                            var feature = evt.feature;
                            var popup = new OpenLayers.Popup.FramedCloud("popup",
                                    "/*pop up content goes here*/",
                            feature.popup = popup;
                        'featureunselected': function(evt) {
                            var feature = evt.feature;
                            feature.popup = null;
    function init()
        map.addLayers([gmap_streets, gmap_hybrid, vmarkers]);
        selectControl = new OpenLayers.Control.SelectFeature(vmarkers, {
                click: true,
                autoActivate: true

did you already add and activate a SelectControl?

    var selectControl = new OpenLayers.Control.SelectFeature(vmarkers, {});



Apart from that you have one curly bracket too much between your two eventListeners.

  • hi I tried that Jfiddle option but its not working properly. featureSelected is working alternative only. once featureSelected is triggered, featureunSelected has to be triggered. – Pradeesh P Jun 10 '15 at 6:10
  • featureunSelected is triggered every time you have a selcted feature and click somewhere in the map where there is no feature or if you click an other feature.that's normal because the feature that was selected first get's unselected – Thomas B Jun 10 '15 at 7:50
  • OK... I got it. But Now I am stuck with another problem. Actually I am setting all these features from an Ajax function written in separate js file. But when i try to implement the selectControl in the index page I couldn't make it work. When I declare the selectControl.acivate() inside the ajax function, only the featureselect event is getting triggered. Nothing else... :-( – Pradeesh P Jun 10 '15 at 9:40
  • could you set up a jsfiddle or post more code to get an idea what's the problem? Just a sidenote: "out.println" looks like java syntax what couldn't work here. do you still use this in your app? – Thomas B Jun 10 '15 at 10:29
  • I updated the question itself. I am new to gisStackexchange and fiddle too. I don't know how to update the qstn through comment box. sorry. and in the case of fiddle I have some external js files that styles the feature in the vector layer and plot the features. – Pradeesh P Jun 10 '15 at 14:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.