3

With OpenLayers 6.12, I cannot visualize a layer concerning Martinique EPSG:32620.

As I have no error I don't know if it comes from this projection or from the GML which would not be compatible. I know however that there is a result for https://datacarto.geomartinique.fr/wfs?version=2.0.0&request=GetFeature&typeNames=ms:pref_chlordecone_analyse_sol_v2_s_972&outputFormat=gml3&SRSNAME=EPSG:32620&bbox=-6800151.831794434,1640142.7893100686,-6780421.9682055665,1647728.6106899313,EPSG:3857

but the features remain hopelessly empty. What to do?

My code :

var chlorodeconeMartiniqueSource = new ol.source.Vector({
                        format: new ol.format.WFS(),
                        loader: function(extent, resolution, projection) {
                            var proj = projection.getCode();
                            var url = 'https://datacarto.geomartinique.fr/wfs?version=2.0.0&request=GetFeature&typeName=ms:pref_chlordecone_analyse_sol_v2_s_972&outputFormat=gml3&SRSNAME=EPSG:32620&' + 'bbox=' + extent.join(',') + ',' + 'EPSG:3857'
                            var xhr = new XMLHttpRequest();
                            xhr.open('GET', url);
                            xhr.onload = function() {
                                if (xhr.status == 200) {
                                    console.log('url',url)
                                    var features = chlorodeconeMartiniqueSource.getFormat().readFeatures(xhr.responseText, { //chlorodeconeMartiniqueSource.getFormat()
                                        dataProjection: 'EPSG:32620', 
                                        featureProjection: 'EPSG:3857'
                                    })
                                chlorodeconeMartiniqueSource.addFeatures(features)
                                console.log('xhr.response',xhr.responseText)
                                console.log('features',features)
                                console.log('chlorodeconeMartiniqueSource',chlorodeconeMartiniqueSource)
                                }
                                }
                                xhr.send();
                                },
                                strategy: ol.loadingstrategy.bbox,
                                });
2
  • Did you define/register projection EPSG:32620 with proj4? (see openlayers.org/en/latest/apidoc/…)?
    – TomazicM
    Commented Apr 28, 2023 at 11:09
  • Yes i try proj4.defs("EPSG:32620" ,"+proj=utm +zone=20 +ellps=WGS84 +datum=WGS84 +units=m +no_defs"); ol.proj.proj4.register(proj4);
    – ericire
    Commented Apr 28, 2023 at 12:16

1 Answer 1

2

ol.format.WFS() defaults to version 1.1.0 with GML3

Either use version=1.1.0 in your url to reflect that

or you will need to specify both the WFS and GML version

ol.format.WFS({version: '2.0.0', gmlFormat: new ol.format.GML3()})

since version 2.0.0 will expect GML3.2 unless another version is specified

https://codesandbox.io/s/vector-wfs-forked-bjz6rf?file=/main.js

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.