Is there a function for a popup ?<br>
<pre>// Interaction; not needed for initial display.
selectControl = new OpenLayers.Control.SelectFeature(layer);
map.addControl(selectControl);
selectControl.activate();
layer.events.on({
'featureselected': onFeatureSelect,
'featureunselected': onFeatureUnselect
});
// 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),
//"<h4>"+feature.attributes.title + "</h4>" + feature.attributes.description,
createPopupForm(), //replacement for previous line and works better for kml file
null, true, onPopupClose);
feature.popup = popup;
popup.feature = feature;
map.addPopup(popup, true);
}
// cutom poup form
function createPopupForm() {
var theHTML = '';
var layerVector = map.layers[1];
var selectedFeature = layerVector.selectedFeatures[0];
var attributeName = selectedFeature.attributes['name'] ? selectedFeature.attributes['name'] : "no name available";
theHTML += '<table style="background-color:#FFFFFF">';
theHTML += '<tr><td align="center" colspan="2"><span style="font-size:14px;font-weight:bold;background-color:#FFFFFF">' + attributeName + '</span><hr></td></tr>' ;
for(var key in selectedFeature.attributes)
{ if(key != "name" && key != "time" && key != "styleUrl")
//theHTML += '<tr><td>' + key + ' :</td><td>' + selectedFeature.attributes[key] + '</td></tr>';
theHTML += '<tr><td><center>' + selectedFeature.attributes[key] + '</td></tr>';
}
theHTML += '</table>';
return theHTML;
}
function onFeatureUnselect(evt) {
feature = evt.feature;
if (feature.popup) {
popup.feature = null;
map.removePopup(feature.popup);
feature.popup.destroy();
feature.popup = null;
}
}</pre>
<br/><hr align="left" width="300" />
View this message in context: <a href="http://osgeo-org.1560.n6.nabble.com/Can-Not-Extract-Attributes-in-KML-File-tp5015176p5015198.html">Re: Can Not Extract Attributes in KML File</a><br/>
Sent from the <a href="http://osgeo-org.1560.n6.nabble.com/OpenLayers-Users-f3910695.html">OpenLayers Users mailing list archive</a> at Nabble.com.<br/>