0

I am loading WMS maps using react-leaflet's WMSTileLayer.

Depending on the layers loaded, the image appears or not.

When the image is not loaded, I have found that Leaflet returns a bunch of tile error's:

tile errors

Unfortunately I can not find any helpful information in them.

When I send the GetMap query manually (https://wms.geo.admin.ch/?service=WMS&request=GetMap&layers=ch.vbs.armee-kriegsdenkmaeler,ch.swisstopo.hiks-dufour&styles&format=image%2Fpng&transparent=TRUE&version=1.3.0&greyscale=0&width=256&height=256&crs=EPSG%3A3857&bbox=1017529.7205322665,5792092.255337515,1095801.2374962869,5870363.772301538) I get a much more helpful answer:

<ServiceExceptionReport xmlns="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.3.0" xsi:schemaLocation="http://www.opengis.net/ogc http://schemas.opengis.net/wms/1.3.0/exceptions_1_3_0.xsd">
<script/>
<ServiceException> msDrawMap(): Image handling error. Failed to draw layer named 'ch.swisstopo.hiks-dufour'. msShapefileOpen(): Unable to access file. (/var/www/vhosts/wms-bgdi/private/wms-bgdi/ch.swisstopo.hiks-dufour.index) msShapefileOpen(): Unable to access file. (/var/local/geodata/ch.swisstopo.hiks-dufour.index) </ServiceException>
</ServiceExceptionReport>

So I can see that this is a server error because the server is missing a file. And I can also deduce what layer is the culprit.

How can I get this much more helpful error message from Leaflet?

So far I see only one workaround:

  1. on tileerror, send a GetMap request using fetch
  2. extract the helpful error from that answer
2
  • It seems you are out of luck here about getting some more info about tile load error. But as for your example of two WMS layers ch.vbs.armee-kriegsdenkmaeler and ch.swisstopo.hiks-dufour, it worked for me if I defined them as two separate Leaflet WMS layers.
    – TomazicM
    May 24, 2022 at 16:16
  • @TomazicM yeah, you're right. My problem is more general but thanks for noticing
    – Alex
    May 24, 2022 at 17:16

1 Answer 1

1

You might try adding EXCEPTIONS=INIMAGE& to the GetMap request to get an image response rather than the default XML response.

https://wms.geo.admin.ch/?service=WMS&request=GetMap&layers=ch.vbs.armee-kriegsdenkmaeler,ch.swisstopo.hiks-dufour&styles&format=image%2Fpng&transparent=TRUE&version=1.3.0&greyscale=0&width=256&height=256&crs=EPSG%3A3857&bbox=1017529.7205322665,5792092.255337515,1095801.2374962869,5870363.772301538&EXCEPTIONS=INIMAGE&

Gives:

INIMAGE error

6
  • Yeah, that works with a separate getMap request. But not when using leaflet's TileLayer.WMS. How can I get a meaningful error when using leaflet's TileLayer.WMS?
    – Alex
    May 24, 2022 at 14:11
  • To be more explicit: I can deal with an XML error (better than with an image). That is not the issue. The issue is to get a meaningful error when using leaflet's TileLayer.WMS.
    – Alex
    May 24, 2022 at 14:13
  • My thinking was at least with an image response you will get the image showing in your application, it's no different from any other GetMap request, better than trying to handle a non image response and parsing it etc.
    – nmtoken
    May 24, 2022 at 15:14
  • How did you try to pass the value? as part of the url https://wms.geo.admin.ch/?EXCEPTIONS=INIMAGE& or as an option?
    – nmtoken
    May 24, 2022 at 15:27
  • Actually, adding EXCEPTIONS=INIMAGE as parameters to TileLayer.WMS results in the error message being displayed instead of tiles, i.e. many times overlaying the map. That is unfortunately not a great user experience as it is unreadable
    – Alex
    May 24, 2022 at 17:22

Your Answer

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

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