library(Mreport) library(leaflet) library(leafletCN)
load_base() load_sample_base()
x <- station_useful[,c(1,2,3,5,19,20)] names(x) <- c("popup","label","col","level","lng","lat")
x <- na.omit(x) x <- x[x$label != "兴安台",] x <- x[x$label != "大王柳",]
gg <- x[x$level == "国家高速",] gd <- x[x$level == "普通国道",] sg <- x[x$level == "省级高速",] sd <- x[x$level == "普通省道",] qb <- x
pal <- colorFactor(c("darkgreen", "yellow", "blue"),domain = unique(x$col)) leaflet(na.omit(x)) %>% setView(lng=116.38,lat=39.9,zoom=9) %>% addTiles() %>% addCircleMarkers(data=qb,label = ~label,popup = ~popup,color = ~pal(col),group = "全部站点") %>% addCircleMarkers(data=gg,label = ~label,popup = ~popup,color = ~pal(col),group = "国家高速") %>% addCircleMarkers(data=gd,label = ~label,popup = ~popup,color = ~pal(col),group = "普通国道") %>% addCircleMarkers(data=sg,label = ~label,popup = ~popup,color = ~pal(col),group = "省级高速") %>% addCircleMarkers(data=sd,label = ~label,popup = ~popup,color = ~pal(col),group = "普通省道") %>% addLayersControl( baseGroups = c("全部站点", "国家高速", "普通国道","省级高速","普通省道"), options = layersControlOptions(collapsed = FALSE) ) %>% addLegend(pal=pal,values=unique(x$col),position = "bottomright")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.