Title: | Interactive Maps with R and Leaflet |
---|---|
Description: | Display spatial data with interactive maps powered by the open- source JavaScript library 'Leaflet' (see <https://leafletjs.com/>). Maps can be rendered in a web browser or displayed in the HTML viewer pane of 'RStudio'. This package is designed to be easy to use and can create complex maps with vector and raster data, web served map tiles and interface elements. |
Authors: | Francois Keck <[email protected]> |
Maintainer: | Francois Keck <[email protected]> |
License: | GPL-3 |
Version: | 0.2.1 |
Built: | 2024-11-13 03:12:41 UTC |
Source: | https://github.com/fkeck/rleafmap |
Define a new basemap layer from a tile server.
basemap( URL, name = NULL, alpha = 1, minZoom = 0, maxZoom = 18, tileSize = 256, tms = FALSE )
basemap( URL, name = NULL, alpha = 1, minZoom = 0, maxZoom = 18, tileSize = 256, tms = FALSE )
URL |
a character string giving the tile server url or a the name of a pre-configured server. |
name |
a character string to name the layer. |
alpha |
a numeric value in |
minZoom , maxZoom
|
numeric values setting the minimum and maximum zoom level. |
tileSize |
a numeric value setting tile size (width and height in pixels, assuming tiles are square). |
tms |
logical. If |
URL
should have the form 'http://{s}.somedomain.com/somepath/{z}/{x}/{y}.png'
with {s}
a facultative subdomain, {z}
the zoom level and {x}
, {y}
the coordinates.
rleafmap comes with a list of pre-configured servers. Names of these servers are returned
by the function bmSource
.
An object of class basemap
which can be directly used in writeMap
.
spLayer
to define data layers.
## Not run: #A simple map with two nice basemaps. bm1 <- basemap("mapquest.map") bm2 <- basemap("stamen.watercolor") writeMap(bm1, bm2) ## End(Not run)
## Not run: #A simple map with two nice basemaps. bm1 <- basemap("mapquest.map") bm2 <- basemap("stamen.watercolor") writeMap(bm1, bm2) ## End(Not run)
Take a tiles server url and return its attribution.
bmCredit(x)
bmCredit(x)
x |
a character string of the url of the server. |
The attribution of the server.
Take a tiles server name (as returned by bmSource
) and return its url.
bmServer(x)
bmServer(x)
x |
a character string of the name of the server. |
The url of the server.
Print a list of tiles servers ready-to-use with basemap
.
bmSource(print.servers = TRUE)
bmSource(print.servers = TRUE)
print.servers |
logical. Should the names of the servers be printed? |
Returns invisibly a matrix with servers names, urls and credits.
This dataset gives the number of ranked campsites and the number of tent pitches for each department of metropolitan France.
data(campsites)
data(campsites)
a SpatialPolygonsDataFrame
with geometries of the 96 french departements (epsg:4326) and 11 variables.
DEP.CODE The code number of each department.
DEP.NAME The name of each department.
CHF.NAME The name of the main (administrative) city of each department.
REGION.NAME The name of the administrative french region of each department.
N.CAMPSITES The number of campsites.
N.5, N.4, N.3, N.2, N.1 The number of campsites for each ranking categories (i.e. stars).
PITCHES The number of camp pitches for each department.
Institut National de l'Information Geographique et Forestiere (2014)
ATOUT FRANCE - Agence de developpement touristique de la France (2014).
This function creates multiple code chunks from a function and along arguments marked with a star (*). Each of these special arguments is a list. The nth code chunk will use the nth element of each marked list (recycled if necessary) as argument.
chunkerize( FUN, arg.names, arg.values, type = "block", echo = FALSE, warning = FALSE, error = FALSE, message = TRUE, fig.width = 4, fig.height = 4, fig.align = "center", options = NULL )
chunkerize( FUN, arg.names, arg.values, type = "block", echo = FALSE, warning = FALSE, error = FALSE, message = TRUE, fig.width = 4, fig.height = 4, fig.align = "center", options = NULL )
FUN |
the function to use for the chunks. |
arg.names |
a character vector giving the argument names of |
arg.values |
a vector giving the values or object names to assign to
each argument given with |
type |
the type of chunk to produce. Can be " |
echo |
logical indicating whether to include R source code in the result. |
warning |
logical indicating whether to print warnings in the result. |
error |
logical indicating whether to stop on errors. |
message |
logical indicating whether to print messages in the result. |
fig.width , fig.height
|
numeric value setting width and height of the plots in inches. |
fig.align |
character string setting the alignment of the plots. Can be " |
options |
a character string to specify the knitr options. This will overwrite the options set with the other arguments. |
a character vector of R code chunks which can be evaluated by knitr.
This dataset gives the number of hotels, number of rooms and capacity for each department of metropolitan France.
data(hotels)
data(hotels)
a SpatialPolygonsDataFrame
with geometries of the 96 french departements (epsg:4326) and 12 variables.
DEP.CODE The code number of each department.
DEP.NAME The name of each department.
CHF.NAME The name of the main (administrative) city of each department.
REGION.NAME The name of the french region (administrative) of each department.
N.HOTELS The number of hotels.
N.5, N.4, N.3, N.2, N.1 The number of hotels for each ranking categories (i.e. stars).
ROOMS The number of hotel's rooms for each department.
CAPACITY The total capacity (beds) for each department.
Institut National de l'Information Geographique et Forestiere (2014)
ATOUT FRANCE - Agence de developpement touristique de la France (2014).
This function creates a legend object that can be attached to a data layer.
layerLegend( style, labels = "", title = NULL, position = "bottomright", png = NULL, size = 5, png.width = NULL, png.height = NULL, stroke.col = 1, stroke.lwd = 1, stroke.lty = -1, stroke.alpha = 1, fill.col = 2, fill.alpha = 0.5, cells.range = c(1, 10), cells.col = heat.colors(12), cells.alpha = 1 )
layerLegend( style, labels = "", title = NULL, position = "bottomright", png = NULL, size = 5, png.width = NULL, png.height = NULL, stroke.col = 1, stroke.lwd = 1, stroke.lty = -1, stroke.alpha = 1, fill.col = 2, fill.alpha = 0.5, cells.range = c(1, 10), cells.col = heat.colors(12), cells.alpha = 1 )
style |
the style of legend to generate.
Can be one of " |
labels |
a vector to label each element of the legend. |
title |
a title which will appear above the legend.
If |
position |
a character string indicating where should the legend be displayed.
This must be one of " |
png |
character vector giving the paths for the PNG icons. If |
size |
a numerical vector giving the size of points (radius in pixels). |
png.width , png.height
|
numerical vectors giving the PNG icons dimensions on the map (in pixels). |
stroke.col |
a vector of any of the three kinds of R color specifications to set strokes color. |
stroke.lwd |
a numerical vector to set strokes width. |
stroke.lty |
a character vector that defines the strokes dash patterns (See Details). |
stroke.alpha |
a vector of numeric values in |
fill.col |
a vector of any of the three kinds of R color specifications to set fill colors. |
fill.alpha |
a vector of numeric values in |
cells.range |
range of gradient values. |
cells.col |
a vector of any of the three kinds of R color specifications giving the colors of the gradient. |
cells.alpha |
a vector of numeric values in |
an object layerlegend
which can be passed to an spLayer*
function through the legend
argument.
Print spl objects
## S3 method for class 'splpoints' print(x, ...) ## S3 method for class 'splicons' print(x, ...) ## S3 method for class 'spllines' print(x, ...) ## S3 method for class 'splpolygons' print(x, ...) ## S3 method for class 'splgrid' print(x, ...)
## S3 method for class 'splpoints' print(x, ...) ## S3 method for class 'splicons' print(x, ...) ## S3 method for class 'spllines' print(x, ...) ## S3 method for class 'splpolygons' print(x, ...) ## S3 method for class 'splgrid' print(x, ...)
x |
an |
... |
additional arguments. Not used. |
Display spatial data with interactive maps powered by the open- source JavaScript library 'Leaflet' (see <https://leafletjs.com/>). Maps can be rendered in a web browser or displayed in the HTML viewer pane of 'RStudio'. This package is designed to be easy to use and can create complex maps with vector and raster data, web served map tiles and interface elements.
Define a new data layer from an object sp.
spLayer(x, ...)
spLayer(x, ...)
x |
a spatial object as defined in the package sp. |
... |
additional arguments to pass to the function. |
## Not run: #POINTS data(velov) vv <- spLayer(velov, stroke=F, popup=velov$NAME) #POLYGONS data(campsites) gcol <- rev(heat.colors(5)) gcut <- cut(mapdep$N.CAMPSITES, breaks=c(-1, 20, 40, 60, 80, 1000)) cs <- spLayer(campsites, fill.col=as.numeric(gcut)) bm1 <- basemap("mapquest.map") writeMap(bm1, cs, vv) ## End(Not run)
## Not run: #POINTS data(velov) vv <- spLayer(velov, stroke=F, popup=velov$NAME) #POLYGONS data(campsites) gcol <- rev(heat.colors(5)) gcut <- cut(mapdep$N.CAMPSITES, breaks=c(-1, 20, 40, 60, 80, 1000)) cs <- spLayer(campsites, fill.col=as.numeric(gcut)) bm1 <- basemap("mapquest.map") writeMap(bm1, cs, vv) ## End(Not run)
Define a Vector Data Layer
## Default S3 method: spLayer(x, ...)
## Default S3 method: spLayer(x, ...)
x |
a spatial object as defined in the package sp. |
... |
additional arguments to pass to the function. |
spLayer.SpatialGridDataFrame
defines a new data layer from an object SpatialGridDataFrame
.
## S3 method for class 'SpatialGridDataFrame' spLayer( x, name = NULL, layer, cells.col = heat.colors(12), cells.alpha = 1, legend = NULL, ... )
## S3 method for class 'SpatialGridDataFrame' spLayer( x, name = NULL, layer, cells.col = heat.colors(12), cells.alpha = 1, legend = NULL, ... )
x |
a spatial object (see Details). |
name |
a character string to name the layer. |
layer |
which layer to select? |
cells.col |
a vector of any of the three kinds of R color specifications giving a gradient to color the grid. |
cells.alpha |
a vector of numeric values in |
legend |
a legend object created with |
... |
additional arguments to pass to the function. |
Define a Vector Data Layer
## S3 method for class 'SpatialLines' spLayer( x, name = NULL, stroke = TRUE, stroke.col = 1, stroke.lwd = 1, stroke.lty = -1, stroke.alpha = 1, label = NULL, popup = "", popup.rmd = FALSE, legend = NULL, ... )
## S3 method for class 'SpatialLines' spLayer( x, name = NULL, stroke = TRUE, stroke.col = 1, stroke.lwd = 1, stroke.lty = -1, stroke.alpha = 1, label = NULL, popup = "", popup.rmd = FALSE, legend = NULL, ... )
x |
a spatial object (see Details). |
name |
a character string to name the layer. |
stroke |
logical. Should a stroke be drawn along lines and polygons? |
stroke.col |
a vector of any of the three kinds of R color specifications to set strokes color. |
stroke.lwd |
a numerical vector to set strokes width. |
stroke.lty |
a character vector that defines the strokes dash patterns (See Details). |
stroke.alpha |
a vector of numeric values in |
label |
a reserved argument (in development). |
popup |
a character vector giving contents for popups. HTML tags are accepted. |
popup.rmd |
a logical indicating whether the popups should be processed as R Markdown with knitr. Default |
legend |
a legend object created with |
... |
additional arguments to pass to the function. |
spLayer.SpatialPoints
defines a new data layer from an object SpatialPoints
or SpatialPointsDataFrame
spLayer.SpatialLines
defines a new data layer from an object SpatialLines
or SpatialLinesDataFrame
spLayer.SpatialPolygons
defines a new data layer from an object SpatialPolygons
or SpatialPolygonsDataFrame
## S3 method for class 'SpatialPoints' spLayer( x, name = NULL, png = NULL, size = 5, png.width = 15, png.height = 15, stroke = TRUE, stroke.col = 1, stroke.lwd = 1, stroke.lty = -1, stroke.alpha = 1, fill = TRUE, fill.col = 2, fill.alpha = 0.5, label = NULL, popup = "", popup.rmd = FALSE, legend = NULL, ... )
## S3 method for class 'SpatialPoints' spLayer( x, name = NULL, png = NULL, size = 5, png.width = 15, png.height = 15, stroke = TRUE, stroke.col = 1, stroke.lwd = 1, stroke.lty = -1, stroke.alpha = 1, fill = TRUE, fill.col = 2, fill.alpha = 0.5, label = NULL, popup = "", popup.rmd = FALSE, legend = NULL, ... )
x |
a spatial object (see Details). |
name |
a character string to name the layer. |
png |
character vector giving the paths for the PNG icons. If |
size |
a numerical vector giving the size of points (radius in pixels). |
png.width , png.height
|
numerical vectors giving the PNG icons dimensions on the map (in pixels). |
stroke |
logical. Should a stroke be drawn along lines and polygons? |
stroke.col |
a vector of any of the three kinds of R color specifications to set strokes color. |
stroke.lwd |
a numerical vector to set strokes width. |
stroke.lty |
a character vector that defines the strokes dash patterns (See Details). |
stroke.alpha |
a vector of numeric values in |
fill |
logical. Should points and polygons be filled? |
fill.col |
a vector of any of the three kinds of R color specifications to set fill colors. |
fill.alpha |
a vector of numeric values in |
label |
a reserved argument (in development). |
popup |
a character vector giving contents for popups. HTML tags are accepted. |
popup.rmd |
a logical indicating whether the popups should be processed as R Markdown with knitr. Default |
legend |
a legend object created with |
... |
additional arguments to pass to the function. |
Define a Vector Data Layer
## S3 method for class 'SpatialPolygons' spLayer( x, name = NULL, stroke = TRUE, stroke.col = 1, stroke.lwd = 1, stroke.lty = -1, stroke.alpha = 1, fill = TRUE, fill.col = 2, fill.alpha = 0.5, label = NULL, popup = "", popup.rmd = FALSE, holes = FALSE, legend = NULL, ... )
## S3 method for class 'SpatialPolygons' spLayer( x, name = NULL, stroke = TRUE, stroke.col = 1, stroke.lwd = 1, stroke.lty = -1, stroke.alpha = 1, fill = TRUE, fill.col = 2, fill.alpha = 0.5, label = NULL, popup = "", popup.rmd = FALSE, holes = FALSE, legend = NULL, ... )
x |
a spatial object (see Details). |
name |
a character string to name the layer. |
stroke |
logical. Should a stroke be drawn along lines and polygons? |
stroke.col |
a vector of any of the three kinds of R color specifications to set strokes color. |
stroke.lwd |
a numerical vector to set strokes width. |
stroke.lty |
a character vector that defines the strokes dash patterns (See Details). |
stroke.alpha |
a vector of numeric values in |
fill |
logical. Should points and polygons be filled? |
fill.col |
a vector of any of the three kinds of R color specifications to set fill colors. |
fill.alpha |
a vector of numeric values in |
label |
a reserved argument (in development). |
popup |
a character vector giving contents for popups. HTML tags are accepted. |
popup.rmd |
a logical indicating whether the popups should be processed as R Markdown with knitr. Default |
holes |
a logical indicating whether to use the |
legend |
a legend object created with |
... |
additional arguments to pass to the function. |
This function tests arguments validity for the function spLayer
.
spLayerControl( name, size = 1, legend = legend, stroke = TRUE, stroke.col = 1, stroke.lwd = 1, stroke.lty = 1, stroke.alpha = 1, fill = TRUE, fill.col = 1, fill.alpha = 1, label = "", popup = "", holes = FALSE )
spLayerControl( name, size = 1, legend = legend, stroke = TRUE, stroke.col = 1, stroke.lwd = 1, stroke.lty = 1, stroke.alpha = 1, fill = TRUE, fill.col = 1, fill.alpha = 1, label = "", popup = "", holes = FALSE )
name |
a character string to name the layer. |
size |
a numerical vector giving the size of points (radius in pixels). |
legend |
a legend object created with |
stroke |
logical. Should a stroke be drawn along lines and polygons? |
stroke.col |
a vector of any of the three kinds of R color specifications to set strokes color. |
stroke.lwd |
a numerical vector to set strokes width. |
stroke.lty |
a character vector that defines the strokes dash patterns (See Details). |
stroke.alpha |
a vector of numeric values in |
fill |
logical. Should points and polygons be filled? |
fill.col |
a vector of any of the three kinds of R color specifications to set fill colors. |
fill.alpha |
a vector of numeric values in |
label |
a reserved argument (in development). |
popup |
a character vector giving contents for popups. HTML tags are accepted. |
holes |
a logical indicating whether to use the |
Get a summary of a map element.
## S3 method for class 'basemap' summary(object, ...) ## S3 method for class 'splpoints' summary(object, ...) ## S3 method for class 'splicons' summary(object, ...) ## S3 method for class 'spllines' summary(object, ...) ## S3 method for class 'splpolygons' summary(object, ...) ## S3 method for class 'splgrid' summary(object, ...) ## S3 method for class 'ui' summary(object, ...)
## S3 method for class 'basemap' summary(object, ...) ## S3 method for class 'splpoints' summary(object, ...) ## S3 method for class 'splicons' summary(object, ...) ## S3 method for class 'spllines' summary(object, ...) ## S3 method for class 'splpolygons' summary(object, ...) ## S3 method for class 'splgrid' summary(object, ...) ## S3 method for class 'ui' summary(object, ...)
object |
a map layer, |
... |
additional arguments. Not used. |
This function is used internally by writeMap
to convert a given spl
object to GeoJSON format.
toGeoJSON(x, lightjson = F)
toGeoJSON(x, lightjson = F)
x |
a |
lightjson |
logical. Should GeoJSON code size be reduced by supressing extra whitespace characters and rounding numeric values? |
A character string of GeoJSON formatted code.
This function is used internally by writeMap
to generate Leaflet JavaScript code for a given layer.
toJS(x, url = "")
toJS(x, url = "")
x |
a |
url |
a character string giving the path for the raster files. |
A character string of JavaScript Code.
Allow the user to choose which interface elements are displayed on the map and their positions.
ui( zoom = c("topleft", "topright", "bottomleft", "bottomright", "none"), layers = c("none", "topright", "topleft", "bottomleft", "bottomright"), attrib = c("bottomright", "topleft", "topright", "bottomleft", "none"), attrib.text = "" )
ui( zoom = c("topleft", "topright", "bottomleft", "bottomright", "none"), layers = c("none", "topright", "topleft", "bottomleft", "bottomright"), attrib = c("bottomright", "topleft", "topright", "bottomleft", "none"), attrib.text = "" )
zoom |
a character string indicating if and how should the zoom control be displayed.
This must be one of " |
layers |
a character string indicating if and how should the layers control be displayed.
This must be one of " |
attrib |
a character string indicating if and how should the attribution control be displayed.
This must be one of " |
attrib.text |
a character string for additionnal credits. HTML tags are accepted. |
An object of class ui
which can be directly given as interface
argument of writeMap
.
This function is used internally by writeMap
to generate JavaScript code
related to the user interface.
uiJS(interface, ar)
uiJS(interface, ar)
interface |
an |
ar |
a list of |
Stations of the bicycle sharing system of the city of Lyon (France).
data(velov)
data(velov)
a SpatialPointsDataFrame
with the location and name of the 349 Velov stations (epsg:4326).
OpenStreetMap (14/04/2014)
This function combines all the elements specified by the user and write the corresponding HTML and Javascript code in a local directory.
writeMap( ..., dir = getwd(), prefix = "", width = 700, height = 400, setView = NULL, setZoom = NULL, interface = NULL, lightjson = FALSE, directView = c("viewer", "browser", "disabled"), leaflet.loc = "online", popup.style = NULL )
writeMap( ..., dir = getwd(), prefix = "", width = 700, height = 400, setView = NULL, setZoom = NULL, interface = NULL, lightjson = FALSE, directView = c("viewer", "browser", "disabled"), leaflet.loc = "online", popup.style = NULL )
... |
|
dir |
a character string giving the directory path to export the map. Default is the working directory. |
prefix |
a character string to add a prefix to file names. This allows multiple exportations in the same directory. |
width , height
|
the width and height of the map, in pixels. |
setView |
a numeric vector of the form |
setZoom |
a numeric value setting the initial map zoom. |
interface |
an |
lightjson |
logical. Should GeoJSON files size be reducedby supressing
extra whitespace characters and rounding numeric values? Default is |
directView |
a character string indicating if and how should the map be displayed.
Default option " |
leaflet.loc |
a character string specifying the location (directory) of the leaflet library.
If set to " |
popup.style |
an optional character string of CSS to customize popups content properties (width, color, etc). |