[OpenLayers-Users] Pop-Up Sample Working on Multiple KML Layers
Jeff_Hobbs at sjwater.com
Jeff_Hobbs at sjwater.com
Mon Sep 29 13:16:39 EDT 2008
Hi,
Wanted to send this out again as I never got any replies.
Thanks in advance!
Jeff
----------------------------------------------
Hi,
I'm using the "generic" pop-up sample in my OL application. I have four
KML files on top of a Yahoo backdrop. I'd like to be able to click on any
one of the four KML layers and have a pop-up showing me the respective
attributes. The pop-up sample does this for one layer. Is there a way to
implement for more than one layer? If so, would anybody by chance have
some sample code they could point me to? If not, any suggested
workarounds, perhaps using a conditional with respective check boxes?
I've pasted the pop-up code below for reference.
Thanks in advance to all!
Jeff
=================================
// This is the pop-up logic
selectControl = new
OpenLayers.Control.SelectFeature(map.layers[3], { // Need to get this to
work on multiple layers!
onSelect: onFeatureSelect,
onUnselect: onFeatureUnselect
})
map.addControl(selectControl);
selectControl.activate();
function onPopupClose(evt){
selectControl.unselect(selectedFeature);
}
function onFeatureSelect(feature){
selectedFeature = feature;
popup = new OpenLayers.Popup.FramedCloud("chicken",
feature.geometry.getBounds().getCenterLonLat(), new OpenLayers.Size(100,
100), "<h2>" + feature.attributes.name + "</h2>" + "<h2>" +
feature.attributes.description + "</h2>", null, true, onPopupClose);
popup.border = '1px solid black';
popup.opacity = .8;
popup.autoSize = true;
popup.panMapIfOutOfView = true;
feature.popup = popup;
map.addPopup(popup);
}
function onFeatureUnselect(feature){
map.removePopup(feature.popup);
feature.popup.destroy();
feature.popup = null;
}
More information about the Users
mailing list