I want to add WFS layer from MapServer in an OpenLayers 4.0.1 client.
var mapserver_wfs_source = new ol.source.Vector({
format: new ol.format.WFS(),
loader: function(extent, resolution, projection){
var url = 'http://localhost:8081/cgi-bin/mapserv.exe?map=/ms4w/apps/tutorial/htdocs/example2_wfs.map&SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&TYPENAME=hydro';
$.ajax({
url
}).done(loadFeatures);
},
strategy: ol.loadingstrategy.bbox,
projection: 'EPSG:4326'
});
var loadFeatures = function(response) {
//console.log(response);
mapserver_wfs_source.addFeatures(new ol.format.WFS().readFeatures(response));
console.log(mapserver_wfs_source.getFeatures());
};
var mapserver_wfs = new ol.layer.Vector({
source: mapserver_wfs_source,
style: new ol.style.Style({
stroke: new ol.style.Stroke({
color: 'rgba(0, 255, 255, 1.0)',
width: 2
}),
fill: new ol.style.Fill({
color: 'rgba(0, 0, 255, 1.0)'
})
})
});
var projection = new ol.proj.Projection({
code: 'EPSG:4326',
units: 'degrees'
});
var map = new ol.Map({
layers: [osm, mapserver_wfs],
target: 'map',
view: new ol.View({
center: [-90, 45],
zoom: 4,
projection: projection
})
});
If I just follow the link 'http://localhost:8081/cgi-bin/mapserv.exe?map=/ms4w/apps/tutorial/htdocs/example2_wfs.map&SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&TYPENAME=hydro' I can see the features, and "mapserver_wfs_source.getFeatures()" returns the features.
Any idea on what is going on here?