デフォルトのマップビューの設定

R で作る leaflet のインタラクティブマップ

Rich Majerus

Vice President of Strategy & Planning, Queens University of Charlotte

Rにおけるジオコーディング

  • ggmapパッケージのgeocode()関数を使用するのが一般的なアプローチです
  • 住所または地名の緯度と経度を返します
library(ggmap)

geocode("350 5th Ave, New York, NY 10118")
Information from URL : https://maps.googleapis.com/maps/api/geocode/...

lon       lat
-73.98575 40.74856
R で作る leaflet のインタラクティブマップ

Rにおけるジオコーディング II

geocode(location, 
        output = c("latlon", "latlona", "more", "all"),
        source = c("google", "dsk"))

geocode("Colby College", output = "more", source = "google")
lon       lat      type          loctype  
-69.66264 44.56387 establishment rooftop  

address
4000 mayflower hill dr, waterville, me 04901, usa
R で作る leaflet のインタラクティブマップ

デフォルトのマップビューの設定

setView()

leaflet() %>% 
 addTiles() %>% 
 setView(lng = -73.98575, 
         lat = 40.74856, 
         zoom = 13)

setView()の使用例

fitBounds()

leaflet() %>% 
 addTiles() %>% 
 fitBounds(
  lng1 = -73.910, lat1 = 40.773, 
  lng2 = -74.060, lat2 = 40.723)

fitBounds()の使用例

R で作る leaflet のインタラクティブマップ

フォーカスの維持

leaflet(options = leafletOptions(dragging = FALSE,
                                 minZoom = 14, 
                                 maxZoom = 18))  %>% 
    addProviderTiles("CartoDB")  %>% 
    setView(lng = -73.98575, lat = 40.74856, zoom = 18)

R で作る leaflet のインタラクティブマップ

フォーカスの復元

leaflet()  %>% 
     addTiles()  %>% 
     setView(lng = -73.98575, lat = 40.74856, zoom = 18) %>% 
     setMaxBounds(lng1 = -73.98575, lat1 = 40.74856, 
                  lng2 = -73.98575, lat2 = 40.74856) 

setMaxBounds()の使用例

R で作る leaflet のインタラクティブマップ

さあ、練習しましょう!

R で作る leaflet のインタラクティブマップ

Preparing Video For Download...