I am using OpenLayers 2.
I have a map with points from GeoJSON file. I created a default style and a select style for these points. I created a popup with attributes from GeoJSON when clicking on a point. All works fine, except that I can't close the popup: the point is unselected, but the popup still remains even if I use the red cross. I read this post that seems to deal with the same issue, but I can't use it in my application.
code for popup :
selection = new OpenLayers.Control.SelectFeature(operationCentroide);
operationCentroide.events.on({
"featureselected": monpopup,
"featureunselected": onFeatureUnselect
});
map.addControl(selection);
selection.activate();
function onPopupClose(evt) {
selection.unselectAll();
}
function monpopup(event) {
var feature = event.feature;
var contenu = feature.attributes.numope;
popup = new OpenLayers.Popup.FramedCloud("chicken",
feature.geometry.getBounds().getCenterLonLat(),
new OpenLayers.Size(100,100),
contenu,
null, true, onPopupClose);
map.addPopup(popup);
}
function onFeatureUnselect(event) {
var feature = event.feature;
if(feature.popup) {
map.removePopup(feature.popup);
feature.popup.destroy();
delete feature.popup;
}
}