0

I'm using Leaflet to display agricultural plots obtain from a WMS.

Here is the link to the WMS : https://wxs.ign.fr/agriculture/geoportail/r/wms?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetCapabilities

Here's what I've done so far :

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css"
    integrity="sha512-xodZBNTC5n17Xt2atTPuE1HxjVMSvLVW9ocqUKLsCC5CXdbqCmblAshOMAS6/keqq/sMZMZ19scR4PsZChSR7A=="
    crossorigin=""/>
    <script src="https://unpkg.com/[email protected]/dist/leaflet.js"
    integrity="sha512-XQoYMqMTK8LvdxXYG3nZ448hOEQiglfqkJs1NOQV44cWnUrBc8PkAOcXy20w0vlaXaVUearIOBhiXZ5V3ynxwA=="
    crossorigin=""></script>
    <script data-key="agriulture" src="\node_modules\geoportal-extensions-leaflet\dist\GpPluginLeaflet.js"></script>
    <script src="\node_modules\geoportal-extensions-leaflet\dist\GpPluginLeaflet.css"></script>
    <script src="\node_modules\proj4\dist\proj4.js"></script>
    <script src="\node_modules\proj4leaflet\src\proj4leaflet.js"></script>

    <title>TEST MAP</title>
    <style>
        #map { height: 500px; }
    </style>
</head>
<body>
    <div id="map"></div>
    <script>
        var map = L.map('map',{crs : L.CRS.EPSG3857}).setView([45.5 , 4.5], 13);
        L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
            maxZoom: 19,
            attribution: '&copy; <a href="https://openstreetmap.org/copyright">OpenStreetMap contributors</a>'
        }).addTo(map);

        var wmsLayer = L.tileLayer.wms('https://wxs.ign.fr/agriculture/geoportail/r/wms?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetCapabilities', {
            layers: 'LANDUSE.AGRICULTURE2020',
        }).addTo(map);

    </script>
</body>  
</html>

The OSM tile is displaying well, but not the WMS layer.

In the console, I get this error :

wms:1 GET https://wxs.ign.fr/agriculture/geoportail/r/wms?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetCapabilities&service=WMS&request=GetMap&layers=LANDUSE.AGRICULTURE2020&styles=&format=image%2Fjpeg&transparent=false&version=1.1.1&width=256&height=256&srs=EPSG%3A3857&bbox=494088.9508353794,5699144.828942743,498980.9206456307,5704036.798752994 400 (BadRequest)

<ServiceExceptionReport xmlns="http://www.opengis.net/ogc">
<script> try { Object.defineProperty(navigator, "globalPrivacyControl", { value: false, configurable: false, writable: false }); document.currentScript.parentElement.removeChild(document.currentScript); } catch(e) {}; </script>
<ServiceException code="MissingParameterValue"> Parametre CRS absent. </ServiceException>
</ServiceExceptionReport>

As there is a CRS params missing, I've tried something with proj4 and proj4leaflet but without success.

3
  • As per the help center please do not include chit chat like thanks and other statements of appreciation within your posts
    – PolyGeo
    Commented Dec 1, 2021 at 22:35
  • Just noting you are sending two parameters named request (determining the type of request being made) but with different values, and two parameters named version (determining the version of the response required) also with different values. The WMS specification tells us that When request parameters are duplicated with conflicting values, the response from the server may be undefined. This International Standard does not mandate which of the duplicated values sent by the client are to be used by the server.
    – nmtoken
    Commented Sep 7, 2023 at 13:50
  • Your transparent=false& has no benefit here, the values for transparent are TRUE or FALSE i.e. case sensitive, the default being FALSE
    – nmtoken
    Commented Sep 7, 2023 at 13:52

1 Answer 1

2

You are making a WMS version 3 request, which needs to use a CRS parameter while you are sending an SRS parameter.

So either use version 1.1.1 and an SRS parameter or change the SRS to a CRS.

In general the best practice is to allow the client code to negotiate the version with the server (so leave the version parameter out of the getCapabilitites request). Though with out checking the source of the leaflet plugin I can't say if this would work in this case.

2
  • Thanks a lot ! It finally works. I'm quite new to WMS in Leaflet , how can i interact with this layer's object : the plot in my case ? Thanks again
    – AdBess
    Commented Dec 1, 2021 at 14:42
  • 1
    If you have additional question, please post it as a separate question.
    – TomazicM
    Commented Dec 1, 2021 at 16:43

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.