leaflet | R Documentation |
Creates a web-map of users' spatial data over open base maps. Output consists of a ready to use HTML file (and a GeoJSON/TopoJSON data file).
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 |
Name(s) of data file(s) (GeoJSON/TopoJSON format), as string or a list of strings. Plotting order follows the file sequence. |
dest |
Path to the |
title |
Map title, as string. Default is |
size |
Size of the map on the website in pixels, as numeric vector – |
base.map |
Base map(s) in the background of the data, as string. One or a list of |
center |
Map center coordinates in decimal degrees, as vector of two numeric values: |
zoom |
Map zoom level, as integer value. Usually a value between |
style |
Style(s) of the data layer(s). One or a list of style object(s), created by |
popup |
Properties (attributes) of the data to be shown in a popup when a map object is clicked. String or a vector of strings. |
label |
Property (attribute) of the data to be shown in a dynamic label, as string. A |
controls |
List of controls to be added to the map. Available controls are |
incl.data |
If |
overwrite |
|
HTML file path, as string.
data
only accepts GeoJSON/TopoJSON files with one geometry type and geographical coordinates (longlat, WGS84).
Due to the security restrictions of some browsers (namely Chrome and Opera) it might be necessary to save the data inside the html file using incl.data = TRUE
.
Christian Graul
Base map tiles are provided by
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 | |
CartoDB Dark matter | 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.