R/SetMapView.R

# You can learn more about package authoring with RStudio at:
#
#   http://r-pkgs.had.co.nz/
#
# Some useful keyboard shortcuts for package authoring:
#
#   Build and Reload Package:  'Ctrl + Shift + B'
#   Check Package:             'Ctrl + Shift + E'
#   Test Package:              'Ctrl + Shift + T'


# mapView <- 'Paris'
# testDF <- data.frame(lat=c(48.875403,48.904567,48.846674),
#                      lng=c(2.317795,2.255450,2.382460))
# map <- leaflet(testDF)
# class(map)

# data(LatitudesLongitudes, package = 'MyMaps')

SetMapView <- function(map,mapView) {

  expect_class(map,c("leaflet","htmlwidget"),info="Wrong class for map")
  expect_class(mapView,"character",info="Wrong class for mapView")

  data(LatitudesLongitudes, package = 'R.Maps')

  expect_in(mapView,names(LatitudesLongitudes),info='View not available')

  latitudesLongitudesView <- LatitudesLongitudes[[mapView]]

  fitBounds(map,
            lat1=latitudesLongitudesView$latitude1,
            lng1=latitudesLongitudesView$longitude1,
            lat2=latitudesLongitudesView$latitude2,
            lng2=latitudesLongitudesView$longitude2)
}

# LatitudesLongitudes <- fromJSON(file="data/LatitudesLongitudes.json")
# devtools::use_data(LatitudesLongitudes)
Blitzy29/R.Maps documentation built on May 6, 2019, 7:57 a.m.