我有这个WMS图层:
http://apps.ecmwf.int/wms/?token=public&version=1.3.0&request=GetMap&layers=composition_bbaod550
我想将它添加到传单地图中,但它没有显示出来。 这是我的代码:
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))
我做错了什么?
编辑#1:
以下是来自开发者控制台的网络请求
编辑#2:
这是我的代码与IvanSanchez的建议。正如您所看到的,建议的方法无法解决问题
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))
答案 0 :(得分:0)
不在基本WMS网址中包含version
和request
参数。这些是由Leaflet内部添加的。 Leaflet需要 base WMS URL,如http://leafletjs.com/examples/wms/wms.html中所述。
所以而不是
addWMSTiles("http://apps.ecmwf.int/wms/?token=public&version=1.3.0&request=GetMap",
待办事项
addWMSTiles("http://apps.ecmwf.int/wms/?token=public&",
另外,引用Leaflet WMS tutorial:
L.TileLayer.WMS
有额外选项,可在Leaflet’s API documentation中找到。任何未在此描述的选项都将在getImage URL中传递给WMS服务器。
所以你实际上可以做到
addWMSTiles("http://apps.ecmwf.int/wms/",
layers = "composition_bbaod550",
options = WMSTileOptions(token = "public", format = "image/png", transparent = TRUE))
如果此操作失败,请在Web浏览器中使用开发人员控制台(按F12)并查看网络请求。如何向WMS发出请求?
编辑:
经过一小段调试后,似乎WMS服务器响应:
<!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>
这意味着WMS服务器无法输出符合Leaflet默认地图投影的图像。
如果要使用此WMS服务器,则必须从其GetCapabilities
文档中检查支持的地图投影列表,并使用Proj4Leaflet使地图使用与默认值不同的投影。
请阅读:
对不起,没有直截了当的回答;你必须做一些工作并学习预测。
答案 1 :(得分:0)
如果我们向WMS服务发出GetCapabilities请求,如下所示,我们可以看到支持的最高WMS版本是1.1.1。因此,您对版本= 1.3.0 WMS服务的GetMap请求可能会出错。
http://apps.ecmwf.int/wms/?token=public&service=WMS&request=GetCapabilities&
当我查看响应时,它似乎有一些错误,实际上当我在我的XML编辑器中检查时,会出现很多错误(很多错误,以及日志在此答案中允许的字符数限制更大)。
WMS配置错误:
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
...
SRS / LatLonBoundingBox / BoundingBox部分应如下所示(结构,而不是内容):
<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" />
因此,服务肯定没有正确配置,这可能是您遇到任何问题的根本原因。