routes: Add Targomo Routes to a Leaflet Map

Description Usage Arguments Value See Also Examples

Description

This function takes source and target data, together with options for the API and drawing options, and returns the map with the requested routes.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
getTargomoRoutes(source_data = NULL, source_lat = NULL,
  source_lng = NULL, target_data = NULL, target_lat = NULL,
  target_lng = NULL, source_id = NULL, target_id = NULL,
  options = targomoOptions(), api_key = Sys.getenv("TARGOMO_API_KEY"),
  region = Sys.getenv("TARGOMO_REGION"), config = list(),
  verbose = FALSE, progress = FALSE, timeout = NULL)

drawTargomoRoutes(map, routes, drawOptions = routeDrawOptions(),
  group = NULL, ...)

addTargomoRoutes(map, source_data = NULL, source_lat = NULL,
  source_lng = NULL, source_id = NULL, target_data = NULL,
  target_lat = NULL, target_lng = NULL, target_id = NULL,
  options = targomoOptions(), drawOptions = routeDrawOptions(),
  group = NULL, api_key = Sys.getenv("TARGOMO_API_KEY"),
  region = Sys.getenv("TARGOMO_REGION"), config = list(),
  verbose = FALSE, progress = FALSE, timeout = NULL)

Arguments

source_data, target_data

The source and target points for your routes - supported types are data.frame matrix and objects from the sf and sp packages.

source_lat, source_lng

Columns identifying the latitude and longitude columns in your sourcedata, or numeric vectors of equal length.

target_lat, target_lng

As for source_lat,source_lng but for target data.

source_id, target_id

Formulas or vectors of IDs to give to your source and target points. These will be used to match back to the input data if applicable.

options

A list of targomoOptions to send to the API.

api_key

Your Targomo API key - defaults to the TARGOMO_API_KEY ennvironment variable.

region

Your Targomo region - defaults to the TARGOMO_REGION environment variable.

config

Config options to pass to httr::POST e.g. proxy settings

verbose

Whether to print out information about the API call.

progress

Whether to show a progress bar of the API call.

timeout

Timeout in seconds (leave NULL for no timeout/curl default).

map

A leaflet map

routes

A list of route segments provided by getTargomoRoutes.

drawOptions

A list of routeDrawOptions to determine how to show the resulting routes on the map.

group

The leaflet map group to add the routes to. One group is used for all map elements being drawn per call to the API.

...

Further arguments to pass to addPolylines

Value

For 'get*', a list of objects of class "sf" containing the routes For 'draw*' and 'add*', the leaflet map returned with the routes drawn on.

See Also

draw-routes

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# load leaflet package
library(leaflet)
l <- leaflet()

# get route from Big Ben to Tower Bridge
r <- getTargomoRoutes(source_lat = 51.5007, source_lng = -0.1246,
                      target_lat = 51.5055, target_lng = -0.0754,
                      options = targomoOptions(travelType = c("bike", "transit")))

# draw the routes on the map
l %>% drawTargomoRoutes(routes = r)

# note, could combine get.. and draw... into one with add...

TargomoR documentation built on Dec. 7, 2019, 1:07 a.m.