[GIS] OpenLayers + Geoserver: how to dynamically retrieve the “geometryName” of a feature layer in GeoServer

geometrygeoserveropenlayers-2wfs

I am trying to get the list of feature layers on GeoServer and then user can add layers into map at anytime they want. my question is:
when using OpenLayers.Protocol.WFS loading a layer, is "geometryName" required?

since from the response of "WFSGetCapabilities" request to Geoserver, for each featureType, there are only "name, title, srsName, and featureNS". If “geometryName” is required, I have to retrive this from "DescribeFeatureType" request by enumerating the feature's properties . however, these two requests are asynchronous, I am not sure how to load this layer without user's interaction input.

anybody helps? appreciated!!

Best Answer

Even better you might not have to retrieve it at all, but it depends very much on the OpenLayers version.

2.10: geometryName is not required. If a value is not provided it will default to 'the_geom' which might not work for you, but that also depends on the WFS version you are using. If using geoserver as a backend I would try the default.

2.11 (currently in dev): no more required and (here's the great news) for WFS versions > 1 OL should figure it out by itself as per the documentation on the OL WFS proto:

http://dev.openlayers.org/docs/files/OpenLayers/Protocol/WFS/v1-js.html#OpenLayers.Protocol.WFS.v1.geometryName