Learn R Programming

leafletR (version 0.2-1)

leaflet: Create a Leaflet web-map

Description

Creates a web-map of users' spatial data over open-source base maps. Output consists of a ready to use HTML file and a GeoJSON data file.

Usage

leaflet(data, dest, title, size, base.map="osm", center, 
  zoom, style, popup, incl.data=FALSE, overwrite=TRUE)
leaf(data, dest, title, size, base.map="osm", center, 
  zoom, style, popup, incl.data=FALSE, overwrite=TRUE)

Arguments

data
Name(s) of data file(s) (GeoJSON format), as string or a list of strings. Plotting order follows the file sequence.
dest
Path to the data file, as string. Optional -- if missing, the current working directory is used.
title
Map title, as string. Default is "map".
size
Size of the map on the website in pixels, as numeric vector -- c(width, height). Optional -- if missing, a fullscreen (browser window) map is generated.
base.map
Base map(s) in the background of the data, as string. One or a list of "osm" (OpenStreetMap standard map), "tls" (Thunderforest Landscape), "mqosm" (MapQuest OSM), "mqsat" (MapQuest Open Aerial), "
center
Map center coordinates in decimal degrees, as vector of two numeric values: c(latitude, longitude). Optional -- if missing, the data layer is centered automatically.
zoom
Map zoom level, as integer value. Usually a value between 0 (global small scale) and 18 (detailed large scale). The MapQuest Open Aerial map (base.map="mqsat") provides only 12 zoom levels [0-11]. Optional -- if miss
style
Style(s) of the data layer(s). One or a list of style object(s), created by styleSingle, styleGrad or styleCat

Value

  • HTML file path, as string.

References

Base map tiles are provided by lll{ OpenStreetMap standard map http://www.openstreetmap.org Thunderforest Landscape http://www.thunderforest.com MapQuest OSM http://www.mapquest.com MapQuest Open Aerial http://www.mapquest.com Stamen Watercolor http://stamen.com Stamen Toner http://stamen.com }

See Also

styleSingle, styleGrad, styleCat

Examples

Run this code
# prepare data
data(quakes)
dat <- toGeoJSON(data=quakes, dest=tempdir())

# create map quick and simple
map <- leaflet(dat)
browseURL(map)

# set output directory and map title
map <- leaflet(data=dat, dest=tempdir(), title="Fiji Earthquakes")
browseURL(map)

# set map size, center and zoom level
map <- leaflet(data=dat, dest=tempdir(), 
  size=c(800,600), center=c(-18.35, 179.75), zoom=6)
browseURL(map)

# set base map and popup
# magnitude is used as popup (type names(quakes) for available properties)
map <- leaflet(data=dat, dest=tempdir(), 
  base.map="mqsat", popup="mag")
browseURL(map)

# include data in HTML file
map <- leaflet(dat, incl.data=TRUE)
browseURL(map)

# preserve existing files from overwriting
map <- leaflet(dat, overwrite=FALSE)

# more than one base map
map <- leaflet(data=dat, dest=tempdir(), 
  base.map=list("osm", "mqsat", "tls"))
browseURL(map)

# multiple properties in the popup
map <- leaflet(data=dat, dest=tempdir(), 
  popup=c("mag", "depth"))
browseURL(map)

# all available properties in the popup
map <- leaflet(data=dat, dest=tempdir(), 
  popup="*")
browseURL(map)

# change style
sty <- styleSingle(col="red", fill=NA)
map <- leaflet(data=dat, dest=tempdir(), base.map="mqsat", style=sty)
browseURL(map)

# more than one data set
park <- toGeoJSON(data=system.file(package="leafletR", "files", 
  "park_sk.zip"), dest=tempdir())
peak <- toGeoJSON(system.file(package="leafletR", "files", "peak_sk.kml"), 
  dest=tempdir())
sty.1 <- styleSingle(col="green", fill="green")
sty.2 <- styleSingle(col="brown", fill="brown", rad=3)
map <- leaflet(data=list(park, peak), dest=tempdir(), 
  style=list(sty.1, sty.2), popup=list("*", "Name"))
browseURL(map)

map <- leaflet(data=list(National.Parks=park, Peaks=peak), dest=tempdir(), 
  style=list(sty.1, sty.2), popup=list("*", "Name"))  # names in legend
browseURL(map)

Run the code above in your browser using DataLab