[GIS] Can’t get WFS working in Openlayers 3

javascriptmapserveropenlayerswfs

I try to get my WFS working but with no success. Actually I use nearly the same Code like in the OL3-Examples.
In Firebug I can see a lot of WFS-Requests and a GML-Response which looks fine to me. Nevertheless nothing is shown in the map.
Can someone see the problem?

var vectorSource = new ol.source.ServerVector({
          //format: new ol.format.GeoJSON(),    
          format: new ol.format.WFS(),        
          loader: function(extent, resolution, projection) {
            var url = 'http://.......&REQUEST=getfeature&typename=deu_adm1_3857&&STYLES=&BBOX=-20026376.39,-20048966.10,20026376.39,20048966.10&SRS=EPSG:3857&  
MAXFEATURES=99&SERVICE=WFS&VERSION=1.1.0';
            $.ajax({
              url: url
            });
          },      
          strategy: ol.loadingstrategy.createTile(new ol.tilegrid.XYZ({
          maxZoom: 19
          })),
        projection: 'EPSG:3857'
        });


        var loadFeatures = function(response) {
          vectorSource.addFeatures(vectorSource.readFeatures(response));
        };

         var vectorLayer = new ol.layer.Vector({
          source: vectorSource,
          style: new ol.style.Style({
            stroke: new ol.style.Stroke({
              color: 'rgba(0, 0, 255, 1.0)',
              width: 5
            })
          })
        });

GML Response

Best Answer

Kaarel´s answer should be marked as the correct answer. You need to call the loadFeatures function from the AJAX call.

I created three jsfiddle to demonstrate ol 3.5.0 calls via AJAX for ol.format.GeoJSON (JSON and JSONP) as well as ol.format.WFS.

WFS

http://jsfiddle.net/goldrydigital/9d3jzpna/

JSON

http://jsfiddle.net/goldrydigital/ucspgvx0/

JSONP

http://jsfiddle.net/goldrydigital/08zzh9n9/

Related Question