3

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!!

3

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

1

I suppose you can do a nested async call. The outer one would be a DescribeFeatureType and the inner one would be the OpenLayers.Protocol.WFS call.

Something like (not tested):

var request = OpenLayers.Request.GET({
    url: 'http://myGeoserver:8080/geoserver/wfs?service=wfs&version=1.1.0&request=DescribeFeatureType',
    success: function (response) {

        var myGeometryName = parseResponseForgeometryName(response);

        var protocol = new OpenLayers.Protocol.WFS({
            version: "1.1.0",
            EndPointURL: "http://myGeoserver:8080/geoserver/wfs",
            featurePrefix: "catalog", //worspace 
            featureType: "myLayer", // Layer Name
            featureNS: "http://mydomain.com/catalog", // Edit Workspace Namespace URI
            geometryName: myGeometryName,
            srsName: myProjections.Mercator
        });

        var response = protocol.read({
            maxFeatures: 500,
            callback: function () {
                alert('complete');
            }
        });

    }
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.