[OpenLayers-Users] Pop-Up Sample Working on Multiple KML Layers

Jeff_Hobbs at sjwater.com Jeff_Hobbs at sjwater.com
Wed Sep 24 14:20:45 EDT 2008


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;
                }

 
 
--------------------------------
Jeff Hobbs
GIS Coordinator
San Jose Water Company (NYSE:SJW)
1265 South Bascom Avenue
San Jose, CA 95128
Voice - (408) 279-7833
Cell - (408) 314-6342
Fax - (408) 279-7889
jeff_hobbs at sjwater.com
http://www.sjwater.com



More information about the Users mailing list