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]}

...

  • Did you tried with other projections ? the definition of the projection EPSG:27700 may be the problem – Pierre Vivet Jan 1 '17 at 12:08
  • I didn't try the other projections, but if I request the layer as a tiled WMS it displays perfectly – Calanus Jan 1 '17 at 13:00
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/

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.