1

I am learning to use Leaflet. I tried to add a layer from https://maps.nlsc.gov.tw/OpenData/wms. My code looks like this:

var wms = L.tileLayer.wms("https://wms.nlsc.gov.tw/wms", {
    layers: 'EMAP2',
    format: 'image/png',
}).addTo(map2);

But the layer didn't show on the map. When I checked what is being returned by the developer's tool, I found they were xml files and not images! So this may be the problem, but I don't know how to fix it. Other things I've tried:

  1. Checking with another layer, "CITY". Doesn't work. Still no layer is showing.

  2. Check if something is really wrong with my code by trying to load a layer from another source by changing the url to "http://ows.terrestris.de/osm/service", and layer to "OSM-WMS". This works!

  3. Check if something is something is wrong with the coordinates by loading the 'EMAP2' from the first source and "OSM-WMS" layer from the second source in QGIS. I set the CRS to EPSG:3857 for both. This works! They overlay just fine.

  4. Check what request the browser is sending using developers tool. For the "EMAP2" layer, this is a sample of what is being requested (as there are multiple request):https://wms.nlsc.gov.tw/wms?service=WMS&request=GetMap&layers=EMAP2&styles=&format=image%2Fpng&transparent=false&version=1.1.1&width=256&height=256&srs=EPSG%3A3857&bbox=13511620.615914037,2886262.188048257,13521404.55553454,2896046.1276687565

  • what does the XML file say? It is the server sending you an error message – Ian Turton Mar 10 at 8:24
  • No error massage. And I think I just found out what went wrong. The problem is for this WMS source, it only accepts uppercase for some of the parameters such as BBOX, WIDTH, etc. There's another post titled "Cannot get specific WMS to display in Leaflet or OpenLayers 3" that also used the same source I used, and ran into the same question. There's a detailed answer there. Should I delete this post? – Sara Mar 10 at 8:30
  • 1
    Anyways, to make the code above work, simply add uppercase: true after in the {} above – Sara Mar 10 at 8:33
  • 1
    If you found the solution, you can answer your own question and so help others with similar problems. – TomazicM Mar 10 at 8:44
  • 1
    Does this answer your question? Cannot get specific WMS to display in Leaflet or OpenLayers 3 – nmtoken Mar 10 at 11:10
1

I found what was wrong. Also I found there's a similar question with a detailed answer at Cannot get specific WMS to display in Leaflet or OpenLayers 3

But to give a simple answer to my own question: While experimenting, it appears that the specific WMS provider will return XML if certain parameters, such as bbox, width, etc are not in uppercase (note this is not the case for all WMS providers). Using developer's tool, I see that leaflet (version 1.6. According to the post I mentioned above, in versions prior to 1.x, the code may work) generates wms request with some lowercase parameters from the code. Therefore, the browser got xml and not png in return and the layer doesn't show. Leaflet provides uppercase option which can solve this problem. The code below works:

var wms = L.tileLayer.wms("https://wms.nlsc.gov.tw/wms", {
    layers: 'EMAP2',
    format: 'image/png',
    uppercase: true,
}).addTo(map2);
|improve this answer|||||

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