I use OpenLayers with vector layer to display differents item on the map.
On top of that I want to add for each item (a feature) a pop-up (when click on item display the popup). To do that I have :
function initMap()
{
// In this function I add with success the different items to the vectorLayer.
}
function finishMap()
{
map.addLayer(vectorLayer);
selectControl = new OpenLayers.Control.SelectFeature(vectorLayer,
{
onSelect: onFeatureSelect,
onUnselect: onFeatureUnselect
});
map.addControl(selectControl);
selectControl.activate();
}
function onFeatureClose(evt) {
selectControl.unselect(selectedFeature);
}
function onFeatureSelect(feature) {
var popup = new OpenLayers.Popup.FramedCloud("popup",
feature.geometry.getBounds().getCenterLonLat(),
null,
feature.description,
true,
onFeatureClose);
popup.panMapIfOutOfView = true;
popup.autoSize = true;
feature.popup = popup;
map.addPopup(popup);
}
function onFeatureUnselect(feature) {
map.removePopup(feature.popup);
feature.popup.destroy();
feature.popup = null;
}
The call for different function is :
- initMap();
- finishMap();
The problem is : I have only one item (of more than 10) which have a pop-up by clicking on it...