Я работаю над картой OpenLayers, которая будет отображать несколько слоев KML одновременно. Я хочу иметь возможность щелкнуть объект на любом слое, и всплывающее окно покажет мне некоторую информацию. Пока я могу щелкнуть только по последнему добавленному слою. Если я хочу щелкнуть по ранее добавленному слою, мне нужно отключить все слои, которые были добавлены ранее. Очевидно, это далеко не идеально. Вот мой код на данный момент:
var select = [];
function addLayer(layerId, layerLink, layerColor)
{
var kmlLayer = new OpenLayers.Layer.Vector("Layer_"+layerId, {
strategies: [new OpenLayers.Strategy.Fixed()],
protocol: new OpenLayers.Protocol.HTTP({
url: layerLink,
format: new OpenLayers.Format.KML({
extractStyles: true,
extractAttributes: true,
maxDepth: 2
})
})
});
kmlLayer.events.on({
"featureselected": onKMLSelect,
"featureunselected": onKMLUnselect
});
select["Layer_"+layerId] = new OpenLayers.Control.SelectFeature(kmlLayer);
map.addControl(select["Layer_"+layerId]);
select["Layer_"+layerId].activate();
map.addLayer(kmlLayer);
}
function onKMLPopupClose(evt) {
for(s in select)
{
select[s].unselectAll();
}
}
function onKMLSelect(event) {
var feature = event.feature;
var content = "<h2>"+feature.attributes.name + "</h2>" + feature.attributes.description;
popup = new OpenLayers.Popup.FramedCloud("chicken",
feature.geometry.getBounds().getCenterLonLat(),
new OpenLayers.Size(100,100),
content,
null, true, onKMLPopupClose);
feature.popup = popup;
map.addPopup(popup);
}
function onKMLUnselect(event) {
var feature = event.feature;
if(feature.popup) {
map.removePopup(feature.popup);
feature.popup.destroy();
delete feature.popup;
}
}
Любая помощь будет принята с благодарностью. Спасибо,