有谁知道如何为传单R中的WMS图层添加图例?

时间:2016-10-21 14:32:34

标签: r leaflet wms

有没有人知道如何在传单R中为WMS Tile图层添加图例?

1 个答案:

答案 0 :(得分:2)

您可以在leaflet.extras中使用addWMSLegend()。您可以将正确的WMS图例服务uri设置为addWMSLegend()。以下是一个示例:

library(leaflet)
library(leaflet.extras)
leaflet()%>%
    addTiles(urlTemplate = 'the url of your basemap service',
        options=tileOptions(useCache=T,crossOrigin=T))%>%
    addWMSTiles(baseUrl = 
        paste0('http://',geoserver.host,':8080/geoserver/gwc/service/wms'),
        layers ='workspace:layer',
        options = WMSTileOptions(format = "image/png", transparent = TRUE),
        attribution = "")%>%
    addWMSLegend(uri=paste0('http://',geoserver.host,
        ':8080/geoserver/gwc/service/wms?',
        'REQUEST=GetLegendGraphic&VERSION=1.0.0',
        '&FORMAT=image/png&LAYER=workspace:layer'))