1

I am trying to load a WFS layer comprised of points. Fiddler shows that data is being returned but it is not being displayed.

Does anyone know what I am missing? Is it something to do with it being in OSGB projection?

I have created a fiddle to show my code (with the base layer removed): https://jsfiddle.net/7mm1bges/

It seems that the method of getting WFS data through OpenLayers has evolved over time, so I have opted for the methodology shown here:

http://openlayers.org/en/latest/examples/vector-wfs.html

Here is a sample of the JSON data that Fiddler shows is being returned:

{"type":"FeatureCollection",
"totalFeatures":1803,
"features":[{"type":"Feature","id":"EAFloodAlertsWarningCentroids.1",
"geometry":{"type":"Point","coordinates":[339095.07019032,345438.84249476]}

...

whyzar
  • 12,053
  • 23
  • 38
  • 72
Calanus
  • 189
  • 7

1 Answers1

0

After going down through the dark maze of GeoServer, OpenLayers 3 and WFS requests I think I got to the bottom of the problem(s).

My main error was thinking that running Fiddler acted as a substitute proxy for development. It works with WMS but not 100% with WFS for some reason. The request above uses JSON, I had to change it to JSONP to work cross domain, but first I had to enable JSONP on the GeoServer web.xml file(GeoServer 2.3 how to enable jsonp).

It still didn't work though because the examples on the openlayers website are rubbish - they are either not updated or never worked - the jsonp response from geoserver can not be thrown at the layer, it needs to be parsed in 2 stages using the following method:

   window.loadFeatures = function (response) {
            vector
                .getSource()
                .addFeatures(new ol.format.GeoJSON().readFeatures(response));
        };

See this for where I got this from:http://jsfiddle.net/goldrydigital/08zzh9n9/

I've updated the fiddle with the complete function, hope this helps someone: https://jsfiddle.net/q8wz1gvg/6/

Calanus
  • 189
  • 7