0

I have added a WFS layer to a map and can see (using Fiddler) a request being made to the server for the layer data. The server uses GML as the data format and the data being returned is valid. However, OpenLayers does not display the data. Here is the code that I use.

$(document).ready(
        function () {
            // allow testing of specific renderers via "?renderer=Canvas", etc
            var renderer = OpenLayers.Util.getParameters(window.location.href).renderer;
            renderer = (renderer) ? [renderer] : OpenLayers.Layer.Vector.prototype.renderers;
            var geographic = new OpenLayers.Projection("EPSG:4326");
            var mercator = new OpenLayers.Projection("EPSG:900913");

            map = new OpenLayers.Map({
                div: "map",
                layers: [
                    new OpenLayers.Layer.WMS("OpenLayers WMS",
                        "http://vmap0.tiles.osgeo.org/wms/vmap0",
                        { layers: "basic" }
                    ),
                    new OpenLayers.Layer.Vector("GML", {
                        strategies: [new OpenLayers.Strategy.Fixed()],
                        protocol: new OpenLayers.Protocol.WFS({
                                url: "http://localhost/MapServer/Default.aspx",
                                featureType: "Layer_ACTIVE",
                                featureNS: "http://www.tstgis.org/gml",
                                version: "1.1.0",
                                geometryName: "line"
                            }),
                            renderers: renderer
                        })
                ],
                zoom: 15
            });

            var bb = new OpenLayers.Bounds(-179.821327209473, 12.1057098342161, -56.5289154052734, 78.1442901657839);
            map.zoomToExtent(bb);
});

What is going on? Note: the returned data set is pretty big (1.5 MB) and I wonder if that has anything to do with the missing display.

4
  • I notice your WFS source is localhost - is your JS application also running on localhost, on the same (default) port? If not, and you've no proxy (you don't specify), the all-too-familiar cross-domain issue could be the reason. In that scenario data will still be downloaded but then discarded by the client.
    – tomfumb
    Commented Jan 31, 2013 at 2:10
  • what projection is your data in? if it isn't epsg:4326 then you are probably zoomed too far in to see it.
    – Ian Turton
    Commented Jan 31, 2013 at 13:42
  • @tomfumb Yes, the JS application is running on localhost. In fact, it's just an HTML test page in the WFS site with the above mentioned code. I am aware of the cross-domain issue and believe that its not that. Commented Jan 31, 2013 at 14:36
  • @iant I am a newbie to GIS and cannot answer your question with 100% confidence. However, from the trace that i see in fiddler, I believe that it is epsg:4326. Here is the initial portion of the response: <gml:boundedBy><gml:Envelope srsName="EPSG:4326"><gml:lowerCorner>-102.01546 28.970645</gml:lowerCorner><gml:upperCorner>-71.021601 43.167174</gml:upperCorner></gml:Envelope></gml:boundedBy> What do you think? Any ideas as to how to troubleshoot this issue? Commented Jan 31, 2013 at 14:44

1 Answer 1

1

I had no doubt that this was a configuration issue with OpenLayers. From what I knew about OpenLayers, I had it configured properly. Turns out, it is essential, in my case, to set the featurePrefix option. The reason for this is that the namespace and prefix in the XML response (GML) for each FeatureMember Node is used to identify the appropriate reader for the response. By default, the featurePrefix is set to ‘feature’. If the response's namespace + prefix does not match the configuration in OpenLayers, the features are not added to the layer and hence not displayed. In my case, the prefix is set to an empty string as the server does not add a prefix to the response.

Also, setting the geometryName is critical. The default value for geometryName is ‘the_geom’ for WFS version 1.0, and null for higher versions. The geometryName is used by the server to actually locate the features. In my case, geometryName used on the server was "msGeometry".

Here is the working code.

$(document).ready(
function () {
    // allow testing of specific renderers via "?renderer=Canvas", etc
    var renderer = OpenLayers.Util.getParameters(window.location.href).renderer;
    renderer = (renderer) ? [renderer] : OpenLayers.Layer.Vector.prototype.renderers;
    var geographic = new OpenLayers.Projection("EPSG:4326");
    var mercator = new OpenLayers.Projection("EPSG:900913");

    map = new OpenLayers.Map({
        div: "map",
        layers: [
            new OpenLayers.Layer.WMS("OpenLayers WMS",
                "http://vmap0.tiles.osgeo.org/wms/vmap0",
                { layers: "basic" }
            ),
            new OpenLayers.Layer.Vector("GML", {
                strategies: [new OpenLayers.Strategy.Fixed()],
                protocol: new OpenLayers.Protocol.WFS({
                        url: "http://localhost/MapServer/Default.aspx",
                        featureType: "Data_ACTIVE",
                        version: "1.1.0",
                        geometryName: "msGeometry",
                        featurePrefix: ""
                    }),
                    renderers: renderer
                })
        ],
        zoom: 15
    });

    var bb = new OpenLayers.Bounds(-179.821327209473, 12.1057098342161, -56.5289154052734, 78.1442901657839);
    map.zoomToExtent(bb);

});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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