[MapServer-users] How to fetch a wfs layer in openLayers

mathias cunault mathias.cunault at inrap.fr
Wed Oct 26 03:30:02 PDT 2022


Mapserver 7.6.0 & OL6

My goal is to find a feature in a WFS layer and zoom on it using openLayers.
Following this example
https://openlayers.org/en/latest/examples/vector-wfs-getfeature.html, I am
trying to do the same with Mapserver.
I am not very familiar with Javascript so I feel uncomfortable in this
exercise.
I wrote :
const featureRequest = new ol.format.WFS().writeGetFeature({
        srsName: 'EPSG:3857',
        featureNS: 'http://openstreemap.org',
        featurePrefix: 'osm',
        featureTypes: ['emprise_3857'],
        outputFormat: 'application/json',
        filter: new ol.format.filter.equalTo('numoa', '25366'),
})

console.log(featureRequest)

fetch(`http://blabla/cgi-bin/mapserv.exe?MAP=c:/.../naasp_ol.map`, {
    method: 'POST',
    body: new XMLSerializer().serializeToString(featureRequest),
})
.then(function (rep) {
    return rep.json();
})
.then(function (json) {
    const features = new ol.format.GeoJSON().readFeatures(json)
    new ol.source.Vector.addFeatures(features)
    map.getView().fit(new ol.source.Vector.getExent())
})
But the chrome console says that there is an issue with the promise that it
is not a valid JSON.
Is it coming from the fetch I wrote in a bad way or a problem with
application/json ?
Indeed I read in Mapserver doc that only mapserver 8+ could handle
application/json (from what I understood)

Maybe it is both? I feel a bit lost.
I tried to find more examples and doc on the net, but nothing clear for me.
Maybe you can help?
Thanks


*----------*
*Mathias Cunault*

*référent SIG / Admin Caviar*

*Inrap Tours - 148 av. Maginot37000 TOURS06 32 05 98 96*
abonnez-vous à la lettre d'information de l'Inrap : http://ww
<http://www.inrap.fr/newsletter.php>w.inrap.fr/newsletter.php
<http://www.inrap.fr/newsletter.php>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/mapserver-users/attachments/20221026/8ea1cc49/attachment.htm>


More information about the MapServer-users mailing list