[OpenLayers-Users] gml and attributes
Francesco Geri
francescogeri at yahoo.it
Mon Apr 16 10:43:51 EDT 2012
Yes. Thanks for the answer. This is an extract of the code.
puntigml = new OpenLayers.Layer.GML("Specimens", "/gis/GeoLayer.gml",{projection: new OpenLayers.Projection("EPSG:4326")});
map.addLayer(puntigml);
select_feature_control =new OpenLayers.Control.SelectFeature(
puntigml,
{
multiple: false,
toggle: true,
multipleKey: 'shiftKey',
toggleKey: 'ctrlKey',
box: true
}
);
map.addControl(select_feature_control);
function selezione_elemento(event) {
//info record
var tipo=event.feature.attributes.type;// comment#1
var collect=event.feature.attributes.place.name; //comment#2
var famiglia=event.feature.attributes.family;
var specie=event.feature.attributes.species;
document.getElementById('tipo').innerHTML=tipo;
document.getElementById('collection').innerHTML=collect;
}
puntigml.events.register('featureselected', this, selezione_elemento);
This is an example of my gml file
<gml:featureMember>
<gml:Specimens>
<type>herbaria</type> // comment#1
<species>Quercus cerris L.</species>
<place>
<name>Valle di Copogna-Monte Lago</name> //comment #2
<town>Serravalle di Chienti</town>
<province>Macerata</province>
<region>Marche</region>
<country>Italia</country>
</place>
<ogr:geometryProperty>
<gml:Polygon srsName="EPSG:4326">
<gml:outerBoundaryIs>
<gml:LinearRing>
<gml:coordinates>12.916666749999999,43.100000000000001 13,43.100000000000001 13,43.149999999999999 12.916666749999999,43.149999999999999 12.916666749999999,43.100000000000001</gml:coordinates></gml:LinearRing>
</gml:outerBoundaryIs>
</gml:Polygon>
</ogr:geometryProperty>
</gml:Specimens>
</gml:featureMember>
When I try to access to a first order node like <type> or <species> the selection function works (look comment #1) but when I try to access to a subtag doesn't extract any information and the firebug result is
event.feature.place is undefined - var collect=event.feature.place.name;
Thanks again,
Francesco
________________________________
Da: Pierre Stévens <pieside at gmx.com>
A: Francesco Geri <francescogeri at yahoo.it>
Inviato: Lunedì 16 Aprile 2012 16:12
Oggetto: Re: [OpenLayers-Users] gml and attributes
Hello,
"event.feature.field1.field2" is normally the right way to access to
attribute "field2".
1. Check if "field2" is correctly written.
2. It can be other thing
Can you give us the real lines (not with <field1><field2>...</field1>)?
It can help more.
Le lun 16 avr 2012 15:51:32 CEST, Francesco Geri a écrit :
> Hello,
> I have some problems whie I try to access to the attributes of gml
> file stored in subtag. Normally when I use the
> event.feature.attributes.field1 I can extract the attributes stored in
> the node "field1". But when I have a situation like this
>
> <field1>
> <field2>
> information
> </field2>
> </field1>
>
> How I can access to the field2 node? I try with
> event.feature.field1.field2 but I obtain an undefined value.
>
> thanks to all,
>
>
> Francesco
>
>
> _______________________________________________
> Users mailing list
> Users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/openlayers-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20120416/ec152d7a/attachment.html
More information about the Users
mailing list