
leaflet(data, dest, title, size, base.map="osm", center, zoom, style, popup, label, controls="all", incl.data=FALSE, overwrite=TRUE)
leaf(data, dest, title, size, base.map="osm", center, zoom, style, popup, label, controls="all", incl.data=FALSE, overwrite=TRUE)
data
file, as string. Optional -- if missing, the current working directory is used."map"
.c(width, height)
. Optional -- if missing, a fullscreen (browser window) map is generated."osm"
(OpenStreetMap standard map), "tls"
(Thunderforest Landscape), "mqosm"
(MapQuest OSM), "mqsat"
(MapQuest Open Aerial), "water"
(Stamen Watercolor), "toner"
(Stamen Toner), "tonerbg"
(Stamen Toner background), "tonerlite"
(Stamen Toner lite), "positron"
(CartoDB Positron) or "darkmatter"
(CartoDB Dark matter). Default is "osm"
. If base.map
is a list, the last item is used as default base map and a layer control button is added to the map.c(latitude, longitude)
. Optional -- if missing, the data layer is centered automatically. code
has to be specified to use center
.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 missing, the zoom level is calculated for the bounding box of the data layer. center
has to be specified to use zoom
.styleSingle
, styleGrad
or styleCat
. Optional -- if missing, a default style is applied."*"
adds all available properties to the popup. A list
of (vectors of) strings specifies properties for multiple data
layers. Per default no popups are shown.list
of strings specifies properties for multiple data
layers. Per default no labels are shown. Only point data is supported and markers do not work very well."zoom"
, "scale"
, "layer"
and "legend"
. "all"
(the default) adds all controls. Controls are only added if necessary, e.g. in case of one data layer there is no legend. NA
omits all controls. Note: data layer controls only appear if incl.data
is set to TRUE
.TRUE
, data
is included in the HTML file itself. Per default (incl.data=FALSE
) the data is saved in a separate file. Including data in the HTML file allows for viewing the map locally on some browsers (e.g. Chrome and Opera).TRUE
(which is the default) overwrites existing files with the same name.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 |
Stamen Toner background | |
http://stamen.com | |
Stamen Toner lite | http://stamen.com |
CartoDB Positron | |
http://cartodb.com |
styleSingle
, styleGrad
, styleCat
## Not run:
# # prepare data
# data(quakes)
# dat <- toGeoJSON(data=quakes, dest=tempdir())
#
# # create and view simple map
# map <- leaflet(dat, dest=tempdir())
# map # redirects to browseURL(map)
#
# # set output directory and map title
# map <- leaflet(data=dat, dest=tempdir(), title="Fiji Earthquakes")
#
# # 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)
#
# # set base map and popup/label
# # magnitude is used as popup (type names(quakes) for available properties)
# map <- leaflet(data=dat, dest=tempdir(),
# base.map="mqsat", popup="stations", label="mag")
#
# # minimalist? - no base map
# map <- leaflet(data=dat, dest=tempdir(),
# base.map=NA, popup="mag")
#
# # include data in HTML file
# map <- leaflet(dat, dest=tempdir(), incl.data=TRUE)
#
# # preserve existing files from overwriting
# map <- leaflet(dat, dest=tempdir(), overwrite=FALSE)
#
# # more than one base map
# map <- leaflet(data=dat, dest=tempdir(),
# base.map=list("osm", "mqsat", "tls"))
#
# # multiple properties in the popup
# map <- leaflet(data=dat, dest=tempdir(),
# popup=c("mag", "depth"))
#
# # all available properties in the popup
# map <- leaflet(data=dat, dest=tempdir(),
# popup="*")
#
# # change style
# sty <- styleSingle(col="red", fill=NA)
# map <- leaflet(data=dat, dest=tempdir(), base.map="mqsat", style=sty)
#
# # controls
# map <- leaflet(data=dat, dest=tempdir(), controls=NA) # no controls
# map <- leaflet(data=dat, dest=tempdir(), controls="scale") # scale only
# map <- leaflet(data=dat, dest=tempdir(), controls=c("zoom", "scale"))
#
# # more than one data set
# park <- system.file(package="leafletR", "files", "park_sk.geojson")
# peak <- toGeoJSON(system.file(package="leafletR", "files", "peak_sk.kmz"),
# dest=tempdir()) # httr package required
# 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"))
#
# # names in legend
# # note: "_" and "." are replaced with blanks in the legend
# map <- leaflet(data=list(National_Parks=park, Peaks.above.600.m)=peak),
# dest=tempdir(), style=list(sty.1, sty.2), popup=list("*", "Name"))
# ## End(Not run)
Run the code above in your browser using DataLab