R/leaflet으로 마커를 임의의 각도로 회전

11440 단어 Rleaflet
작업 디렉토리에 leaflet.rotatedMarker.js 을 배치하고 다음을 실행합니다.
library(leaflet)
library(htmltools)

lat <- rnorm(n=10, mean=35, sd=1)
lng <- rnorm(n=10, mean=135, sd=1)
dir <- runif(n=10, min=0, max=359)
X <- data.frame(lat, lng, dir)

leaflet.rotatedMarker <- htmlDependency(name="leaflet.rotatedMarker", version="0.2.0", src=getwd(), script="leaflet.rotatedMarker.js")
icon <- makeIcon(iconUrl="iconfinder_icon-arrow-up-a_211622.png", iconWidth=32, iconHeight=32)

l <- leaflet() %>% addTiles()
l$dependencies <- list(leaflet.rotatedMarker)
l %>% 
  addMarkers(lng=X$lng, lat=X$lat, icon=icon, options=markerOptions(rotationAngle=X$dir))



이쪽이 알기 쉬운 생각이 든다. CircleMarkers와 잘 맞추기가 어렵습니다.
library(leaflet)
library(htmltools)

lat <- rnorm(n=10, mean=35, sd=1)
lng <- rnorm(n=10, mean=135, sd=1)
dir <- runif(n=10, min=0, max=359)
X <- data.frame(lat, lng, dir)

leaflet.rotatedMarker <- htmlDependency(name="leaflet.rotatedMarker", version="0.2.0", src=getwd(), script="leaflet.rotatedMarker.js")
icon <- makeIcon(iconUrl="https://upload.wikimedia.org/wikipedia/commons/a/aa/Aiga_uparrow.svg", iconWidth=10, iconHeight=10)

l <- leaflet() %>% addTiles()
l$dependencies <- list(leaflet.rotatedMarker)
l %>% 
  addCircleMarkers(lng=X$lng, lat=X$lat, radius=5) %>%
  addMarkers(lng=X$lng, lat=X$lat, icon=icon, options=markerOptions(rotationAngle=X$dir))

좋은 웹페이지 즐겨찾기