Could anyone explain to me the good way to initialize a vector layer using a response from a MapServer?
Here is the way i do:
new ol.layer.Vector({
title: name,
source: new ol.source.Vector({
wrapX: false,
url: function (extent) {
return data.map_server_adress +
"&typename=" + name +
"&srs=" + data.projection +
"&service=WFS&request=GetFeature&version=1.0.0&BBOX="+ extent.join(',');
},
format: new ol.format.GML(),
strategy: ol.loadingstrategy.bbox,
})
And it seems to work since i get this kind of responses from the server:
<wfs:FeatureCollection>
<gml:boundedBy>
<gml:Box srsName="EPSG:27572">
<gml:coordinates>915095.490151,2081613.946304 915547.647404,2082070.940534</gml:coordinates>
</gml:Box>
</gml:boundedBy>
<gml:featureMember>
<ms:parcelles_wfs fid="parcelles_wfs.10583768">
<gml:boundedBy>
<gml:Box srsName="EPSG:27572">
<gml:coordinates>915289.953312,2081613.946304 915330.053226,2081669.612361</gml:coordinates>
</gml:Box>
</gml:boundedBy>
<ms:msGeometry>
<gml:Polygon srsName="EPSG:27572">
<gml:outerBoundaryIs>
<gml:LinearRing>
<gml:coordinates>915315.110225,2081613.946304 915307.324782,2081627.632231 915301.500411,2081637.931837 915289.953312,2081658.351753 915303.878919,2081667.360430 915307.332797,2081669.612361 915330.053226,2081628.008577 915315.110225,2081613.946304 </gml:coordinates>
</gml:LinearRing>
</gml:outerBoundaryIs>
</gml:Polygon>
</ms:msGeometry>
<ms:ogc_fid>10583768</ms:ogc_fid>
</ms:parcelles_wfs>
</gml:featureMember>
</wfs:FeatureCollection>
But then when i try to get features from the source of the layer i just get an empty array. I tried to print the source and features informations above seems to be in a member named nullGeometryFeatures_. I guess OpenLayers isn't able to build the feature's geometry but can't understand why?
EDIT :
Thanks to Mike's answer i realised the server i use was sending GML2 data while OpenLayers default expected format is GML3. So if your data looks like that instead of that, you just have to change new ol.format.GML()
to new ol.format.GML2()
!