250606.R.廣州獻(xiàn)血優(yōu)待證景點(diǎn)標(biāo)注

結(jié)果是交互式html文檔


互動(dòng)地圖截圖

原始數(shù)據(jù)


原始數(shù)據(jù)

R語言代碼

# Sat Jun  7 14:39:58 2025 edit
# 字符編碼:UTF-8
# R 版本:R 4.4.2 x64 for window 11
# cgh163email@163.com
# 個(gè)人筆記不負(fù)責(zé)任,拎了個(gè)梨????
#.rs.restartR()
require(openxlsx)
rm(list = ls());gc()
library(leaflet)
require(leafletCN)
library(htmltools)



  dt <- read.xlsx("原始數(shù)據(jù)/工作簿2.xlsx")
gzmap <- sf::st_read('原始數(shù)據(jù)/gz.min.geojson')
plot(gzmap$geometry)
# 示例數(shù)據(jù)(含兩個(gè)鏈接)
attractions <- data.frame(
  name = c("故宮", "外灘", "西湖", "長城"),
  lng = c(116.3974, 121.4902, 120.1551, 116.5704),
  lat = c(39.9183, 31.2397, 30.2741, 40.4319),
  url1 = c(
    "https://www.dpm.org.cn/",
    "https://www.trip.com/travel-guide/shanghai/the-bund-1401261/",
    "https://www.hangzhou.gov.cn/col/col1228980242/index.html",
    "https://www.thegreatwall.com.cn/"
  ),
  link_text1 = c("官網(wǎng)", "旅游攻略", "政務(wù)網(wǎng)", "官方網(wǎng)站"),
  url2 = c(
    "https://baike.baidu.com/item/%E5%8C%97%E4%BA%AC%E6%95%85%E5%AE%AB/127716",
    "https://baike.baidu.com/item/%E5%A4%96%E6%BB%A9/1696305",
    "https://baike.baidu.com/item/%E8%A5%BF%E6%B9%96/142748",
    "https://baike.baidu.com/item/%E4%B8%87%E9%87%8C%E9%95%BF%E5%9F%8E/1420"
  ),
  link_text2 = c("百度百科", "百度百科", "百度百科", "百度百科")
)
head(attractions)

# 創(chuàng)建地圖
leaflet(attractions) |>
  addTiles() |>
  addMarkers(
    lng = ~lng,
    lat = ~lat,
    label = ~name,
    popup = ~paste0(
      "<div style='min-width:150px'>",
      "<b>", name, "</b><br><br>",
      "<span style='display: inline-block; margin-bottom: 5px;'>",
      "?? <a href='", url1, "' target='_blank' style='color: #0066cc;'>", link_text1, "</a>",
      "</span><br>",
      "<span style='display: inline-block;'>",
      "?? <a href='", url2, "' target='_blank' style='color: #cc3300;'>", link_text2, "</a>",
      "</span>",
      "</div>"
    ),
    clusterOptions = markerClusterOptions()
  ) |>
  addControl(
    html = "<div style='padding:5px;background:white;border:1px solid gray;'>
            <b>點(diǎn)擊標(biāo)記查看雙鏈接</b><br>
            <small>藍(lán)色鏈接:官方資源 | 紅色鏈接:百科資料</small>
            </div>",
    position = "topright"
  )
# Sat Jun  7 14:45:26 2025 ------------------------------
head(dt)
# name  lng lat urlinf  txt.inf urlamap txt.gps
# (溫室也免)中國科學(xué)院華南植物園  113.364581  23.182387   https://mp.weixin.qq.com/s?__biz=MzUzMjkwMTU5Mw==&mid=2247486919&idx=2&sn=e5bd8a518107fb8cef25c4218a4d6c0f&scene=21#wechat_redirect 推文介紹    https://uri.amap.com/marker?position=113.364581,23.182387&name=(溫室也免)中國科學(xué)院華南植物園&src=梨子定位&coordinate=gaode&callnative=1  高德地圖
# 白江湖森林公園   113.896809  23.507591   https://mp.weixin.qq.com/s/H1509RbFM9zVk5-P6qGLSA   推文介紹    https://uri.amap.com/marker?position=113.896809,23.507591&name=白江湖森林公園&src=梨子定位&coordinate=gaode&callnative=1   高德地圖

# Sat Jun  7 15:11:40 2025 +++++++++++++++++++

leaflet(dt) |>
  amap() |>
  addMarkers(
    lng = ~lng,
    lat = ~lat,
    label = ~name,
    popup = ~paste0(
      "<div style='min-width:150px'>",
      "<b>", name, "</b><br><br>",
      "<span style='display: inline-block; margin-bottom: 5px;'>",
      "?? <a href='", urlinf, "' target='_blank' style='color: #0066cc;'>", txt.inf, "</a>",
      "</span><br>",
      "<span style='display: inline-block;'>",
      "?? <a href='", urlamap, "' target='_blank' style='color: #cc3300;'>", txt.gps, "</a>",
      "</span>",
      "</div>"
    ),
    clusterOptions = markerClusterOptions()
  )
# Sat Jun  7 15:52:33 2025 +++++++++++++++++++
# options = popupOptions(maxWidth = 300, minWidth = 250)

lmap <- leaflet(dt) |>
  amap() |>
  addMarkers(
    # options = popupOptions(maxWidth = 300, minWidth = 250),
      popup = ~paste0(
        "<div style='min-width:200px; font-size:16px;'>",
        "<b>", name, "</b><br><br>",
        "<button onclick=\"window.open('", urlinf, "','_blank')\"
         style='background-color: #0066cc; color: white; border: none;
                padding: 10px; margin: 5px 0; width: 100%;
                border-radius: 5px; font-size:16px;'>
        ?? ", txt.inf, "
      </button><br>",
        "<button onclick=\"window.open('", urlamap, "','_blank')\"
         style='background-color: #cc3300; color: white; border: none;
                padding: 10px; margin: 5px 0; width: 100%;
                border-radius: 5px; font-size:16px;'>
        ?? ", txt.gps, "
      </button>",
        "</div>"
      ),
      clusterOptions = markerClusterOptions()  # 點(diǎn)聚合功能
          )    |>
addPolygons(
  data = gzmap,  # 你的sf對(duì)象
  color = "#baddf1",   # 邊界線顏色(紅色)
  weight = 3,          # 邊界線寬度
  opacity = 1,         # 邊界線不透明度
  fillColor = "transparent",  # 填充顏色(透明)
  fillOpacity = 0,     # 填充不透明度
  label = ~鄉(xiāng)鎮(zhèn)名        # 懸停標(biāo)簽(使用sf對(duì)象中的name字段)
)
lmap

# 保存為HTML
library(htmlwidgets)
saveWidget(lmap, file = "廣州獻(xiàn)血優(yōu)待證景點(diǎn)地圖.html")

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • R語言與數(shù)據(jù)挖掘:公式;數(shù)據(jù);方法 R語言特征 對(duì)大小寫敏感 通常,數(shù)字,字母,. 和 _都是允許的(在一些國家還...
    __一蓑煙雨__閱讀 1,857評(píng)論 0 5
  • 關(guān)于Mongodb的全面總結(jié) MongoDB的內(nèi)部構(gòu)造《MongoDB The Definitive Guide》...
    中v中閱讀 32,309評(píng)論 2 89
  • 1. Java基礎(chǔ)部分 基礎(chǔ)部分的順序:基本語法,類相關(guān)的語法,內(nèi)部類的語法,繼承相關(guān)的語法,異常的語法,線程的語...
    子非魚_t_閱讀 34,734評(píng)論 18 399
  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,578評(píng)論 19 139
  • JAVA面試題 1、作用域public,private,protected,以及不寫時(shí)的區(qū)別答:區(qū)別如下:作用域 ...
    JA尐白閱讀 1,269評(píng)論 1 0

友情鏈接更多精彩內(nèi)容