[OpenLayers-Users] Firefox - popup feature attribute "undefined"

mbjorge minika.bjorge at statkart.no
Tue Dec 8 03:52:53 EST 2009


I am a newbie to OpenLayers and I have followed the KML example. I have spent
hours searching through previous posts for an answer.

Firefox and Opera:  The pop up works on Firefox but only displays the name.
The description displays "undefined". <br />
IE :both  the "name" and "description text appears.

You can see it here 
http://www.sjokart.no/admin/filestore/Sjkartverket/kml/test/testKMLPopGML.html
my kml test 

Here's my code:


var lon = 11.8;
      var lat = 64.5;
      var zoom = 5;
      var map, layer, gmap, kmlLayer, selectControl;

    function init(){
        map = new OpenLayers.Map('map');
        layer = new OpenLayers.Layer.WMS( "OpenLayers WMS",
                    "http://labs.metacarta.com/wms/vmap0", {layers:
'basic'}, {isBaseLayer: true});		
	map.addLayer(layer);		
	map.addControl(new OpenLayers.Control.LayerSwitcher());		
		
        kmlLayer = new OpenLayers.Layer.GML("KML",
"http://www.sjokart.no/admin/filestore/Sjkartverket/kml/vannstandstasjoner2.kml", 
        {
            format: OpenLayers.Format.KML, 
            formatOptions: {
              extractStyles: true, 
              extractAttributes: true,
	  maxDepth: 2
            }
			
         });
	 map.addLayer(kmlLayer);
	 map.setCenter(new OpenLayers.LonLat(lon, lat), zoom);         
		 
	 selectControl = new OpenLayers.Control.SelectFeature(kmlLayer);
		 
	 kmlLayer.events.on({
                "featureselected": onFeatureSelect,
                "featureunselected": onFeatureUnselect
         });

	 map.addControl(selectControl);
         selectControl.activate();  
		 
	 function onPopupClose(evt) {
	 selectControl.unselectAll();
	 }
		 
	function onFeatureSelect(event) {
	var feature = event.feature;
	var detail = feature.attributes['description']; 
	var content = "<div style='font-size:.8em; width:120px;'><strong>"+
feature.attributes.name + "</strong><hr />" + detail + "</div>";
            
            popup = new OpenLayers.Popup.FramedCloud("chicken", 
                   feature.geometry.getBounds().getCenterLonLat(),
                   new OpenLayers.Size(100,100),
                   content,
                   null, true, onPopupClose);
           popup.border = '1px solid black';
            popup.opacity = .7;            
            popup.panMapIfOutOfView = true; 
			
            feature.popup = popup;			
            map.addPopup(popup);
	    }
		
	function onFeatureUnselect(event) {
	 var feature = event.feature;
	    if(feature.popup) {
	      map.removePopup(feature.popup);
	      feature.popup.destroy();
	      delete feature.popup;
		}
	 } 
		 
}



This is my kml code:


<?xml version="1.0"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
 <Document>
   <name>Vannstandsm&#229;lere</name>
   <open>1</open>
   <Style id="neither">
      <IconStyle>
        <Icon>
          <href>http://maps.google.com/mapfiles/ms/icons/red-dot.png</href>
        </Icon>
      </IconStyle>
   </Style>
   <Style id="gloss">
      <IconStyle>
	<Icon>
	   <href>http://maps.google.com/mapfiles/ms/icons/blue-dot.png</href>
	</Icon>		
      </IconStyle>
   </Style>
   <Style id="both">
      <IconStyle>
	<Icon>
	  <href>http://maps.google.com/mapfiles/ms/icons/orange-dot.png</href>
	</Icon>		
      </IconStyle>
   </Style>  
   <Placemark>
     <name>Andenes</name>	   
     <description><![CDATA[
http://www.sjokart.no/admin/filestore/Sjkartverket/kml/bilder/Andenes_small.jpg
<p style="text-align: left; float: right; width: 300px;">Lokalitet:<br />
Breddegrad: 69&#176;19' N.<br>Lengdegrad: 16&#176;09' E.<br /><br
/>Vannstandsm&#229;leren er plassert p&#229; trafikk- og allmenningskai,
ikke langt fra And&#248;y Havnevesen (Hamnegata 71).<br><br>
http://vannweb/joomla/index.php?option=com_content&view=article&Itemid=73&id=88%3Avannstandsmalere-andenes
Les mer </p>]]>  
     </description>
     <styleUrl>#both</styleUrl>
     <Point>
       <coordinates>16.133909,69.326158</coordinates>
     </Point>
   </Placemark>
   <Placemark>
     <name>Bergen</name>	   
     <description><![CDATA[
http://www.sjokart.no/admin/filestore/Sjkartverket/kml/bilder/Bergen_small.jpg
<p style="text-align: left; margin-left: 4px; float: right; width:
300px;">Lokalitet: <br />Breddegrad: 60&#176;24' N.<br>Lengdegrad:
05&#176;18' E.<br /><br />Vannstandsm&#229;leren er plassert mellom
Bradbenken og Dreggekaien i V&#229;gen i Bergen sentrum.<br><br>
http://vannweb/joomla/index.php?option=com_content&view=article&Itemid=73&id=87%3Avannstandsmalere-bergen
Les mer </p>]]>  
     </description>
     <styleUrl>#neither</styleUrl>
     <Point>
       <coordinates>5.320493,60.398053</coordinates>
     </Point>
   </Placemark>
</Document>
</kml>


Any help would be appreciated.:-(

Thanks


-- 
View this message in context: http://n2.nabble.com/Firefox-popup-feature-attribute-undefined-tp4131261p4131261.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.



More information about the Users mailing list