1

I'm having trouble to add a WFS layer over an OSM map. At first I thought that my data had a problem, and I thus decided to adapt one of the example on the Openlayers website. I have no error returned, but the layer is not appearing... Instead, I see in Firebug that there is a WFS request made to the server, but it is empty

http://demo.opengeo.org/geoserver/wfs

No GET request or arguments whatsoever. I can correctly make the request and I get a xml file as a result (in eg Firefox). I thought it was maybe because of the a proxy and I set one up (the one in Openlayers FAQ), but I get the same thing.

Here is the code I use:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <script src="http://www.openlayers.org/api/2.11/OpenLayers.js"></script>
    <script>


        var map, layer;
            var epsg900913 = new OpenLayers.Projection("EPSG:3857");
            var epsg4326 = new OpenLayers.Projection("EPSG:4326");

        function init(){
            OpenLayers.ProxyHost = "/cgi-bin/proxy.cgi?url=";
            var cent=new OpenLayers.LonLat(6.59,46.39).transform(epsg4326,epsg900913);

            var osm = new OpenLayers.Layer.OSM("Open Street Map");
            var wfs = new OpenLayers.Layer.Vector("States", {
                strategies: [new OpenLayers.Strategy.BBOX()],
                protocol: new OpenLayers.Protocol.WFS({
                    version: "1.0.0",
                    srsName: "EPSG:4326", // this is the default
                    url:  "http://demo.opengeo.org/geoserver/wfs",
                    featureType: "states",
                    featureNS: "http://www.openplans.org/topp"
                }),
                projection: new OpenLayers.Projection("ESPG:4326")
            });

            map = new OpenLayers.Map("map",{
                projection: epsg900913,
                layers:[osm,wfs],
                center: cent,
                zoom: 10
            });
            map.setCenter(new OpenLayers.LonLat(lon, lat), zoom);
            map.addControl( new OpenLayers.Control.LayerSwitcher() );

        }

    </script>
</head>
<body onload="init()">
    <div style="width:500px; height:500px" id="map"></div>
    <div id="coordinates"></div>
</body>
</html>

1 Answer 1

2

Ok, I've lost several more hours of my life due to my mild dyslexia. The line

projection: new OpenLayers.Projection("ESPG:4326")

should read EPSG...

The proxy is also mandatory. However, quick followup: Why is the request I see in firebug

http://demo.opengeo.org/geoserver/wfs

and not something like

http://demo.opengeo.org/geoserver/wfs?REQUEST=GET...
2
  • are you using POST instead of GET?
    – Ian Turton
    Jun 28, 2013 at 8:28
  • ah, yes, it is a POST request. Is there a way to do a GET instead, to see the difference and tinker with it?
    – Bulkilol
    Jun 28, 2013 at 8:46

Your Answer

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

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