[OpenLayers-Users] ***** SPAM ***** problem to obtain the field value

bartvde at osgis.nl bartvde at osgis.nl
Thu Dec 4 10:51:49 EST 2008


Hi,

you might want to have a look at:

http://trac.openlayers.org/ticket/1812

After applying the patch you can do something like:

function setHTML(response) {
        var format = new OpenLayers.Format.WMSGetFeatureInfo();
        var features = format.read(response.responseXML ||
response.responseText);
}

and you'll get an array of OpenLayers.Feature.Vector which have an
attributes property. See example below how to access that.

But since you are using Geoserver, you can do something like (no need to
apply the patch in this case);

function setHTML(response) {
        var format = new OpenLayers.Format.GML();
        var features = format.read(response.responseXML ||
response.responseText);
         for (var i=0, len=features.length; i<len; i++) {
                var feature = features[i];
                for (attribute in feature.attributes) {
                    var value = feature.attributes[attribute];
                    console.log(attribute + ": " + value);
                }
          }
}

* code untested *

Hope this helps.

Best regards,
Bart

>
>
>
> Hi, I continue with problems to obtain value for some field of the my
> layer I attached a part of my code and image of the result.
>
> I like show in the windows form the value of the some field.
>
> .  function setHTML(response) {
>       document.getElementById('texto').innerHTML =response.responseText;
>
>        // var XMLformat = new OpenLayers.Format.XML();
>     // var xml;
>           // xml = XMLformat.read(response.responseText);
>          //  var PCode = xml.getElementsByTagName('parcela');
>          //  var primerParrafo = PCode[0];
>
>        // document.getElementById('texto').innerHTML =primerParrafo;
>         };
>
>     // support GetFeatureInfo
>             map.events.register('click', map, function (e) {
>                // document.getElementById('nodelist').innerHTML =
> "Cargando... por favor espere...";
>              var url =  map.layers[0].getFullRequestString(
>                     {
>                         REQUEST: "GetFeatureInfo",
>                         EXCEPTIONS: "application/vnd.ogc.se_xml",
>                         BBOX: map.getExtent().toBBOX(),
>                         X: e.xy.x,
>                         Y: e.xy.y,
>                         INFO_FORMAT: 'application/vnd.ogc.xml',
>                         QUERY_LAYERS: map.layers[0].params.LAYERS,
>                         FEATURE_COUNT: 50,
>                         WIDTH: map.size.w,
>                         HEIGHT: map.size.h
>                     },
>                     "http://localhost:8080/geoserver/wfs"
>                 );
>
>             OpenLayers.loadURL(url, '', this, setHTML, setHTML);
>
> Any help would be greatly appreciated,
>
> Salas
>
>
>
>
> ___________________________________
> Dpto de Sistemas Informáticos
> Oficina Central Grupo Empresarial GEOCUBA
> Este mensaje esta libre de virus.
> Revisado por Kaspersky Antivirus
> ----------------------------------------------------------------------
> Engine version:  4.0.1.14
> Engine date:  2002/06/25
> Definition count:  1282274
> Definition date:  2008/12/02
> MDAV version: 2.2.8
>
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
>





More information about the Users mailing list