R語言鲁驶,交互Leaflet圖層添加不透明度按鈕!
Snipaste_2020-12-01_22-22-32.jpg
logo.png
微信截圖_20201201233324.png
# Tue Dec 01 22:23:50 2020 -
# 字符編碼:UTF-8
# R 版本:R x64 4.0.3 for window 10
# cgh163email@163.com
# 個(gè)人筆記不負(fù)責(zé)任
# —— 拎了個(gè)梨??
rm(list=ls());gc()
.rs.restartR()
# Leaflet圖層不透明度按鈕
remotes::install_git('https://gitee.com/youmigo/leaflet.multiopacity')
library(leaflet) # Create Interactive Web Maps with the JavaScript 'Leaflet'
Library
library(leaflet.multiopacity) # Leaflet Multiple Opacity Controls for R
library(raster) # Geographic Data Analysis and Modeling
require(leafletCN) # An R Gallery for China and Other Geojson Choropleth Map in
Leaflet
# 虛擬一個(gè)柵格圖層演示:
r <- raster(xmn = 113, xmx = 114,
ymn = 23, ymx = 24,
nrows = 30, ncols = 30) # 范圍
values(r) <- matrix(1:900, nrow(r), ncol(r), byrow = TRUE) # 高程
crs(r) <- crs("+init=epsg:4326") # 投影坐標(biāo)系統(tǒng)
plot(r) # 預(yù)覽
#提供layerId俱两、group或category以顯示不透明度控件
#如果未指定,將渲染所有層的控件
leaflet() %>%
amap(layerId = "Wikimedia") %>%
# addProviderTiles("Wikimedia", layerId = "Wikimedia") %>%
addRasterImage(r, layerId = "raster") %>%
addAwesomeMarkers(lng = 113.5, lat = 23.5,
layerId = "hospital", label = "Hospital") %>%
addOpacityControls(layerId = c("raster", "hospital"),
collapsed = FALSE, position = "topright",
title = "Opacity Control")
# Tue Dec 01 22:34:31 2020 ----diy--------------------------
require(raster) # Geographic Data Analysis and Modeling
require(leaflet) # Create Interactive Web Maps with the JavaScript 'Leaflet'
Library
require(leaflet.multiopacity) # Leaflet Multiple Opacity Controls for R
img <- raster('https://s1.ax1x.com/2020/10/27/BQCc2q.jpg')
# 手動(dòng)指定Bbox:
img@extent@xmin <- 113
img@extent@xmax <- 114
img@extent@ymax <- 24
img@extent@ymin <- 23
crs(img) <- crs("+init=epsg:4326") # 投影坐標(biāo)系統(tǒng)
plot(img) # 預(yù)覽
# Tue Dec 01 23:29:51 2020 --照片和指定Bbox和投影坐標(biāo)系統(tǒng)ok
#
leaflet() %>% addTiles() %>% # 底圖
addRasterImage(img,layerId = 'photo') %>% # 照片
addOpacityControls(title = '滑塊標(biāo)題O(∩_∩)O哈哈哈~') # 透明度滾動(dòng)條
# Tue Dec 01 23:32:20 2020 --end