0

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() !

PopHip
  • 700
  • 6
  • 23
  • Have you tried `format: new ol.format.WFS()` – Mike Apr 17 '19 at 16:14
  • @Mike Yes I tried but got the same problem, everything is pushed into nullGeometryFeatures_ – PopHip Apr 18 '19 at 07:09
  • It seems like non-standard GML. OpenLayers supports Simplified Features http://schemas.opengis.net/gml/3.1.1/profiles/gmlsfProfile/1.0.0/gmlsf.xsd where the coordinates should be specified by .not by – Mike Apr 18 '19 at 09:34
  • Thanks ! you're right ! OpenLayers seems to use GML3 standard while the server I request return GML2 formated xml as you can see here : http://demo.mapserver.org/cgi-bin/wfs?SERVICE=WFS&VERSION=1.0.0&REQUEST=getfeature&TYPENAME=continents&MAXFEATURES=1&OUTPUTFORMAT=gml2 – PopHip Apr 18 '19 at 10:28
  • Unfortunatly i don't have the hand on this server so i'll try to solve this compatibility issue and add an answer to this post ! – PopHip Apr 18 '19 at 10:30
  • OpenLayers also has `format.GML2` but I'm not sure how much it supports – Mike Apr 18 '19 at 10:36
  • Great thanks ! GML2 format solved my problem, I did not know it exists. Should I add an answer to the post for better visibility ? – PopHip Apr 18 '19 at 11:06

0 Answers0