R语言leafem包,addStaticLabels函數,添加文本标签
# Thu Nov 05 00:36:24 2020 -
# 字符编码:UTF-8
# R 版本:R x64 4.0.3 for window 10
# cgh163email@163.com
# 个人笔记不负责任
# —— 拎了个梨🍐
.rs.restartR()
# addStaticLabels函數,添加文本标签
rm(list=ls());gc()
library(leaflet)
require(sf)
lopt = labelOptions(noHide = TRUE,
direction = 'top',
textOnly = TRUE)
indata <- sf::st_read(system.file("shape/nc.shp", package="sf"))
leaflet(indata) %>%
addProviderTiles("OpenStreetMap") %>%
addFeatures(.) %>%
addStaticLabels(., label = indata$NAME) # 顯示標籤
# Thu Nov 05 00:39:36 2020 --
leaflet(indata) %>%
addProviderTiles("OpenStreetMap") %>%
addFeatures(.) %>%
addStaticLabels(., label = indata$NAME,
style = list("color" = "red", "font-weight" = "bold")) # 設定標籤顏色
# Thu Nov 05 00:41:00 2020 ---diy---------------------------
map.gz <- st_read('https://geo.datav.aliyun.com/areas_v2/bound/440100_full.json')
leaflet() %>% addTiles() %>%
addStaticLabels(data = map.gz)
names(map.gz)
leaflet() %>% addTiles() %>%
addStaticLabels(data = map.gz
,style = list("color" = "#FFFF00", "font-weight" = "bold")
,label = map.gz$name)