Reputation: 1016
I have this WMS layer:
http://apps.ecmwf.int/wms/?token=public&version=1.3.0&request=GetMap&layers=composition_bbaod550
I want to add it to a leaflet map but it is not showing up. Here is my code:
library("leaflet")
library("sp")
leaflet() %>% addTiles() %>% setView(0, 50, zoom = 1) %>%
addWMSTiles("http://apps.ecmwf.int/wms/?token=public&version=1.3.0&request=GetMap",
layers = "composition_bbaod550",
options = WMSTileOptions(format = "image/png", transparent = TRUE))
What am I doing wrong?
EDIT #1:
Here is what the network requests look like from the developer console
EDIT #2:
Here is my code with IvanSanchez's suggestions. As you can see the proposed approach did not fix the problem
library("leaflet")
library("sp")
leaflet() %>% addTiles() %>% setView(0, 50, zoom = 1) %>%
addWMSTiles("http://apps.ecmwf.int/wms/",
layers = "composition_bbaod550",
options = WMSTileOptions(token = "public",
srs = "EPSG:4326",
format = "image/png",
transparent = TRUE))
Upvotes: 2
Views: 2897
Reputation: 320
If we make a GetCapabilities request to the WMS service as below, we can see that the highest supported WMS version is 1.1.1. So your GetMap request for a version=1.3.0 WMS service will probably error.
http://apps.ecmwf.int/wms/?token=public&service=WMS&request=GetCapabilities&
When I looked at the response it appeared to have some errors and indeed when I checked in my XML editor, there are many errors (so many that the log is greater the character limit allowed in this answer).
WMS configuration errors:
System ID: http://apps.ecmwf.int/wms/?token=public&service=WMS&request=GetCapabilities
Main validation file: http://apps.ecmwf.int/wms/?token=public&service=WMS&request=GetCapabilities
Schema: http://schemas.opengis.net/wms/1.1.1/WMS_MS_Capabilities.dtd
Engine name: Xerces
Severity: error
Description: Attribute "xlink:execution" is not allowed to appear in element "OnlineResource".
Start location: 44:17
End location: 44:54
System ID: http://apps.ecmwf.int/wms/?token=public&service=WMS&request=GetCapabilities
Main validation file: http://apps.ecmwf.int/wms/?token=public&service=WMS&request=GetCapabilities
Schema: http://schemas.opengis.net/wms/1.1.1/WMS_MS_Capabilities.dtd
Engine name: Xerces
Severity: error
Description: Unexpected element "SRS". The content of the parent element type must match "(Name?,Title,Abstract?,KeywordList?,SRS*,LatLonBoundingBox?,BoundingBox*,Dimension*,Extent*,Attribution?,AuthorityURL*,Identifier*,MetadataURL*,DataURL*,FeatureListURL*,Style*,ScaleHint?,Layer*)".
Start location: 97:8
End location: 97:11
System ID: http://apps.ecmwf.int/wms/?token=public&service=WMS&request=GetCapabilities
Main validation file: http://apps.ecmwf.int/wms/?token=public&service=WMS&request=GetCapabilities
Schema: http://schemas.opengis.net/wms/1.1.1/WMS_MS_Capabilities.dtd
Engine name: Xerces
Severity: error
Description: Unexpected element "SRS". The content of the parent element type must match "(Name?,Title,Abstract?,KeywordList?,SRS*,LatLonBoundingBox?,BoundingBox*,Dimension*,Extent*,Attribution?,AuthorityURL*,Identifier*,MetadataURL*,DataURL*,FeatureListURL*,Style*,ScaleHint?,Layer*)".
Start location: 122:10
End location: 122:13
System ID: http://apps.ecmwf.int/wms/?token=public&service=WMS&request=GetCapabilities
Main validation file: http://apps.ecmwf.int/wms/?token=public&service=WMS&request=GetCapabilities
Schema: http://schemas.opengis.net/wms/1.1.1/WMS_MS_Capabilities.dtd
Engine name: Xerces
Severity: error
Description: Attribute "multipleValues" is not allowed to appear in element "Extent".
Start location: 137:60
End location: 137:78
System ID: http://apps.ecmwf.int/wms/?token=public&service=WMS&request=GetCapabilities
Main validation file: http://apps.ecmwf.int/wms/?token=public&service=WMS&request=GetCapabilities
Schema: http://schemas.opengis.net/wms/1.1.1/WMS_MS_Capabilities.dtd
Engine name: Xerces
Severity: error
Description: Unexpected element "SRS". The content of the parent element type must match "(Name?,Title,Abstract?,KeywordList?,SRS*,LatLonBoundingBox?,BoundingBox*,Dimension*,Extent*,Attribution?,AuthorityURL*,Identifier*,MetadataURL*,DataURL*,FeatureListURL*,Style*,ScaleHint?,Layer*)".
Start location: 273:10
End location: 273:13
System ID: http://apps.ecmwf.int/wms/?token=public&service=WMS&request=GetCapabilities
Main validation file: http://apps.ecmwf.int/wms/?token=public&service=WMS&request=GetCapabilities
Schema: http://schemas.opengis.net/wms/1.1.1/WMS_MS_Capabilities.dtd
Engine name: Xerces
Severity: error
Description: Attribute "multipleValues" is not allowed to appear in element "Extent".
Start location: 288:60
End location: 288:78
System ID: http://apps.ecmwf.int/wms/?token=public&service=WMS&request=GetCapabilities
Main validation file: http://apps.ecmwf.int/wms/?token=public&service=WMS&request=GetCapabilities
Schema: http://schemas.opengis.net/wms/1.1.1/WMS_MS_Capabilities.dtd
Engine name: Xerces
Severity: error
Description: Unexpected element "SRS". The content of the parent element type must match "(Name?,Title,Abstract?,KeywordList?,SRS*,LatLonBoundingBox?,BoundingBox*,Dimension*,Extent*,Attribution?,AuthorityURL*,Identifier*,MetadataURL*,DataURL*,FeatureListURL*,Style*,ScaleHint?,Layer*)".
Start location: 393:10
End location: 393:13
...
The SRS / LatLonBoundingBox / BoundingBox section should look something like below (structure, not content):
<SRS>CRS:84</SRS>
<SRS>EPSG:27700</SRS>
<SRS>EPSG:3034</SRS>
<SRS>EPSG:3413</SRS>
<SRS>EPSG:3857</SRS>
<SRS>EPSG:4258</SRS>
<SRS>EPSG:4326</SRS>
<SRS>EPSG:900913</SRS>
<LatLonBoundingBox minx="-10.8018" miny="49.5889" maxx="3.92104" maxy="61.1359" />
<BoundingBox SRS="CRS:84"
minx="-10.8018" miny="49.5889" maxx="3.92104" maxy="61.1359" />
<BoundingBox SRS="EPSG:27700"
minx="-235677" miny="-34616" maxx="827937" maxy="1.28234e+006" />
<BoundingBox SRS="EPSG:3034"
minx="2.5664e+006" miny="2.55843e+006" maxx="3.67848e+006" maxy="3.94271e+006" />
<BoundingBox SRS="EPSG:3413"
minx="1.79406e+006" miny="-3.77262e+006" maxx="3.43831e+006" maxy="-2.09742e+006" />
<BoundingBox SRS="EPSG:3857"
minx="-1.20245e+006" miny="6.37538e+006" maxx="436488" maxy="8.6571e+006" />
<BoundingBox SRS="EPSG:4258"
minx="-10.8018" miny="49.5889" maxx="3.92104" maxy="61.1359" />
<BoundingBox SRS="EPSG:4326"
minx="-10.8018" miny="49.5889" maxx="3.92104" maxy="61.1359" />
<BoundingBox SRS="EPSG:900913"
minx="-10.8018" miny="49.5889" maxx="3.92104" maxy="61.1359" />
So the service is definitely not configured correctly, and this is probably the root cause of any problems you are having.
Upvotes: 2
Reputation: 19079
Do not include the version
nor the request
parameters in the base WMS URL. These are added internally by Leaflet. Leaflet expects a base WMS URL, as explained in http://leafletjs.com/examples/wms/wms.html.
So instead of
addWMSTiles("http://apps.ecmwf.int/wms/?token=public&version=1.3.0&request=GetMap",
Do
addWMSTiles("http://apps.ecmwf.int/wms/?token=public&",
Also, quoting from the Leaflet WMS tutorial:
L.TileLayer.WMS
has extra options, which can be found in Leaflet’s API documentation. Any option not described there will be passed to the WMS server in the getImage URLs.
So you can actually do
addWMSTiles("http://apps.ecmwf.int/wms/",
layers = "composition_bbaod550",
options = WMSTileOptions(token = "public", format = "image/png", transparent = TRUE))
If this fails, use the developer console in your web browser (press F12) and see the network requests. How do the requests to the WMS look like?
Edit:
After a tiny bit of debugging, it seems that the WMS server is responding with:
<!DOCTYPE ServiceExceptionReport SYSTEM "/static/frontend/contrib/exception_1_1_1.dtd">
<ServiceExceptionReport version="1.1.1">
<ServiceException code='InvalidSRS'><![CDATA[
Unsupported projection 'EPSG:3857'
]]>
</ServiceException>
</ServiceExceptionReport>
This means that the WMS server is not capable of outputting images which fit the default map projection for Leaflet.
If you want to use this WMS server, you'll have to check the list of supported map projections from its GetCapabilities
document, and use Proj4Leaflet to make the map use a projection different than the default.
Do read:
I'm sorry there's no straightforward answer; you'll have to do a bit of work and learning about projections.
Upvotes: 1