hello,
the popup will not open if all the layers are active, why?
if active layers 2 is ok, but 3 does not work ??!
<script src="OpenLayers.js"></script>
<script type="text/javascript" src="OpenStreetMap.js"></script>
<script type="text/javascript">
var map;
var lon =9.19;
var lat =45.46;
var zoom =10;
function init(){
map = new OpenLayers.Map("map", {
controls: [
new OpenLayers.Control.Navigation(),
new OpenLayers.Control.LayerSwitcher()
]
});
layerMapnik = new OpenLayers.Layer.OSM.Mapnik("Mapnik");
layerMapnik.setOpacity(0.4);
map.addLayer(layerMapnik);
var newLayer = new OpenLayers.Layer.OSM("Mappa locale", "tiles/${z}/${x}/${y}.png", {numZoomLevels: 19, alpha: true, isBaseLayer: false});
map.addLayer(newLayer);
// Layer Sedi
var layer_sedi = new OpenLayers.Layer.Vector("Sedi libere", {
strategies: [new OpenLayers.Strategy.BBOX({resFactor: 1.1})],
protocol: new OpenLayers.Protocol.HTTP({
url: "./geco_sedi.txt",
format: new OpenLayers.Format.Text()
})
});
map.addLayer(layer_sedi);
// Interaction; not needed for initial display.
selectControl = new OpenLayers.Control.SelectFeature(layer_sedi);
map.addControl(selectControl);
selectControl.activate();
layer_sedi.events.on({
'featureselected': onFeatureSelect,
'featureunselected': onFeatureUnselect
});
// End Layer Sedi
// Layer Stazionamenti
var layer_stazionamenti = new OpenLayers.Layer.Vector("Stazionamenti liberi", {
strategies: [new OpenLayers.Strategy.BBOX({resFactor: 1.1})],
protocol: new OpenLayers.Protocol.HTTP({
url: "./geco_stazionamenti.txt",
format: new OpenLayers.Format.Text()
})
});
map.addLayer(layer_stazionamenti);
// Interaction; not needed for initial display.
selectControl = new OpenLayers.Control.SelectFeature(layer_stazionamenti);
map.addControl(selectControl);
selectControl.activate();
layer_stazionamenti.events.on({
'featureselected': onFeatureSelect,
'featureunselected': onFeatureUnselect
});
// End Layer Stazionamenti
// Layer Mezzi Disponibili
var layer_mezzidisponibili = new OpenLayers.Layer.Vector("Mezzi disponibili", {
strategies: [new OpenLayers.Strategy.BBOX({resFactor: 1.1})],
protocol: new OpenLayers.Protocol.HTTP({
url: "./geco_mezzidisponibili.txt",
format: new OpenLayers.Format.Text()
})
});
map.addLayer(layer_mezzidisponibili);
// Interaction; not needed for initial display.
selectControl = new OpenLayers.Control.SelectFeature(layer_mezzidisponibili);
map.addControl(selectControl);
selectControl.activate();
layer_mezzidisponibili.events.on({
'featureselected': onFeatureSelect,
'featureunselected': onFeatureUnselect
});
// End Layer Mezzi Disponibili
if( ! map.getCenter() ){
var lonLat = new OpenLayers.LonLat(lon, lat).transform(new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject());
map.setCenter (lonLat, zoom);
}
}
// Needed only for interaction, not for the display.
function onPopupClose(evt) {
// 'this' is the popup.
var feature = this.feature;
if (feature.layer) { // The feature is not destroyed
selectControl.unselect(feature);
} else { // After "moveend" or "refresh" events on POIs layer all
// features have been destroyed by the Strategy.BBOX
this.destroy();
}
}
function onFeatureSelect(evt) {
feature = evt.feature;
popup = new OpenLayers.Popup.FramedCloud("featurePopup",
feature.geometry.getBounds().getCenterLonLat(),
new OpenLayers.Size(100,100),
"<h2>"+feature.attributes.title + "</h2>" +
feature.attributes.description,
null, true, onPopupClose);
feature.popup = popup;
popup.feature = feature;
map.addPopup(popup, true);
}
function onFeatureUnselect(evt) {
feature = evt.feature;
if (feature.popup) {
popup.feature = null;
map.removePopup(feature.popup);
feature.popup.destroy();
feature.popup = null;
}
}
</script>