Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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.

share|improve this question
    
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 Jan 31 '13 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. –  iant Jan 31 '13 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. –  Umair Ishaq Jan 31 '13 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? –  Umair Ishaq Jan 31 '13 at 14:44
add comment

1 Answer

up vote 1 down vote accepted

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);

});

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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