-2

Is it possible to add a vector layer in Leaflet from MapServer's WFS ?


I tried Flexberry WFST plugin and it doesn't work (WFS layer is not displayed).

Here is the JavaScript code for adding WFS layer to my Leaflet map:

var wfsLayer = new L.WFS({
    url: 'http://localhost/cgi-bin/mapserv.exe?map=../path/to/file.map',
    typeNS: 'ms',
    typeName: 'regions',
    crs: L.CRS.EPSG4326,
    style: {
        color: 'blue',
        weight: 2,
    }
}).addTo(mymap)
  .on('load', function () {
      mymap.fitBounds(wfsLayer);
  });

Here is the line i added to METADATA bloc of my mapfile:
"wfs_namespace_prefix" "ms"

When I look in the development tool panel of Firefox, I can see that :

  • An answer is sent by MapServer starting like this (it seems OK):
<?xml version='1.0' encoding="UTF-8" ?>
<wfs:FeatureCollection
   xmlns:ms="http://mapserver.gis.umn.edu/mapserver"
   xmlns:gml="http://www.opengis.net/gml"
   xmlns:wfs="http://www.opengis.net/wfs"
   xmlns:ogc="http://www.opengis.net/ogc"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://mapserver.gis.umn.edu/mapserver http://localhost/cgi-bin/mapserv.exe?map=..\path\to\file.map&amp;SERVICE=WFS&amp;VERSION=1.1.0&amp;REQUEST=DescribeFeatureType&amp;TYPENAME=ms:regions&amp;OUTPUTFORMAT=SFE_XMLSCHEMA  http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd">
      <gml:boundedBy>
        <gml:Envelope srsName="EPSG:4326">
            <gml:lowerCorner>41.333632 -5.141333</gml:lowerCorner>
            <gml:upperCorner>51.089000 9.559960</gml:upperCorner>
        </gml:Envelope>
      </gml:boundedBy>
    <gml:featureMember>
      <ms:regions gml:id="regions.REG000000000000000000001">
        <gml:boundedBy>
            <gml:Envelope srsName="EPSG:4326">
                <gml:lowerCorner>44.115380 2.062914</gml:lowerCorner>
                <gml:upperCorner>46.804031 7.185887</gml:upperCorner>
            </gml:Envelope>
        </gml:boundedBy>
        <ms:msGeometry>
          <gml:MultiSurface srsName="EPSG:4326">
            <gml:surfaceMember>
              <gml:Polygon>
                <gml:exterior>
                  <gml:LinearRing>
                    <gml:posList srsDimension="2">46.398235 6.568242 46.398311 6.568703 46.398534 ...   46.398433 6.565389 46.398556 6.565788 46.398235 6.568242 </gml:posList>
                  </gml:LinearRing>
                </gml:exterior>
                <gml:interior>
                  <gml:LinearRing>
                    <gml:posList srsDimension="2">44.345127 4.871285 44.345346 4.875885 44.345427 ... 44.345127 4.871285 </gml:posList>
                  </gml:LinearRing>
                </gml:interior>
              </gml:Polygon>
            </gml:surfaceMember>
          </gml:MultiSurface>
        </ms:msGeometry>
        <ms:id>REG000000000000000000001</ms:id>
        <ms:nom_reg>AUVERGNE-RHONE-ALPES</ms:nom_reg>
        <ms:insee_reg>84</ms:insee_reg>
      </ms:regions>
    </gml:featureMember>
            ...
  • At the same time, there is the following JavaScript error:
    TypeError: feature.getElementsByTagNameNS is not a function

    It comes from the generateLayer function of Flexberry' WFST library:
  generateLayer: function (feature) {
  var geometryField = feature.getElementsByTagNameNS(this.namespaceUri, this.options.geometryField)[0];


Maybe MapServer does not support data request with a namespace. Indeed all examples for adding WFS layer in Leaflet I found on the web are based on GeoServer or Esri server (never MapServer).

  • 2
    There seems to be couple of WFS plugins leafletjs.com/plugins.html so why not. Have a try. – user30184 Sep 20 at 20:58
  • You say Maybe MapServer does not support data request with a namespace. but in your question you say that in Firefox you get a response, so the issue doesn't look like it's a MapServer namespace issue. – nmtoken Sep 23 at 15:51
  • It's true so maybe this is the plugin that does not support WFS from MapServer. – Mordor Sep 24 at 16:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.