[OpenLayers-Users] Getting attributes from a Feature-Layer

Kai Behncke Kai-Behncke at gmx.de
Tue Mar 3 11:38:05 EST 2009


Dear list,


I haven`t got any clue why in that case it was not possible to get to run someting like:

var myFeature=myWfsLayer.getFeatureById(feature.id);
alert (myFeature.attributes.gid);
or e.g. alert (myFeature.data.name)....


but never mind, I found another solution:


In my UMN MS-WFS I wrote
"gml_featureid" "objekt_id" to get the database-Id of the feature.

In the OL-File I wrote:

var objekt_id=myFeature.fid;
objekt_id=objekt_id.split(".");
objekt_id=objekt_id[1];

With that information a Ajax-Request is sent to a php-file where a database-query is started. These results occur then in the popup.

Best regards and thank you again for the help, Kai

Here the code:

---------------------

var gastronomap_wfs= new OpenLayers.Layer.WFS( "small_wfs",
  "http://www.xyz.de/cgi-bin/mapserv?map=/home/etc/etc/gastronomap_wfs.map",
   {Typename: 'gastronomie_wfs', maxfeatures: 100, extractAttributes:true}
); 

            map.addLayers([gsat,gastronomap_wfs]);
            map.addControl(new OpenLayers.Control.LayerSwitcher());
        
    gastro = new OpenLayers.Control.SelectFeature(gastronomap_wfs, {
        callbacks: {
            'over': function()
            {
               
              
               feature_info_hover(arguments[0], gastronomap_wfs);
            }
        }
    });
    
   //-----------------------------------------Second Ajax-Request 

var resObjekt;
if (navigator.appName.search("Microsoft") > -1) {

//resObjekt = new ActiveXObject("Microsoft.XMLHTTP");
resObjekt = new ActiveXObject("MSXML2.XMLHTTP");
}
else {
resObjekt= new XMLHttpRequest();}

function sndReq(wert) {

alert (wert);

resObjekt.open('get','test.php?wo='+wert,true);
resObjekt.onreadystatechange = handleResponse;
resObjekt.send(null);



}

function handleResponse(){

if (resObjekt.readyState == 4){
document.getElementById("test").innerHTML= resObjekt.responseText;
}
}
//---------------------------------------------------------------   
    
    function feature_info_hover(feature, myWfsLayer)
{



var myFeature=myWfsLayer.getFeatureById(feature.id);

if (myFeature)
    {


var objekt_id=myFeature.fid;
objekt_id=objekt_id.split(".");
objekt_id=objekt_id[1];
 sndReq(objekt_id); 
 var window_position = new OpenLayers.LonLat(myFeature.geometry.x, myFeature.geometry.y);
         this.popup = new OpenLayers.Popup("ol-info-popup", window_position, null, '<div ><span>' + 
"Objekt id: " + objekt_id + '</span><br></div><div id="test"></div>', false);

         this.popup.autoSize = true;
         map.addPopup(this.popup, true);
         
this.autodestroy = window.setTimeout(function()
        {
            if (map && map.popups && map.popups.length > 0)
             {
                var len = map.popups.length;
                 for (var i = 0; i < len; i++)
                {
                    if (map.popups[i] && map.popups[i].destroy)
                     {
                         map.popups[i].destroy();
                    }
                }
            }
         }, 3000);
   
    }




}
 map.addControl(gastro);
    gastro.activate();







-------- Original-Nachricht --------
> Datum: Tue, 03 Mar 2009 13:10:45 +0100
> Von: "Kai Behncke" <Kai-Behncke at gmx.de>
> An: users at openlayers.org
> Betreff: [OpenLayers-Users] Getting attributes from a Feature-Layer

> Dear list,
> 
> 
> I have loaded a couple of Features from a WFS (stored in PostGIS) as a
> layer.
> I can get the internal feature.id  (myWfsLayer.getFeatureById(feature.id)
> of each feature as well as the geometry.
> 
> But I wonder how I can get the attributes (e.g. name, gid etc.) of that
> layer?
> 
> I´m thinking about sending a HttpRequest to a server with a php-File that
> gives as response the result like (SELECT name, gid from xyz where
> the_geom= feature.geometry).
> 
> I´m pretty sure that this won`t be the most elegant way.
> Is there another way how to get the attributes of a feature?
> 
> Thank you very much, Kai
> -- 
> Computer Bild Tarifsieger! GMX FreeDSL - Telefonanschluss + DSL
> für nur 17,95 ¿/mtl.!* http://dsl.gmx.de/?ac=OM.AD.PD003K11308T4569a
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users

-- 
Psssst! Schon vom neuen GMX MultiMessenger gehört? Der kann`s mit allen: http://www.gmx.net/de/go/multimessenger01



More information about the Users mailing list