I am trying to create a map in both Leaflet and OpenLayers 3 which displays the layer EMAP8
from the WMS http://wms.nlsc.gov.tw/wms
. I can't get it to work. I can open the layer in QGIS, but when I try to use it in Leaflet like this:
var overlay_taiwanemapen0 = L.tileLayer.wms('http://wms.nlsc.gov.tw/wms', {
layers: 'EMAP8',
format: 'image/png',
transparent: true,
continuousWorld : true,
});
or in OpenLayers 3 like this:
var lyr_taiwanemapen = new ol.layer.Tile({
source: new ol.source.TileWMS(({
url: "http://wms.nlsc.gov.tw/wms",
params: {"LAYERS": "EMAP8", "TILED": "true"},
})),
title: "taiwane-map(en)",
});
I get nothing displayed. I can see layers being requested, and data being transferred, but nothing on the map.
What am I doing wrong?
Best Answer
OpenLayers 3
The
VERSION
in WMS request parameterparams
in OL3, when omitted, is 1.3.0.You simple have to add the parameter
'VERSION': '1.1.1'
to your request. You can check the version supported by the server from the capabilities document.Solution for OpenLayers 3:
I've setup a fiddle using your WMS.
The full code is:
Leaflet (versions prior than 1.x)
The code provided in the question runs without any problem in Leaflet, in versions prior to 1.x.
This working fiddle has the code provided in the question.
Leaflet 1.x
In Leaflet 1.x all WMS query parameters are in lowercase, which is fine for servers following the WMS specification.
To provide compatibility with non compliant servers requiring WMS query parameters in uppercase, there is an optional parameter
uppercase: true
.The solution with Leaflet 1.x is:
Check this working fiddle with the code for Leaflet 1.x.