From d16e19217252a0084c58ded93efbd6f5c1fce0aa Mon Sep 17 00:00:00 2001 From: tim-salabim Date: Tue, 30 Jan 2018 21:25:33 +0100 Subject: [PATCH 01/94] prepare news in develop after cran submission --- NEWS.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/NEWS.md b/NEWS.md index 6144a564f..8871be394 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,8 @@ ## mapview 2.3.0 + +## mapview 2.3.0 + new features: * popupTable has gained argument row.numbers to disable row numbers. #109 From 4a7b4bd017e4e1944d2a8e6a98c253ee9a2d3fb0 Mon Sep 17 00:00:00 2001 From: tim-salabim Date: Wed, 31 Jan 2018 19:52:38 +0100 Subject: [PATCH 02/94] re-enable stars. add argument label to mapview raster mathods. --- NAMESPACE | 1 + R/mapView.R | 122 ++++++++++++++++++++++--------------------- R/mapview-package.R | 2 +- R/raster.R | 8 ++- man/mapView.Rd | 11 ++-- man/mapview-class.Rd | 19 ++++++- 6 files changed, 96 insertions(+), 67 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 583de8f59..b1fd2b98e 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -54,6 +54,7 @@ import(satellite) import(scales) import(sf) import(sp) +import(stars) import(viridisLite) importFrom(grDevices,colorRampPalette) importFrom(grDevices,dev.off) diff --git a/R/mapView.R b/R/mapView.R index 532c44d3c..5c89628e5 100644 --- a/R/mapView.R +++ b/R/mapView.R @@ -60,8 +60,9 @@ if ( !isGeneric('mapView') ) { #' @param popup a \code{list} of HTML strings with the popup contents, usually #' created from \code{\link{popupTable}}. See \code{\link{addControl}} for #' details. -#' @param label a character vector of labels to be shown on mouseover. See -#' \code{\link{addControl}} for details. +#' @param label For vector data (sf/sp) a character vector of labels to be +#' shown on mouseover. See \code{\link{addControl}} for details. For raster +#' data (Raster*/stars) a logical indicating whether to add image query. #' @param native.crs logical whether to reproject to web map coordinate #' reference system (web mercator - epsg:3857) or render using native CRS of #' the supplied data (can also be NA). Default is FALSE which will render in @@ -228,6 +229,7 @@ setMethod('mapView', signature(x = 'RasterLayer'), homebutton = TRUE, native.crs = FALSE, method = c("bilinear", "ngb"), + label = TRUE, ...) { method = match.arg(method) @@ -264,6 +266,7 @@ setMethod('mapView', signature(x = 'RasterLayer'), homebutton = homebutton, native.crs = native.crs, method = method, + label = label, ...) } else { NULL @@ -274,63 +277,62 @@ setMethod('mapView', signature(x = 'RasterLayer'), ) -# ## Stars layer ================================================================== -# #' @describeIn mapview \code{stars} -# -# setMethod('mapView', signature(x = 'stars'), -# function(x, -# map = NULL, -# maxpixels = mapviewGetOption("mapview.maxpixels"), -# col.regions = mapviewGetOption("raster.palette")(256), -# at = NULL, -# na.color = mapviewGetOption("na.color"), -# use.layer.names = FALSE, -# values = NULL, -# map.types = mapviewGetOption("basemaps"), -# alpha.regions = 0.8, -# legend = mapviewGetOption("legend"), -# legend.opacity = 1, -# trim = TRUE, -# verbose = mapviewGetOption("verbose"), -# layer.name = NULL, -# homebutton = TRUE, -# native.crs = FALSE, -# method = c("bilinear", "ngb"), -# ...) { -# -# method = match.arg(method) -# -# if (is.null(at)) at <- lattice::do.breaks( -# extendLimits(range(as.numeric(x[[1]][, , 1]), -# na.rm = TRUE)), 256 -# ) -# -# if (mapviewGetOption("platform") == "leaflet") { -# leaflet_stars(x, -# map = map, -# maxpixels = maxpixels, -# col.regions = col.regions, -# at = at, -# na.color, na.color, -# use.layer.names = use.layer.names, -# values = values, -# map.types = map.types, -# alpha.regions = alpha.regions, -# legend = legend, -# legend.opacity = legend.opacity, -# trim = trim, -# verbose = verbose, -# layer.name = layer.name, -# homebutton = homebutton, -# native.crs = native.crs, -# method = method, -# ...) -# } else { -# NULL -# } -# -# } -# ) +## Stars layer ================================================================== +#' @describeIn mapview \code{stars} +setMethod('mapView', signature(x = 'stars'), + function(x, + map = NULL, + maxpixels = mapviewGetOption("mapview.maxpixels"), + col.regions = mapviewGetOption("raster.palette")(256), + at = NULL, + na.color = mapviewGetOption("na.color"), + use.layer.names = FALSE, + values = NULL, + map.types = mapviewGetOption("basemaps"), + alpha.regions = 0.8, + legend = mapviewGetOption("legend"), + legend.opacity = 1, + trim = TRUE, + verbose = mapviewGetOption("verbose"), + layer.name = NULL, + homebutton = TRUE, + native.crs = FALSE, + method = c("bilinear", "ngb"), + ...) { + + method = match.arg(method) + + if (is.null(at)) at <- lattice::do.breaks( + extendLimits(range(as.numeric(x[[1]][, , 1]), + na.rm = TRUE)), 256 + ) + + if (mapviewGetOption("platform") == "leaflet") { + leaflet_stars(x, + map = map, + maxpixels = maxpixels, + col.regions = col.regions, + at = at, + na.color, na.color, + use.layer.names = use.layer.names, + values = values, + map.types = map.types, + alpha.regions = alpha.regions, + legend = legend, + legend.opacity = legend.opacity, + trim = trim, + verbose = verbose, + layer.name = layer.name, + homebutton = homebutton, + native.crs = native.crs, + method = method, + ...) + } else { + NULL + } + + } +) @@ -353,6 +355,7 @@ setMethod('mapView', signature(x = 'RasterStackBrick'), verbose = mapviewGetOption("verbose"), homebutton = TRUE, method = c("bilinear", "ngb"), + label = TRUE, ...) { if (mapviewGetOption("platform") == "leaflet") { @@ -371,6 +374,7 @@ setMethod('mapView', signature(x = 'RasterStackBrick'), verbose = verbose, homebutton = homebutton, method = method, + label = label, ...) } else { NULL diff --git a/R/mapview-package.R b/R/mapview-package.R index bf6ee127a..46147024d 100644 --- a/R/mapview-package.R +++ b/R/mapview-package.R @@ -14,7 +14,7 @@ #' \cr #' \emph{Maintainer:} Tim Appelhans \email{tim.appelhans@gmail.com} #' -#' @import leaflet sp sf raster satellite scales Rcpp methods png lattice gdalUtils viridisLite base64enc +#' @import leaflet sp sf raster satellite stars scales Rcpp methods png lattice gdalUtils viridisLite base64enc #' @importFrom grDevices rgb dev.off png svg colorRampPalette #' @importFrom utils find glob2rx #' @importFrom webshot webshot diff --git a/R/raster.R b/R/raster.R index a74f465ba..831862442 100644 --- a/R/raster.R +++ b/R/raster.R @@ -23,6 +23,7 @@ leafletRL = function(x, homebutton, native.crs, method, + label, ...) { if (inherits(map, "mapview")) map = mapview2leaflet(map) @@ -110,7 +111,8 @@ leafletRL = function(x, group = grp, layerId = grp, ...) - m = addImageQuery(m, x, group = grp, layerId = grp, position = "topright") + if (label) + m = addImageQuery(m, x, group = grp, layerId = grp, position = "topright") if (legend) { ## add legend # m = leaflet::addLegend(map = m, @@ -167,6 +169,7 @@ leafletRSB = function(x, layer.name, homebutton, method, + label, ...) { pkgs = c("leaflet", "raster", "magrittr") @@ -190,6 +193,7 @@ leafletRSB = function(x, layer.name = layer.name, homebutton = homebutton, method = method, + label = label, ...) out = new('mapview', object = list(x), map = m@map) } else { @@ -204,6 +208,7 @@ leafletRSB = function(x, legend = legend, homebutton = homebutton, method = method, + label = label, ...) for (i in 2:nlayers(x)) { m = mapView(x[[i]], @@ -217,6 +222,7 @@ leafletRSB = function(x, legend = legend, homebutton = FALSE, method = method, + label = label, ...) } diff --git a/man/mapView.Rd b/man/mapView.Rd index 1995aa621..c0e249945 100644 --- a/man/mapView.Rd +++ b/man/mapView.Rd @@ -44,7 +44,7 @@ alpha.regions = 0.8, legend = mapviewGetOption("legend"), legend.opacity = 1, trim = TRUE, verbose = mapviewGetOption("verbose"), layer.name = NULL, homebutton = TRUE, native.crs = FALSE, - method = c("bilinear", "ngb"), ...) + method = c("bilinear", "ngb"), label = TRUE, ...) \S4method{mapView}{RasterStackBrick}(x, map = NULL, maxpixels = mapviewGetOption("mapview.maxpixels"), @@ -53,7 +53,7 @@ values = NULL, map.types = mapviewGetOption("basemaps"), legend = mapviewGetOption("legend"), legend.opacity = 1, trim = TRUE, verbose = mapviewGetOption("verbose"), homebutton = TRUE, - method = c("bilinear", "ngb"), ...) + method = c("bilinear", "ngb"), label = TRUE, ...) \S4method{mapView}{Satellite}(x, map = NULL, maxpixels = mapviewGetOption("mapview.maxpixels"), @@ -240,6 +240,10 @@ which is appropriate for continuous variables. The other option, 'ngb' (nearest neighbor), is useful for categorical variables. Ignored if the raster layer is of class \code{factor} in which case "ngb" is used.} +\item{label}{For vector data (sf/sp) a character vector of labels to be +shown on mouseover. See \code{\link{addControl}} for details. For raster +data (Raster*/stars) a logical indicating whether to add image query.} + \item{...}{additional arguments passed on to repective functions. See \code{\link{addRasterImage}}, \code{\link{addCircles}}, \code{\link{addPolygons}}, \code{\link{addPolylines}} for details} @@ -265,9 +269,6 @@ of the column(s) to be used for defining the size of circles} created from \code{\link{popupTable}}. See \code{\link{addControl}} for details.} -\item{label}{a character vector of labels to be shown on mouseover. See -\code{\link{addControl}} for details.} - \item{highlight}{either \code{FALSE}, \code{NULL} or a list of styling options for feature highlighting on mouse hover. See \code{\link{highlightOptions}} for details.} diff --git a/man/mapview-class.Rd b/man/mapview-class.Rd index 34069dbc6..1f1bb9436 100644 --- a/man/mapview-class.Rd +++ b/man/mapview-class.Rd @@ -1,12 +1,29 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/AAAmapviewClasses.R +% Please edit documentation in R/AAAmapviewClasses.R, R/mapView.R \docType{class} \name{mapview-class} \alias{mapview-class} +\alias{mapView,stars-method} \title{Class mapview} +\usage{ +\S4method{mapView}{stars}(x, map = NULL, + maxpixels = mapviewGetOption("mapview.maxpixels"), + col.regions = mapviewGetOption("raster.palette")(256), at = NULL, + na.color = mapviewGetOption("na.color"), use.layer.names = FALSE, + values = NULL, map.types = mapviewGetOption("basemaps"), + alpha.regions = 0.8, legend = mapviewGetOption("legend"), + legend.opacity = 1, trim = TRUE, verbose = mapviewGetOption("verbose"), + layer.name = NULL, homebutton = TRUE, native.crs = FALSE, + method = c("bilinear", "ngb"), ...) +} \description{ Class mapview } +\section{Methods (by generic)}{ +\itemize{ +\item \code{mapView}: \code{stars} +}} + \section{Slots}{ \describe{ From ab5a02f97dd8aaa89614b19f6665703bf8fb44be Mon Sep 17 00:00:00 2001 From: tim-salabim Date: Wed, 31 Jan 2018 19:52:59 +0100 Subject: [PATCH 03/94] update news and bump version --- DESCRIPTION | 5 +++-- NEWS | 7 +++++++ NEWS.md | 6 +++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 8a0149672..06dcd43a4 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: mapview Type: Package Title: Interactive Viewing of Spatial Data in R -Version: 2.3.0 -Date: 2018-01-30 +Version: 2.3.2 +Date: 2018-01-31 Authors@R: c( person("Tim", "Appelhans", email = "tim.appelhans@gmail.com", role = c("cre", "aut")), person("Florian", "Detsch", email = "florian.detsch@staff.uni-marburg.de", role = c("aut")), @@ -40,6 +40,7 @@ Imports: webshot, viridisLite, sf, + stars, base64enc, svglite, uuid diff --git a/NEWS b/NEWS index f765bbc70..2432cced9 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,10 @@ +mapview 2.3.2 + +new features: + + * mapview for raster data has gained argument label (logical) to disable image query. https://twitter.com/pierreroudier/status/958476875344392193 + + mapview 2.3.0 new features: diff --git a/NEWS.md b/NEWS.md index 8871be394..edf26296a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,8 @@ -## mapview 2.3.0 +## mapview 2.3.2 + +new features: + + * mapview for raster data has gained argument label (logical) to disable image query. https://twitter.com/pierreroudier/status/958476875344392193 ## mapview 2.3.0 From 309d356dc262a1ff292fbe9e7e7dd37ddd3b51e3 Mon Sep 17 00:00:00 2001 From: tim-salabim Date: Sat, 3 Feb 2018 13:59:55 +0100 Subject: [PATCH 04/94] add argument prefix to image query --- inst/htmlwidgets/lib/joda/joda.js | 10 +++++----- man/addImageQuery.Rd | 5 ++++- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/inst/htmlwidgets/lib/joda/joda.js b/inst/htmlwidgets/lib/joda/joda.js index e19359726..6bf4666ce 100644 --- a/inst/htmlwidgets/lib/joda/joda.js +++ b/inst/htmlwidgets/lib/joda/joda.js @@ -28,7 +28,7 @@ rasterPicker.old = function(e, x, data) { } }; -rasterPicker.pick = function(event, leafletConfig, digits) { +rasterPicker.pick = function(event, leafletConfig, digits, prefix) { var rasterLayers = this.getRasterLayers(leafletConfig); var pickedLayerData = {}; // collect values of clicked raster layers @@ -39,7 +39,7 @@ rasterPicker.pick = function(event, leafletConfig, digits) { } // render collected hit values var outputWidget = this.getInfoLegend(leafletConfig); - outputWidget.innerHTML = this.renderInfo(pickedLayerData, digits); + outputWidget.innerHTML = this.renderInfo(pickedLayerData, digits, prefix); }; rasterPicker.getInfoLegend = function(leafletConfig) { @@ -130,7 +130,7 @@ rasterPicker.getLayerData = function(rasterHitInfo, latlng, zoom) { return layerData; }; -rasterPicker.renderInfo = function(pickedLayerData, digits) { +rasterPicker.renderInfo = function(pickedLayerData, digits, prefix) { var text = ""; for (var layer_key in pickedLayerData) { var layer = pickedLayerData[layer_key]; @@ -138,9 +138,9 @@ rasterPicker.renderInfo = function(pickedLayerData, digits) { continue; } if(digits === null) { - text += "Layer "+ layer.layerId + ": "+ layer.value+ "
"; + text += prefix+ ""+ layer.layerId + ": "+ layer.value+ "
"; } else { - text += "Layer "+ layer.layerId + ": "+ layer.value.toFixed(digits)+ "
"; + text += prefix+ ""+ layer.layerId + ": "+ layer.value.toFixed(digits)+ "
"; } /*text += "
(lat,lng=" + layer.lat + "," + layer.lng + ")"; text += "
(x,y=" + layer.index.x + "," + layer.index.y + ")"; diff --git a/man/addImageQuery.Rd b/man/addImageQuery.Rd index 182b6cbbb..6646dcff0 100644 --- a/man/addImageQuery.Rd +++ b/man/addImageQuery.Rd @@ -5,7 +5,8 @@ \title{Add image query functionality to leaflet/mapview map.} \usage{ addImageQuery(map, x, group = NULL, layerId = NULL, project = TRUE, - type = c("mousemove", "click"), digits, position = "topright", ...) + type = c("mousemove", "click"), digits, position = "topright", + prefix = "Layer", ...) } \arguments{ \item{map}{the map with the RasterLayer to be queried.} @@ -28,6 +29,8 @@ to 'mousemove'.} \item{position}{where to place the display field. Default is 'topright'.} +\item{prefix}{a character string to be shown as prefix for the layerId.} + \item{...}{currently not used.} } \value{ From 34a65bfd23aa86e4a9272da259f03751f488b743 Mon Sep 17 00:00:00 2001 From: tim-salabim Date: Sat, 3 Feb 2018 14:00:29 +0100 Subject: [PATCH 05/94] also prefix for image query --- R/extensions.R | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/R/extensions.R b/R/extensions.R index 7a254abc2..4e84baf86 100644 --- a/R/extensions.R +++ b/R/extensions.R @@ -631,6 +631,7 @@ addGeometry = function(map, #' to 'mousemove'. #' @param digits the number of digits to be shown in the display field. #' @param position where to place the display field. Default is 'topright'. +#' @param prefix a character string to be shown as prefix for the layerId. #' @param ... currently not used. #' #' @return @@ -660,6 +661,7 @@ addImageQuery = function(map, type = c("mousemove", "click"), digits, position = 'topright', + prefix = 'Layer', ...) { if (inherits(map, "mapview")) map = mapview2leaflet(map) @@ -723,7 +725,7 @@ addImageQuery = function(map, 'function(el, x, data) { var map = this; map.on("', type, '", function (e) { - rasterPicker.pick(e, x, ', digits, '); + rasterPicker.pick(e, x, ', digits, ', "', prefix, ' "); }); }' ) From 691b1a003db31f10213f2b21c29ca4f705c2fa4d Mon Sep 17 00:00:00 2001 From: tim-salabim Date: Sat, 3 Feb 2018 14:01:15 +0100 Subject: [PATCH 06/94] add argument method to viewRGB. fixes https://github.com/r-spatial/mapview/issues/125 --- R/projection.R | 8 ++++---- R/viewRGB.R | 13 +++++++++---- man/viewRGB.Rd | 13 +++++++++---- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/R/projection.R b/R/projection.R index 582320664..c357aeb82 100644 --- a/R/projection.R +++ b/R/projection.R @@ -10,12 +10,12 @@ wrong_proj_warning <- " projecting to '", llcrs, "'") # Check and potentially adjust projection of objects to be rendered ======= -checkAdjustProjection <- function(x) { +checkAdjustProjection <- function(x, method) { x <- switch(class(x)[1], - "RasterLayer" = rasterCheckAdjustProjection(x), - "RasterStack" = rasterCheckAdjustProjection(x), - "RasterBrick" = rasterCheckAdjustProjection(x), + "RasterLayer" = rasterCheckAdjustProjection(x, method), + "RasterStack" = rasterCheckAdjustProjection(x, method), + "RasterBrick" = rasterCheckAdjustProjection(x, method), "SpatialPointsDataFrame" = spCheckAdjustProjection(x), "SpatialPolygonsDataFrame" = spCheckAdjustProjection(x), "SpatialLinesDataFrame" = spCheckAdjustProjection(x), diff --git a/R/viewRGB.R b/R/viewRGB.R index 7ff4cac3c..dcd459455 100644 --- a/R/viewRGB.R +++ b/R/viewRGB.R @@ -27,19 +27,22 @@ if ( !isGeneric('viewRGB') ) { #' for available options. #' @param na.color the color to be used for NA pixels #' @param layer.name the name of the layer to be shown on the map +#' @param method Method used to compute +#' values for the resampled layer that is passed on to leaflet. mapview does +#' projection on-the-fly to ensure correct display and therefore needs to know +#' how to do this projection. The default is 'bilinear' (bilinear interpolation), +#' which is appropriate for continuous variables. The other option, 'ngb' +#' (nearest neighbor), is useful for categorical variables. #' @param ... additional arguments passed on to \code{\link{mapView}} #' #' @author #' Tim Appelhans #' #' @examples -#' \dontrun{ #' library(raster) #' #' viewRGB(poppendorf, 4, 3, 2) # true-color #' viewRGB(poppendorf, 5, 4, 3) # false-color -#' } -#' #' #' @export #' @docType methods @@ -56,11 +59,13 @@ setMethod("viewRGB", signature(x = "RasterStackBrick"), na.color = mapviewGetOption("na.color"), layer.name = deparse(substitute(x, env = parent.frame())), + method = c("bilinear", "ngb"), ...) { + method = match.arg(method) m <- initMap(map, map.types, projection(x)) x <- rasterCheckSize(x, maxpixels) - xout <- rasterCheckAdjustProjection(x) + xout <- rasterCheckAdjustProjection(x, method) mat <- cbind(xout[[r]][], xout[[g]][], diff --git a/man/viewRGB.Rd b/man/viewRGB.Rd index 4736ba27f..6b2203bf4 100644 --- a/man/viewRGB.Rd +++ b/man/viewRGB.Rd @@ -11,7 +11,8 @@ maxpixels = mapviewGetOption("mapview.maxpixels"), map.types = mapviewGetOption("basemaps"), na.color = mapviewGetOption("na.color"), - layer.name = deparse(substitute(x, env = parent.frame())), ...) + layer.name = deparse(substitute(x, env = parent.frame())), + method = c("bilinear", "ngb"), ...) } \arguments{ \item{x}{a RasterBrick or RasterStack} @@ -37,6 +38,13 @@ for available options.} \item{layer.name}{the name of the layer to be shown on the map} +\item{method}{Method used to compute +values for the resampled layer that is passed on to leaflet. mapview does +projection on-the-fly to ensure correct display and therefore needs to know +how to do this projection. The default is 'bilinear' (bilinear interpolation), +which is appropriate for continuous variables. The other option, 'ngb' +(nearest neighbor), is useful for categorical variables.} + \item{...}{additional arguments passed on to \code{\link{mapView}}} } \description{ @@ -49,13 +57,10 @@ multi-band satellite images. Note, this text is plagirized, i.e. copied from \code{\link{plotRGB}}. } \examples{ -\dontrun{ library(raster) viewRGB(poppendorf, 4, 3, 2) # true-color viewRGB(poppendorf, 5, 4, 3) # false-color -} - } \author{ From 60d570bc5fdd47cb77e4da3506c09b7e2f1de2b3 Mon Sep 17 00:00:00 2001 From: tim-salabim Date: Sat, 3 Feb 2018 14:01:45 +0100 Subject: [PATCH 07/94] add arguments to modify image query --- R/mapView.R | 57 ++++++++++++++++++++++++++++++--------- R/raster.R | 24 ++++++++++++++++- R/stars.R | 64 +++++++++++++++++++++++++------------------- man/mapView.Rd | 58 +++++++++++++++++++++++++++++---------- man/mapview-class.Rd | 19 +------------ 5 files changed, 148 insertions(+), 74 deletions(-) diff --git a/R/mapView.R b/R/mapView.R index 5c89628e5..433bb93e0 100644 --- a/R/mapView.R +++ b/R/mapView.R @@ -82,6 +82,15 @@ if ( !isGeneric('mapView') ) { #' @param maxpoints the maximum number of points making up the geometry. #' In case of lines and polygons this refers to the number of vertices. See #' Details for more information. +#' @param query.type for raster methods only. Whether to show raster value query +#' on \code{'mousemove'} or \code{'click'}. Ignored if \code{label = FALSE}. +#' @param query.digits for raster methods only. The amount of digits to be shown +#' by raster value query. Ignored if \code{label = FALSE}. +#' @param query.position for raster methods only. The position of the raster +#' value query info box. See \code{position} argument of \code{\link{addLegend}} +#' for possible values. Ignored if \code{label = FALSE}. +#' @param query.prefix for raster methods only. a character string to be shown +#' as prefix for the layerId. Ignored if \code{label = FALSE}. #' @param ... additional arguments passed on to repective functions. #' See \code{\link{addRasterImage}}, \code{\link{addCircles}}, #' \code{\link{addPolygons}}, \code{\link{addPolylines}} for details @@ -106,10 +115,11 @@ if ( !isGeneric('mapView') ) { #' Tim Appelhans #' #' @examples -#' \dontrun{ #' mapview() #' #' ## simple features ==================================================== +#' library(sf) +#' #' # sf #' mapview(breweries) #' mapview(franconia) @@ -130,25 +140,24 @@ if ( !isGeneric('mapView') ) { #' #' ## spatial objects ===================================================== #' mapview(leaflet::gadmCHE) -#' mapview(atlStorms2005) +#' mapview(leaflet::atlStorms2005) #' #' #' ## styling options & legends =========================================== -#' mapview(cantons, color = "white", col.regions = "red") -#' mapview(cantons, color = "magenta", col.regions = "white") +#' mapview(franconia, color = "white", col.regions = "red") +#' mapview(franconia, color = "magenta", col.regions = "white") #' #' mapview(breweries, zcol = "founded") #' mapview(breweries, zcol = "founded", at = seq(1400, 2200, 200), legend = TRUE) -#' mapview(cantons, zcol = "NAME_1", legend = TRUE) +#' mapview(franconia, zcol = "district", legend = TRUE) #' -#' library(RColorBrewer) -#' clrs <- colorRampPalette(brewer.pal(9, "Blues")) -#' mapview(breweries, zcol = "founded", col.regions = clrs, legend = TRUE) +#' clrs <- sf.colors +#' mapview(franconia, zcol = "district", col.regions = clrs, legend = TRUE) #' #' ### multiple layers ==================================================== #' mapview(franconia) + breweries #' mapview(list(breweries, franconia)) -#' mapview(breweries) + mapview(franconia) + stormtracks +#' mapview(franconia) + mapview(breweries) + trails #' #' mapview(franconia, zcol = "district") + mapview(breweries, zcol = "village") #' mapview(list(franconia, breweries), @@ -198,8 +207,6 @@ if ( !isGeneric('mapView') ) { #' density = count / st_area(.)) %>% #' mapview(zcol = "density") #' -#' } -#' #' @export #' @docType methods #' @name mapView @@ -230,6 +237,10 @@ setMethod('mapView', signature(x = 'RasterLayer'), native.crs = FALSE, method = c("bilinear", "ngb"), label = TRUE, + query.type = c("mousemove", "click"), + query.digits, + query.position = "topright", + query.prefix = "Layer", ...) { method = match.arg(method) @@ -253,7 +264,7 @@ setMethod('mapView', signature(x = 'RasterLayer'), maxpixels = maxpixels, col.regions = col.regions, at = at, - na.color, na.color, + na.color = na.color, use.layer.names = use.layer.names, values = values, map.types = map.types, @@ -267,6 +278,10 @@ setMethod('mapView', signature(x = 'RasterLayer'), native.crs = native.crs, method = method, label = label, + query.type = query.type, + query.digits = query.digits, + query.position = query.position, + query.prefix = query.prefix, ...) } else { NULL @@ -278,7 +293,7 @@ setMethod('mapView', signature(x = 'RasterLayer'), ## Stars layer ================================================================== -#' @describeIn mapview \code{stars} +#' @describeIn mapView \code{\link{stars}} setMethod('mapView', signature(x = 'stars'), function(x, map = NULL, @@ -298,6 +313,11 @@ setMethod('mapView', signature(x = 'stars'), homebutton = TRUE, native.crs = FALSE, method = c("bilinear", "ngb"), + label = TRUE, + query.type = c("mousemove", "click"), + query.digits, + query.position = "topright", + query.prefix = "Layer", ...) { method = match.arg(method) @@ -326,6 +346,11 @@ setMethod('mapView', signature(x = 'stars'), homebutton = homebutton, native.crs = native.crs, method = method, + label = label, + query.type = query.type, + query.digits = query.digits, + query.position = query.position, + query.prefix = query.prefix, ...) } else { NULL @@ -356,6 +381,10 @@ setMethod('mapView', signature(x = 'RasterStackBrick'), homebutton = TRUE, method = c("bilinear", "ngb"), label = TRUE, + query.type = c("mousemove", "click"), + query.digits, + query.position = "topright", + query.prefix = "Layer", ...) { if (mapviewGetOption("platform") == "leaflet") { @@ -403,6 +432,7 @@ setMethod('mapView', signature(x = 'Satellite'), verbose = mapviewGetOption("verbose"), homebutton = TRUE, method = c("bilinear", "ngb"), + label = TRUE, ...) { if (mapviewGetOption("platform") == "leaflet") { @@ -420,6 +450,7 @@ setMethod('mapView', signature(x = 'Satellite'), verbose = verbose, homebutton = homebutton, method = method, + label = label, ...) } else { NULL diff --git a/R/raster.R b/R/raster.R index 831862442..256cad430 100644 --- a/R/raster.R +++ b/R/raster.R @@ -24,6 +24,10 @@ leafletRL = function(x, native.crs, method, label, + query.type, + query.digits, + query.position, + query.prefix, ...) { if (inherits(map, "mapview")) map = mapview2leaflet(map) @@ -112,7 +116,9 @@ leafletRL = function(x, layerId = grp, ...) if (label) - m = addImageQuery(m, x, group = grp, layerId = grp, position = "topright") + m = addImageQuery(m, x, group = grp, layerId = grp, + type = query.type, digits = query.digits, + position = query.position, prefix = query.prefix) if (legend) { ## add legend # m = leaflet::addLegend(map = m, @@ -170,6 +176,10 @@ leafletRSB = function(x, homebutton, method, label, + query.type, + query.digits, + query.position, + query.prefix, ...) { pkgs = c("leaflet", "raster", "magrittr") @@ -194,6 +204,10 @@ leafletRSB = function(x, homebutton = homebutton, method = method, label = label, + query.type = query.type, + query.digits = query.digits, + query.position = query.position, + query.prefix = query.prefix, ...) out = new('mapview', object = list(x), map = m@map) } else { @@ -209,6 +223,10 @@ leafletRSB = function(x, homebutton = homebutton, method = method, label = label, + query.type = query.type, + query.digits = query.digits, + query.position = query.position, + query.prefix = query.prefix, ...) for (i in 2:nlayers(x)) { m = mapView(x[[i]], @@ -223,6 +241,10 @@ leafletRSB = function(x, homebutton = FALSE, method = method, label = label, + query.type = query.type, + query.digits = query.digits, + query.position = query.position, + query.prefix = query.prefix, ...) } diff --git a/R/stars.R b/R/stars.R index 8b6a5a92a..8ea26e8c2 100644 --- a/R/stars.R +++ b/R/stars.R @@ -115,6 +115,11 @@ leaflet_stars = function(x, homebutton, native.crs, method, + label, + query.type, + query.digits, + query.position, + query.prefix, ...) { if (inherits(map, "mapview")) map = mapview2leaflet(map) @@ -151,11 +156,11 @@ leaflet_stars = function(x, # if (is.fact) { # at = x@data@attributes[[1]]$ID # } else { - offset = diff(range(as.numeric(x[[1]][, , 1]), na.rm = TRUE)) * 0.05 - top = max(as.numeric(x[[1]][, , 1]), na.rm = TRUE) + offset - bot = min(as.numeric(x[[1]][, , 1]), na.rm = TRUE) - offset - values = seq(bot, top, length.out = 10) - values = round(values, 5) + offset = diff(range(as.numeric(x[[1]][, , 1]), na.rm = TRUE)) * 0.05 + top = max(as.numeric(x[[1]][, , 1]), na.rm = TRUE) + offset + bot = min(as.numeric(x[[1]][, , 1]), na.rm = TRUE) - offset + values = seq(bot, top, length.out = 10) + values = round(values, 5) # } } else { values = round(values, 5) @@ -167,20 +172,20 @@ leaflet_stars = function(x, # na.color = na.color) # # pal2 = pal # } else { - pal = rasterColors(col.regions, - at = at, - na.color = na.color) - - # if (length(at) > 11) { - # pal2 = leaflet::colorNumeric(palette = col.regions, - # domain = at, - # na.color = na.color) - # } else { - # pal2 = leaflet::colorBin(palette = col.regions, - # bins = length(at), - # domain = at, - # na.color = na.color) - # } + pal = rasterColors(col.regions, + at = at, + na.color = na.color) + + # if (length(at) > 11) { + # pal2 = leaflet::colorNumeric(palette = col.regions, + # domain = at, + # na.color = na.color) + # } else { + # pal2 = leaflet::colorBin(palette = col.regions, + # bins = length(at), + # domain = at, + # na.color = na.color) + # } # } @@ -192,15 +197,18 @@ leaflet_stars = function(x, } ## add layers to base map - m = addStarsImage(map = m, - x = x, - colors = pal, - project = FALSE, - opacity = alpha.regions, - group = grp, - layerId = grp, - ...) - m = addImageQuery(m, x, group = grp, layerId = grp, position = "topright") + m = addStarsImage(map = m, + x = x, + colors = pal, + project = FALSE, + opacity = alpha.regions, + group = grp, + layerId = grp, + ...) + if (label) + m = addImageQuery(m, x, group = grp, layerId = grp, + type = query.type, digits = query.digits, + position = query.position, prefix = query.prefix) if (legend) { stop("legend currently not supported for stars layers", call. = FALSE) ## add legend diff --git a/man/mapView.Rd b/man/mapView.Rd index c0e249945..c322ddedb 100644 --- a/man/mapView.Rd +++ b/man/mapView.Rd @@ -4,6 +4,7 @@ \name{mapView} \alias{mapView} \alias{mapView,RasterLayer-method} +\alias{mapView,stars-method} \alias{mapView,RasterStackBrick-method} \alias{mapView,Satellite-method} \alias{mapView,sf-method} @@ -44,7 +45,21 @@ alpha.regions = 0.8, legend = mapviewGetOption("legend"), legend.opacity = 1, trim = TRUE, verbose = mapviewGetOption("verbose"), layer.name = NULL, homebutton = TRUE, native.crs = FALSE, - method = c("bilinear", "ngb"), label = TRUE, ...) + method = c("bilinear", "ngb"), label = TRUE, query.type = c("mousemove", + "click"), query.digits, query.position = "topright", + query.prefix = "Layer", ...) + +\S4method{mapView}{stars}(x, map = NULL, + maxpixels = mapviewGetOption("mapview.maxpixels"), + col.regions = mapviewGetOption("raster.palette")(256), at = NULL, + na.color = mapviewGetOption("na.color"), use.layer.names = FALSE, + values = NULL, map.types = mapviewGetOption("basemaps"), + alpha.regions = 0.8, legend = mapviewGetOption("legend"), + legend.opacity = 1, trim = TRUE, verbose = mapviewGetOption("verbose"), + layer.name = NULL, homebutton = TRUE, native.crs = FALSE, + method = c("bilinear", "ngb"), label = TRUE, query.type = c("mousemove", + "click"), query.digits, query.position = "topright", + query.prefix = "Layer", ...) \S4method{mapView}{RasterStackBrick}(x, map = NULL, maxpixels = mapviewGetOption("mapview.maxpixels"), @@ -53,7 +68,9 @@ values = NULL, map.types = mapviewGetOption("basemaps"), legend = mapviewGetOption("legend"), legend.opacity = 1, trim = TRUE, verbose = mapviewGetOption("verbose"), homebutton = TRUE, - method = c("bilinear", "ngb"), label = TRUE, ...) + method = c("bilinear", "ngb"), label = TRUE, query.type = c("mousemove", + "click"), query.digits, query.position = "topright", + query.prefix = "Layer", ...) \S4method{mapView}{Satellite}(x, map = NULL, maxpixels = mapviewGetOption("mapview.maxpixels"), @@ -62,7 +79,7 @@ map.types = mapviewGetOption("basemaps"), legend = mapviewGetOption("legend"), legend.opacity = 1, trim = TRUE, verbose = mapviewGetOption("verbose"), homebutton = TRUE, - method = c("bilinear", "ngb"), ...) + method = c("bilinear", "ngb"), label = TRUE, ...) \S4method{mapView}{sf}(x, map = NULL, zcol = NULL, burst = FALSE, color = mapviewGetOption("vector.palette"), @@ -244,6 +261,19 @@ layer is of class \code{factor} in which case "ngb" is used.} shown on mouseover. See \code{\link{addControl}} for details. For raster data (Raster*/stars) a logical indicating whether to add image query.} +\item{query.type}{for raster methods only. Whether to show raster value query +on \code{'mousemove'} or \code{'click'}. Ignored if \code{label = FALSE}.} + +\item{query.digits}{for raster methods only. The amount of digits to be shown +by raster value query. Ignored if \code{label = FALSE}.} + +\item{query.position}{for raster methods only. The position of the raster +value query info box. See \code{position} argument of \code{\link{addLegend}} +for possible values. Ignored if \code{label = FALSE}.} + +\item{query.prefix}{for raster methods only. a character string to be shown +as prefix for the layerId. Ignored if \code{label = FALSE}.} + \item{...}{additional arguments passed on to repective functions. See \code{\link{addRasterImage}}, \code{\link{addCircles}}, \code{\link{addPolygons}}, \code{\link{addPolylines}} for details} @@ -335,6 +365,8 @@ and fully queriable. } \section{Methods (by class)}{ \itemize{ +\item \code{stars}: \code{\link{stars}} + \item \code{RasterStackBrick}: \code{\link{stack}} / \code{\link{brick}} \item \code{Satellite}: \code{\link{satellite}} @@ -395,10 +427,11 @@ and fully queriable. }} \examples{ -\dontrun{ mapview() ## simple features ==================================================== +library(sf) + # sf mapview(breweries) mapview(franconia) @@ -419,25 +452,24 @@ mapview(poppendorf[[5]]) ## spatial objects ===================================================== mapview(leaflet::gadmCHE) -mapview(atlStorms2005) +mapview(leaflet::atlStorms2005) ## styling options & legends =========================================== -mapview(cantons, color = "white", col.regions = "red") -mapview(cantons, color = "magenta", col.regions = "white") +mapview(franconia, color = "white", col.regions = "red") +mapview(franconia, color = "magenta", col.regions = "white") mapview(breweries, zcol = "founded") mapview(breweries, zcol = "founded", at = seq(1400, 2200, 200), legend = TRUE) -mapview(cantons, zcol = "NAME_1", legend = TRUE) +mapview(franconia, zcol = "district", legend = TRUE) -library(RColorBrewer) -clrs <- colorRampPalette(brewer.pal(9, "Blues")) -mapview(breweries, zcol = "founded", col.regions = clrs, legend = TRUE) +clrs <- sf.colors +mapview(franconia, zcol = "district", col.regions = clrs, legend = TRUE) ### multiple layers ==================================================== mapview(franconia) + breweries mapview(list(breweries, franconia)) -mapview(breweries) + mapview(franconia) + stormtracks +mapview(franconia) + mapview(breweries) + trails mapview(franconia, zcol = "district") + mapview(breweries, zcol = "village") mapview(list(franconia, breweries), @@ -487,8 +519,6 @@ franconia \%>\% density = count / st_area(.)) \%>\% mapview(zcol = "density") -} - } \author{ Tim Appelhans diff --git a/man/mapview-class.Rd b/man/mapview-class.Rd index 1f1bb9436..34069dbc6 100644 --- a/man/mapview-class.Rd +++ b/man/mapview-class.Rd @@ -1,29 +1,12 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/AAAmapviewClasses.R, R/mapView.R +% Please edit documentation in R/AAAmapviewClasses.R \docType{class} \name{mapview-class} \alias{mapview-class} -\alias{mapView,stars-method} \title{Class mapview} -\usage{ -\S4method{mapView}{stars}(x, map = NULL, - maxpixels = mapviewGetOption("mapview.maxpixels"), - col.regions = mapviewGetOption("raster.palette")(256), at = NULL, - na.color = mapviewGetOption("na.color"), use.layer.names = FALSE, - values = NULL, map.types = mapviewGetOption("basemaps"), - alpha.regions = 0.8, legend = mapviewGetOption("legend"), - legend.opacity = 1, trim = TRUE, verbose = mapviewGetOption("verbose"), - layer.name = NULL, homebutton = TRUE, native.crs = FALSE, - method = c("bilinear", "ngb"), ...) -} \description{ Class mapview } -\section{Methods (by generic)}{ -\itemize{ -\item \code{mapView}: \code{stars} -}} - \section{Slots}{ \describe{ From a43031a45b427ac4e9cb7059c0a168495b28280d Mon Sep 17 00:00:00 2001 From: tim-salabim Date: Sat, 3 Feb 2018 14:01:58 +0100 Subject: [PATCH 08/94] update news and bump version --- DESCRIPTION | 4 ++-- NEWS | 2 +- NEWS.md | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 06dcd43a4..8e8160d33 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: mapview Type: Package Title: Interactive Viewing of Spatial Data in R -Version: 2.3.2 -Date: 2018-01-31 +Version: 2.3.3 +Date: 2018-02-03 Authors@R: c( person("Tim", "Appelhans", email = "tim.appelhans@gmail.com", role = c("cre", "aut")), person("Florian", "Detsch", email = "florian.detsch@staff.uni-marburg.de", role = c("aut")), diff --git a/NEWS b/NEWS index 2432cced9..e37b9fa34 100644 --- a/NEWS +++ b/NEWS @@ -1,4 +1,4 @@ -mapview 2.3.2 +mapview 2.3.3 new features: diff --git a/NEWS.md b/NEWS.md index edf26296a..afe79b75e 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -## mapview 2.3.2 +## mapview 2.3.3 new features: From 9bc0782d1bfb05279bbcd9599d292d98ae343c5a Mon Sep 17 00:00:00 2001 From: tim-salabim Date: Sat, 3 Feb 2018 14:11:53 +0100 Subject: [PATCH 09/94] add more news --- NEWS.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index afe79b75e..e1cf0ba97 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,7 +2,12 @@ new features: - * mapview for raster data has gained argument label (logical) to disable image query. https://twitter.com/pierreroudier/status/958476875344392193 + * addImageQuery has gained argument prefix to modify the layerId prefix. + * mapview methods for raster data have gained arguments label, query.type, query.digits, query.position and query.prefix to modify raster value query settings. https://twitter.com/pierreroudier/status/958476875344392193 + +bugfixes: + + * viewRGB failed because of missing method argument. #125 ## mapview 2.3.0 From e30c74fe31b2ad9e2b18c1c0636b520f3451eb6b Mon Sep 17 00:00:00 2001 From: tim-salabim Date: Sat, 3 Feb 2018 14:21:33 +0100 Subject: [PATCH 10/94] add new raster value query arguments to spgrid and pixels methods also --- R/mapView.R | 24 ++++++++++++++++++++++++ R/raster.R | 10 ++++++++++ man/mapView.Rd | 8 ++++++-- 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/R/mapView.R b/R/mapView.R index 433bb93e0..a06ace455 100644 --- a/R/mapView.R +++ b/R/mapView.R @@ -404,6 +404,10 @@ setMethod('mapView', signature(x = 'RasterStackBrick'), homebutton = homebutton, method = method, label = label, + query.type = query.type, + query.digits = query.digits, + query.position = query.position, + query.prefix = query.prefix, ...) } else { NULL @@ -1070,6 +1074,11 @@ setMethod('mapView', signature(x = 'SpatialPixelsDataFrame'), homebutton = TRUE, native.crs = FALSE, method = c("bilinear", "ngb"), + label = TRUE, + query.type = c("mousemove", "click"), + query.digits, + query.position = "topright", + query.prefix = "Layer", ...) { if (mapviewGetOption("platform") == "leaflet") { @@ -1092,6 +1101,11 @@ setMethod('mapView', signature(x = 'SpatialPixelsDataFrame'), homebutton = homebutton, native.crs = native.crs, method = method, + label = label, + query.type = query.type, + query.digits = query.digits, + query.position = query.position, + query.prefix = query.prefix, ...) } else { NULL @@ -1124,6 +1138,11 @@ setMethod('mapView', signature(x = 'SpatialGridDataFrame'), homebutton = TRUE, native.crs = FALSE, method = c("bilinear", "ngb"), + label = TRUE, + query.type = c("mousemove", "click"), + query.digits, + query.position = "topright", + query.prefix = "Layer", ...) { if (mapviewGetOption("platform") == "leaflet") { @@ -1146,6 +1165,11 @@ setMethod('mapView', signature(x = 'SpatialGridDataFrame'), homebutton = homebutton, native.crs = native.crs, method = method, + label = label, + query.type = query.type, + query.digits = query.digits, + query.position = query.position, + query.prefix = query.prefix, ...) } else { NULL diff --git a/R/raster.R b/R/raster.R index 256cad430..5193089ee 100644 --- a/R/raster.R +++ b/R/raster.R @@ -282,6 +282,11 @@ leafletPixelsDF = function(x, homebutton, native.crs, method, + label, + query.type, + query.digits, + query.position, + query.prefix, ...) { pkgs = c("leaflet", "sp", "magrittr") @@ -316,6 +321,11 @@ leafletPixelsDF = function(x, homebutton = homebutton, native.crs = native.crs, method = method, + label = label, + query.type = query.type, + query.digits = query.digits, + query.position = query.position, + query.prefix = query.prefix, ...) out = new('mapview', object = list(x), map = m@map) diff --git a/man/mapView.Rd b/man/mapView.Rd index c322ddedb..602c986a1 100644 --- a/man/mapView.Rd +++ b/man/mapView.Rd @@ -173,7 +173,9 @@ alpha.regions = 0.8, legend = mapviewGetOption("legend"), legend.opacity = 1, trim = TRUE, verbose = mapviewGetOption("verbose"), layer.name = NULL, homebutton = TRUE, native.crs = FALSE, - method = c("bilinear", "ngb"), ...) + method = c("bilinear", "ngb"), label = TRUE, query.type = c("mousemove", + "click"), query.digits, query.position = "topright", + query.prefix = "Layer", ...) \S4method{mapView}{SpatialGridDataFrame}(x, map = NULL, zcol = NULL, maxpixels = mapviewGetOption("mapview.maxpixels"), @@ -183,7 +185,9 @@ alpha.regions = 0.8, legend = mapviewGetOption("legend"), legend.opacity = 1, trim = TRUE, verbose = mapviewGetOption("verbose"), layer.name = NULL, homebutton = TRUE, native.crs = FALSE, - method = c("bilinear", "ngb"), ...) + method = c("bilinear", "ngb"), label = TRUE, query.type = c("mousemove", + "click"), query.digits, query.position = "topright", + query.prefix = "Layer", ...) \S4method{mapView}{SpatialPointsDataFrame}(x, zcol = NULL, layer.name = NULL, ...) From 9253a72c9c70ca4f3eb87cc8e58235a2f4535bb4 Mon Sep 17 00:00:00 2001 From: tim-salabim Date: Sun, 4 Feb 2018 14:08:31 +0100 Subject: [PATCH 11/94] update and un-dontrun most examples --- R/coords2Lines.R | 2 -- R/coords2Polygons.R | 2 -- R/cubeView.R | 5 +-- R/extensions.R | 50 ++++++++++++++++------------ R/extent.R | 4 +-- R/garnishMap.R | 12 +++---- R/mapviewOptions.R | 12 ++----- R/plainView.R | 5 +-- R/plus.R | 15 +++------ R/popup.R | 19 +---------- R/projection.R | 2 +- R/raster.R | 67 ++++++++++++++++++++++++++++++++++++++ R/raster2PNG.R | 63 ----------------------------------- R/sync.R | 5 +-- man/addFeatures.Rd | 16 ++++----- man/addHomeButton.Rd | 9 ++--- man/addLogo.Rd | 5 +-- man/addMouseCoordinates.Rd | 14 +++++--- man/coords2Lines.Rd | 2 -- man/coords2Polygons.Rd | 2 -- man/cubeView.Rd | 5 +-- man/garnishMap.Rd | 12 +++---- man/latticeView.Rd | 5 +-- man/mapviewOptions.Rd | 5 +-- man/plainView.Rd | 5 +-- man/plus.Rd | 15 +++------ man/popup.Rd | 19 +---------- man/viewExtent.Rd | 4 +-- 28 files changed, 160 insertions(+), 221 deletions(-) delete mode 100644 R/raster2PNG.R diff --git a/R/coords2Lines.R b/R/coords2Lines.R index 8b04fbefe..d2b6591b7 100644 --- a/R/coords2Lines.R +++ b/R/coords2Lines.R @@ -25,7 +25,6 @@ if ( !isGeneric("coords2Lines") ) { #' \code{\link{SpatialLines-class}}, \code{\link{SpatialLinesDataFrame}}. #' #' @examples -#' \dontrun{ #' library(sp) #' #' coords1 <- cbind(c(2, 4, 4, 1, 2), c(2, 3, 5, 4, 2)) @@ -38,7 +37,6 @@ if ( !isGeneric("coords2Lines") ) { #' #' plot(sln1, col = "grey75") #' plot(sln2, col = "grey25", add = TRUE) -#' } #' #' @export coords2Lines #' @name coords2Lines diff --git a/R/coords2Polygons.R b/R/coords2Polygons.R index 1104a60d5..a11b23995 100644 --- a/R/coords2Polygons.R +++ b/R/coords2Polygons.R @@ -26,7 +26,6 @@ if ( !isGeneric("coords2Polygons") ) { #' \code{\link{SpatialPolygons-class}}, \code{\link{SpatialPolygonsDataFrame}}. #' #' @examples -#' \dontrun{ #' library(sp) #' #' coords1 <- cbind(c(2, 4, 4, 1, 2), c(2, 3, 5, 4, 2)) @@ -37,7 +36,6 @@ if ( !isGeneric("coords2Polygons") ) { #' #' plot(spy1, col = "grey75") #' plot(spy2, col = "grey25", add = TRUE) -#' } #' #' @export coords2Polygons #' @name coords2Polygons diff --git a/R/cubeView.R b/R/cubeView.R index d2e29159c..bf53a04d1 100644 --- a/R/cubeView.R +++ b/R/cubeView.R @@ -34,7 +34,6 @@ #' Stephan Woellauer and Tim Appelhans #' #' @examples -#' \dontrun{ #' library(raster) #' #' kili_data <- system.file("extdata", "kiliNDVI.tif", package = "mapview") @@ -42,10 +41,8 @@ #' #' cubeView(kiliNDVI) #' -#' library(RColorBrewer) -#' clr <- colorRampPalette(brewer.pal(9, "BrBG")) +#' clr <- viridisLite::viridis #' cubeView(kiliNDVI, at = seq(-0.15, 0.95, 0.1), col.regions = clr) -#' } #' #' @export cubeView #' @name cubeView diff --git a/R/extensions.R b/R/extensions.R index 4e84baf86..62855cdbc 100644 --- a/R/extensions.R +++ b/R/extensions.R @@ -31,11 +31,15 @@ #' If style is set to "basic", only 'lat', 'lon' and 'zoom' are shown. #' #' @examples -#' \dontrun{ -#' leaflet() %>% addTiles() # without mouse position info -#' leaflet() %>% addTiles() %>% addMouseCoordinates(style = "basic") # with basic mouse position info -#' mapview(easter.egg = TRUE) # detailed mouse position info by default ;-) -#' } +#' library(leaflet) +#' +#' leaflet() %>% addProviderTiles("OpenStreetMap") # without mouse position info +#' leaflet() %>% +#' addProviderTiles("OpenStreetMap") %>% +#' addMouseCoordinates(style = "basic") # with basic mouse position info +#' leaflet() %>% +#' addProviderTiles("OpenStreetMap") %>% +#' addMouseCoordinates() # with detailed mouse position info #' #' #' @export addMouseCoordinates @@ -155,16 +159,17 @@ addMouseCoordinates <- function(map, style = c("detailed", "basic"), #' @param add logical. Whether to add the button to the map (mainly for internal use). #' #' @examples -#' \dontrun{ +#' library(leaflet) #' library(raster) #' -#' m <- leaflet() %>% addTiles() %>% addCircleMarkers(data = breweries91) %>% -#' addHomeButton(extent(breweries91), "breweries91") +#' m <- leaflet() %>% +#' addProviderTiles("OpenStreetMap") %>% +#' addCircleMarkers(data = breweries) %>% +#' addHomeButton(extent(breweries), "breweries") #' m #' #' ## remove the button #' removeHomeButton(m) -#' } #' #' #' @export addHomeButton @@ -176,6 +181,12 @@ addHomeButton <- function(map, ext, layer.name = "layer", if (inherits(map, "mapview")) map <- mapview2leaflet(map) stopifnot(inherits(map, "leaflet")) + # drop names in case extent of sf object + ext@xmin = unname(ext@xmin) + ext@xmax = unname(ext@xmax) + ext@ymin = unname(ext@ymin) + ext@ymax = unname(ext@ymax) + hb <- try(getCallEntryFromMap(map, "addHomeButton"), silent = TRUE) if (!inherits(hb, "try-error") & length(hb) == 1) { ext_coords <- unlist(map$x$calls[[hb]][["args"]][1:4]) @@ -264,7 +275,7 @@ leafletHomeButtonDependencies <- function() { #' @param height height of the rendered image in pixels. #' #' @examples -#' \dontrun{ +#' library(leaflet) #' ## default position is topleft next to zoom control #' #' img <- "https://www.r-project.org/logo/Rlogo.svg" @@ -277,7 +288,6 @@ leafletHomeButtonDependencies <- function() { #' leaflet() %>% addTiles() %>% addLogo(img, src = "local", alpha = 0.3) #' #' ## dancing banana gif :-) -#' library(magick) #' m <- mapview(breweries91) #' #' addLogo(m, "https://jeroenooms.github.io/images/banana.gif", @@ -287,8 +297,6 @@ leafletHomeButtonDependencies <- function() { #' width = 100, #' height = 100) #' -#' } -#' #' #' @export addLogo #' @name addLogo @@ -495,16 +503,16 @@ remoteImage <- function(img, alpha, url, width, height) { #' A leaflet \code{map} object. #' #' @examples -#' \dontrun{ -#' leaflet() %>% addTiles() %>% addCircleMarkers(data = breweries) -#' leaflet() %>% addTiles() %>% addFeatures(data = breweries) +#' library(leaflet) #' -#' leaflet() %>% addTiles() %>% addPolylines(data = atlStorms2005) -#' leaflet() %>% addTiles() %>% addFeatures(atlStorms2005) +#' leaflet() %>% addProviderTiles("OpenStreetMap") %>% addCircleMarkers(data = breweries) +#' leaflet() %>% addProviderTiles("OpenStreetMap") %>% addFeatures(data = breweries) #' -#' leaflet() %>% addTiles() %>% addPolygons(data = franconia) -#' leaflet() %>% addTiles() %>% addFeatures(franconia) -#' } +#' leaflet() %>% addProviderTiles("OpenStreetMap") %>% addPolylines(data = atlStorms2005) +#' leaflet() %>% addProviderTiles("OpenStreetMap") %>% addFeatures(atlStorms2005) +#' +#' leaflet() %>% addProviderTiles("OpenStreetMap") %>% addPolygons(data = franconia) +#' leaflet() %>% addProviderTiles("OpenStreetMap") %>% addFeatures(franconia) #' #' @export addFeatures #' @name addFeatures diff --git a/R/extent.R b/R/extent.R index 9e115f35e..70362a146 100644 --- a/R/extent.R +++ b/R/extent.R @@ -21,13 +21,13 @@ #' Tim Appelhans #' #' @examples -#' \dontrun{ +#' library(leaflet) +#' #' viewExtent(poppendorf) #' viewExtent(breweries) #' viewExtent(franconia) + breweries #' viewExtent(trails) + trails + breweries #' leaflet() %>% addProviderTiles("OpenStreetMap") %>% addExtent(breweries) -#' } #' #' @export viewExtent #' @name viewExtent diff --git a/R/garnishMap.R b/R/garnishMap.R index d28061399..f9ece1cc0 100644 --- a/R/garnishMap.R +++ b/R/garnishMap.R @@ -11,14 +11,16 @@ #' @param ... functions and their arguments to add things to a map. #' #' @examples -#' \dontrun{ -#' m <- leaflet() %>% addTiles() -#' garnishMap(m, addMouseCoordinates) +#' library(leaflet) +#' +#' m <- leaflet() %>% addProviderTiles("OpenStreetMap") +#' garnishMap(m, addMouseCoordinates, style = "basic") #' #' ## add more than one with named argument #' library(raster) +#' #' m1 <- garnishMap(m, addMouseCoordinates, addHomeButton, -#' ext = extent(breweries91)) +#' ext = extent(breweries)) #' m1 #' #' ## even more flexible @@ -26,8 +28,6 @@ #' fillOpacity = 0.8, color = "black", fillColor = "#BEBEBE") #' garnishMap(m2, addCircleMarkers, data = breweries) #' -#' } -#' #' @export garnishMap #' @name garnishMap #' @rdname garnishMap diff --git a/R/mapviewOptions.R b/R/mapviewOptions.R index 8abafb81b..d04e65b97 100644 --- a/R/mapviewOptions.R +++ b/R/mapviewOptions.R @@ -65,26 +65,20 @@ #' \code{\link{rasterOptions}}, \code{\link{options}} #' #' @examples -#' \dontrun{ #' mapviewOptions() #' mapviewOptions(na.color = "pink") #' mapviewOptions() #' #' mapviewGetOption("platform") -#' } +#' +#' mapviewOptions(default = TRUE) +#' mapviewOptions() #' #' #' @export mapviewOptions #' @name mapviewOptions #' @rdname mapviewOptions #' @aliases mapviewOptions - -# pkgs <- c("viridis", "viridisLite") -# viridis_avl <- try(sapply(pkgs, "requireNamespace", -# quietly = TRUE, USE.NAMES = FALSE)) -# viridis_avl <- any(viridis_avl) - - mapviewOptions <- function(platform, basemaps, raster.size, diff --git a/R/plainView.R b/R/plainView.R index 6b6a872ad..1cc36784d 100644 --- a/R/plainView.R +++ b/R/plainView.R @@ -52,7 +52,6 @@ if ( !isGeneric('plainView') ) { #' Tim Appelhans #' #' @examples -#' \dontrun{ #' ### raster data ### #' library(sp) #' library(raster) @@ -71,11 +70,9 @@ if ( !isGeneric('plainView') ) { #' m1 <- plainView(poppendorf[[5]]) #' m1 #' -#' # raster stack +#' # raster stack - true color #' plainview(poppendorf, 4, 3, 2) #' -#' } -#' #' @export plainView #' @name plainView #' @rdname plainView diff --git a/R/plus.R b/R/plus.R index 40c084211..341e58f1e 100644 --- a/R/plus.R +++ b/R/plus.R @@ -10,20 +10,15 @@ if ( !isGeneric('+') ) { #' the objects should be added to e1. #' #' @examples -#' \dontrun{ -#' ### raster data ### -#' library(sp) -#' library(raster) -#' -#' m1 <- mapView(poppendorf[[5]]) -#' -#' ### point vector data ### -#' m2 <- mapView(breweries91) +#' m1 <- mapView(franconia, col.regions = "red") +#' m2 <- mapView(breweries) #' #' ### add two mapview objects #' m1 + m2 #' '+'(m2, m1) -#' } +#' +#' ### add layers to a mapview object +#' m1 + breweries + poppendorf[[4]] #' #' @name + #' @docType methods diff --git a/R/popup.R b/R/popup.R index 5406c1b16..0053ebfe2 100644 --- a/R/popup.R +++ b/R/popup.R @@ -14,7 +14,7 @@ #' A \code{list} of HTML strings required to create feature popup tables. #' #' @examples -#' \dontrun{ +#' library(leaflet) #' #' ## include columns 1 and 2 only #' mapview(franconia, popup = popupTable(franconia, zcol = 1:2)) @@ -23,7 +23,6 @@ #' leaflet() %>% addCircleMarkers(data = breweries) #' leaflet() %>% addCircleMarkers(data = breweries, #' popup = popupTable(breweries)) -#' } #' #' @export popupTable #' @name popupTable @@ -57,7 +56,6 @@ popupTable = function(x, zcol, row.numbers = TRUE) { #' A \code{list} of HTML strings required to create popup graphs. #' #' @examples -#' \dontrun{ #' ## remote images ----- #' ### one image #' library(sf) @@ -89,7 +87,6 @@ popupTable = function(x, zcol, row.numbers = TRUE) { #' coords = c("x", "y"), crs = 4326) #' img = system.file("img","Rlogo.png",package="png") #' mapview(pnt, popup = popupImage(img)) -#' } #' #' @export popupImage #' @name popupImage @@ -203,7 +200,6 @@ popupRemoteImage = function(img, width = 300, height = "100%") { #' A \code{list} of HTML strings required to create popup graphs. #' #' @examples -#' \dontrun{ #' ### example: svg ----- #' #' library(sp) @@ -236,24 +232,11 @@ popupRemoteImage = function(img, width = 300, height = "100%") { #' mapview(pt, popup = popupGraph(p2, width = 300, height = 400)) #' #' ### example: html ----- -#' library(scatterD3) -#' p = lapply(1:length(meuse), function(i) { -#' clr =rep(0, length(meuse)) -#' clr[[i]] = 1 -#' scatterD3(x = meuse$cadmium, -#' y = meuse$copper, -#' col_var = clr, -#' legend_width = 0) -#' }) -#' -#' mapview(meuse, popup = popupGraph(p, type = "html", width = 400, height = 300)) -#' #' mapview(breweries[1, ], map.types = "Esri.WorldImagery", #' popup = popupGraph(mapview(breweries[1, ])@map, #' type = "html", #' width = 500, #' height = 400)) -#' } #' #' @export popupGraph #' @name popupGraph diff --git a/R/projection.R b/R/projection.R index c357aeb82..1aca99e00 100644 --- a/R/projection.R +++ b/R/projection.R @@ -10,7 +10,7 @@ wrong_proj_warning <- " projecting to '", llcrs, "'") # Check and potentially adjust projection of objects to be rendered ======= -checkAdjustProjection <- function(x, method) { +checkAdjustProjection <- function(x, method = "bilinear") { x <- switch(class(x)[1], "RasterLayer" = rasterCheckAdjustProjection(x, method), diff --git a/R/raster.R b/R/raster.R index 5193089ee..4d0b0eadf 100644 --- a/R/raster.R +++ b/R/raster.R @@ -357,6 +357,73 @@ leafletSatellite = function(x, ...) { +# Convert RasterLayers to png or RasterStacks/Bricks to RGB png + +## raster layer ----------------------------------------------------------- +raster2PNG <- function(x, + col.regions, + at, + na.color, + maxpixels) { + + x <- rasterCheckSize(x, maxpixels = maxpixels) + + mat <- t(raster::as.matrix(x)) + + if (missing(at)) at <- lattice::do.breaks(range(mat, na.rm = TRUE), 256) + + cols <- lattice::level.colors(mat, + at = at, + col.regions = col.regions) + cols[is.na(cols)] = na.color + cols = col2Hex(cols, alpha = TRUE) + #cols <- clrs(t(mat)) + png_dat <- as.raw(grDevices::col2rgb(cols, alpha = TRUE)) + dim(png_dat) <- c(4, ncol(x), nrow(x)) + + return(png_dat) +} + + +## raster stack/brick ----------------------------------------------------- + +rgbStack2PNG <- function(x, r, g, b, + na.color, + quantiles = c(0.02, 0.98), + maxpixels, + ...) { + + x <- rasterCheckSize(x, maxpixels = maxpixels) + + x3 <- raster::subset(x, c(r, g, b)) + + mat <- cbind(x[[r]][], + x[[g]][], + x[[b]][]) + + for(i in seq(ncol(mat))){ + z <- mat[, i] + lwr <- stats::quantile(z, quantiles[1], na.rm = TRUE) + upr <- stats::quantile(z, quantiles[2], na.rm = TRUE) + z <- (z - lwr) / (upr - lwr) + z[z < 0] <- 0 + z[z > 1] <- 1 + mat[, i] <- z + } + + na_indx <- rowNA(mat) #apply(mat, 1, base::anyNA) # + cols <- rep(na.color, nrow(mat)) #mat[, 1] # + #cols[na_indx] <- na.color + cols[!na_indx] <- grDevices::rgb(mat[!na_indx, ], alpha = 1) + png_dat <- as.raw(grDevices::col2rgb(cols, alpha = TRUE)) + dim(png_dat) <- c(4, ncol(x), nrow(x)) + + return(png_dat) +} + + + + ########################################################################### ########################################################################### diff --git a/R/raster2PNG.R b/R/raster2PNG.R deleted file mode 100644 index 7688cb9fc..000000000 --- a/R/raster2PNG.R +++ /dev/null @@ -1,63 +0,0 @@ -# Convert RasterLayers to png or RasterStacks/Bricks to RGB png - -## raster layer ----------------------------------------------------------- -raster2PNG <- function(x, - col.regions, - at, - na.color, - maxpixels) { - - x <- rasterCheckSize(x, maxpixels = maxpixels) - - mat <- t(raster::as.matrix(x)) - - if (missing(at)) at <- lattice::do.breaks(range(mat, na.rm = TRUE), 256) - - cols <- lattice::level.colors(mat, - at = at, - col.regions = col.regions) - cols[is.na(cols)] = na.color - cols = col2Hex(cols, alpha = TRUE) - #cols <- clrs(t(mat)) - png_dat <- as.raw(grDevices::col2rgb(cols, alpha = TRUE)) - dim(png_dat) <- c(4, ncol(x), nrow(x)) - - return(png_dat) -} - - -## raster stack/brick ----------------------------------------------------- - -rgbStack2PNG <- function(x, r, g, b, - na.color, - quantiles = c(0.02, 0.98), - maxpixels, - ...) { - - x <- rasterCheckSize(x, maxpixels = maxpixels) - - x3 <- raster::subset(x, c(r, g, b)) - - mat <- cbind(x[[r]][], - x[[g]][], - x[[b]][]) - - for(i in seq(ncol(mat))){ - z <- mat[, i] - lwr <- stats::quantile(z, quantiles[1], na.rm = TRUE) - upr <- stats::quantile(z, quantiles[2], na.rm = TRUE) - z <- (z - lwr) / (upr - lwr) - z[z < 0] <- 0 - z[z > 1] <- 1 - mat[, i] <- z - } - - na_indx <- rowNA(mat) #apply(mat, 1, base::anyNA) # - cols <- rep(na.color, nrow(mat)) #mat[, 1] # - #cols[na_indx] <- na.color - cols[!na_indx] <- grDevices::rgb(mat[!na_indx, ], alpha = 1) - png_dat <- as.raw(grDevices::col2rgb(cols, alpha = TRUE)) - dim(png_dat) <- c(4, ncol(x), nrow(x)) - - return(png_dat) -} diff --git a/R/sync.R b/R/sync.R index 60f227da9..674a167cd 100644 --- a/R/sync.R +++ b/R/sync.R @@ -16,9 +16,8 @@ #' @param no.initial.sync whether to sync the initial view (default TRUE). #' #' @examples -#' -#' \dontrun{ #' library(sp) +#' library(raster) #' #' data(meuse) #' coordinates(meuse) <- ~x+y @@ -55,8 +54,6 @@ #' sync(m1, m2, m3, m4) # synced #' sync(m1, m2, m3, m4, no.initial.sync = FALSE) # all maps zoomed to m4 extent #' -#' } -#' #' @export latticeView #' @name latticeView #' @aliases latticeView diff --git a/man/addFeatures.Rd b/man/addFeatures.Rd index 0baa94266..ed0b1bc18 100644 --- a/man/addFeatures.Rd +++ b/man/addFeatures.Rd @@ -22,15 +22,15 @@ A leaflet \code{map} object. Add simple features geomertries from \code{\link[sf]{sf}} } \examples{ -\dontrun{ -leaflet() \%>\% addTiles() \%>\% addCircleMarkers(data = breweries) -leaflet() \%>\% addTiles() \%>\% addFeatures(data = breweries) +library(leaflet) -leaflet() \%>\% addTiles() \%>\% addPolylines(data = atlStorms2005) -leaflet() \%>\% addTiles() \%>\% addFeatures(atlStorms2005) +leaflet() \%>\% addProviderTiles("OpenStreetMap") \%>\% addCircleMarkers(data = breweries) +leaflet() \%>\% addProviderTiles("OpenStreetMap") \%>\% addFeatures(data = breweries) -leaflet() \%>\% addTiles() \%>\% addPolygons(data = franconia) -leaflet() \%>\% addTiles() \%>\% addFeatures(franconia) -} +leaflet() \%>\% addProviderTiles("OpenStreetMap") \%>\% addPolylines(data = atlStorms2005) +leaflet() \%>\% addProviderTiles("OpenStreetMap") \%>\% addFeatures(atlStorms2005) + +leaflet() \%>\% addProviderTiles("OpenStreetMap") \%>\% addPolygons(data = franconia) +leaflet() \%>\% addProviderTiles("OpenStreetMap") \%>\% addFeatures(franconia) } diff --git a/man/addHomeButton.Rd b/man/addHomeButton.Rd index 8eb9e4db7..3dc4826a8 100644 --- a/man/addHomeButton.Rd +++ b/man/addHomeButton.Rd @@ -35,16 +35,17 @@ Use removeHomeButton to remove home button }} \examples{ -\dontrun{ +library(leaflet) library(raster) -m <- leaflet() \%>\% addTiles() \%>\% addCircleMarkers(data = breweries91) \%>\% - addHomeButton(extent(breweries91), "breweries91") +m <- leaflet() \%>\% + addProviderTiles("OpenStreetMap") \%>\% + addCircleMarkers(data = breweries) \%>\% + addHomeButton(extent(breweries), "breweries") m ## remove the button removeHomeButton(m) -} } diff --git a/man/addLogo.Rd b/man/addLogo.Rd index 7b829f008..61f6f00bf 100644 --- a/man/addLogo.Rd +++ b/man/addLogo.Rd @@ -36,7 +36,7 @@ This function adds an image to a map. Both local and remote (web) image sources are supported. Position on the map is completely controllable. } \examples{ -\dontrun{ +library(leaflet) ## default position is topleft next to zoom control img <- "https://www.r-project.org/logo/Rlogo.svg" @@ -49,7 +49,6 @@ img <- system.file("img", "Rlogo.png", package="png") leaflet() \%>\% addTiles() \%>\% addLogo(img, src = "local", alpha = 0.3) ## dancing banana gif :-) -library(magick) m <- mapview(breweries91) addLogo(m, "https://jeroenooms.github.io/images/banana.gif", @@ -59,7 +58,5 @@ addLogo(m, "https://jeroenooms.github.io/images/banana.gif", width = 100, height = 100) -} - } diff --git a/man/addMouseCoordinates.Rd b/man/addMouseCoordinates.Rd index 189ad986f..dcee2f0ec 100644 --- a/man/addMouseCoordinates.Rd +++ b/man/addMouseCoordinates.Rd @@ -41,11 +41,15 @@ If style is set to "detailed", the following information will be displayed: If style is set to "basic", only 'lat', 'lon' and 'zoom' are shown. } \examples{ -\dontrun{ -leaflet() \%>\% addTiles() # without mouse position info -leaflet() \%>\% addTiles() \%>\% addMouseCoordinates(style = "basic") # with basic mouse position info -mapview(easter.egg = TRUE) # detailed mouse position info by default ;-) -} +library(leaflet) + +leaflet() \%>\% addProviderTiles("OpenStreetMap") # without mouse position info +leaflet() \%>\% + addProviderTiles("OpenStreetMap") \%>\% + addMouseCoordinates(style = "basic") # with basic mouse position info +leaflet() \%>\% + addProviderTiles("OpenStreetMap") \%>\% + addMouseCoordinates() # with detailed mouse position info } diff --git a/man/coords2Lines.Rd b/man/coords2Lines.Rd index f4ab448b5..802dc68d5 100644 --- a/man/coords2Lines.Rd +++ b/man/coords2Lines.Rd @@ -35,7 +35,6 @@ point coordinates in one go, i.e. without being required to run through the single steps outlined in \code{\link{SpatialLines}}. } \examples{ -\dontrun{ library(sp) coords1 <- cbind(c(2, 4, 4, 1, 2), c(2, 3, 5, 4, 2)) @@ -48,7 +47,6 @@ mapview(sln1) plot(sln1, col = "grey75") plot(sln2, col = "grey25", add = TRUE) -} } \seealso{ diff --git a/man/coords2Polygons.Rd b/man/coords2Polygons.Rd index c7ff6810c..a5a7bdc8b 100644 --- a/man/coords2Polygons.Rd +++ b/man/coords2Polygons.Rd @@ -38,7 +38,6 @@ of point coordinates in one go, i.e. without being required to run through the single steps outlined in \code{\link{SpatialPolygons}}. } \examples{ -\dontrun{ library(sp) coords1 <- cbind(c(2, 4, 4, 1, 2), c(2, 3, 5, 4, 2)) @@ -49,7 +48,6 @@ spy2 <- coords2Polygons(coords2, ID = "B") plot(spy1, col = "grey75") plot(spy2, col = "grey25", add = TRUE) -} } \seealso{ diff --git a/man/cubeView.Rd b/man/cubeView.Rd index 7c829bf68..3a9a11479 100644 --- a/man/cubeView.Rd +++ b/man/cubeView.Rd @@ -52,7 +52,6 @@ move mouse down/up to zoom the cube. }} \examples{ -\dontrun{ library(raster) kili_data <- system.file("extdata", "kiliNDVI.tif", package = "mapview") @@ -60,10 +59,8 @@ kiliNDVI <- stack(kili_data) cubeView(kiliNDVI) -library(RColorBrewer) -clr <- colorRampPalette(brewer.pal(9, "BrBG")) +clr <- viridisLite::viridis cubeView(kiliNDVI, at = seq(-0.15, 0.95, 0.1), col.regions = clr) -} } \author{ diff --git a/man/garnishMap.Rd b/man/garnishMap.Rd index 64b7c3126..6d368f644 100644 --- a/man/garnishMap.Rd +++ b/man/garnishMap.Rd @@ -19,14 +19,16 @@ them to the map. Arguments must be named. Functions can be plain or character strings. } \examples{ -\dontrun{ -m <- leaflet() \%>\% addTiles() -garnishMap(m, addMouseCoordinates) +library(leaflet) + +m <- leaflet() \%>\% addProviderTiles("OpenStreetMap") +garnishMap(m, addMouseCoordinates, style = "basic") ## add more than one with named argument library(raster) + m1 <- garnishMap(m, addMouseCoordinates, addHomeButton, - ext = extent(breweries91)) + ext = extent(breweries)) m1 ## even more flexible @@ -35,5 +37,3 @@ m2 <- garnishMap(m1, addPolygons, data = franconia, popup = popupTable(franconia garnishMap(m2, addCircleMarkers, data = breweries) } - -} diff --git a/man/latticeView.Rd b/man/latticeView.Rd index f7ecefcbc..4ba9f3175 100644 --- a/man/latticeView.Rd +++ b/man/latticeView.Rd @@ -42,9 +42,8 @@ is best to use the provided convenience function \code{sync}. }} \examples{ - -\dontrun{ library(sp) +library(raster) data(meuse) coordinates(meuse) <- ~x+y @@ -82,5 +81,3 @@ sync(m1, m2, m3, m4) # synced sync(m1, m2, m3, m4, no.initial.sync = FALSE) # all maps zoomed to m4 extent } - -} diff --git a/man/mapviewOptions.Rd b/man/mapviewOptions.Rd index 9c09e0b98..72414e4ff 100644 --- a/man/mapviewOptions.Rd +++ b/man/mapviewOptions.Rd @@ -95,13 +95,14 @@ query single mapviewOption parameters }} \examples{ -\dontrun{ mapviewOptions() mapviewOptions(na.color = "pink") mapviewOptions() mapviewGetOption("platform") -} + +mapviewOptions(default = TRUE) +mapviewOptions() } diff --git a/man/plainView.Rd b/man/plainView.Rd index 6a21e1365..2f4a81fb0 100644 --- a/man/plainView.Rd +++ b/man/plainView.Rd @@ -96,7 +96,6 @@ For plainView there are a few keyboard shortcuts defined: }} \examples{ -\dontrun{ ### raster data ### library(sp) library(raster) @@ -115,11 +114,9 @@ plainView(meuse.grid, zcol = "dist") m1 <- plainView(poppendorf[[5]]) m1 -# raster stack +# raster stack - true color plainview(poppendorf, 4, 3, 2) -} - } \author{ Stephan Woellauer diff --git a/man/plus.Rd b/man/plus.Rd index 058a9a0c8..b07b00583 100644 --- a/man/plus.Rd +++ b/man/plus.Rd @@ -30,19 +30,14 @@ mapview + data adds spatial data (raster*, sf*, sp*) to a mapview map [...] } \examples{ -\dontrun{ -### raster data ### -library(sp) -library(raster) - -m1 <- mapView(poppendorf[[5]]) - -### point vector data ### -m2 <- mapView(breweries91) +m1 <- mapView(franconia, col.regions = "red") +m2 <- mapView(breweries) ### add two mapview objects m1 + m2 '+'(m2, m1) -} + +### add layers to a mapview object +m1 + breweries + poppendorf[[4]] } diff --git a/man/popup.Rd b/man/popup.Rd index d17d6a7ee..dc68c9282 100644 --- a/man/popup.Rd +++ b/man/popup.Rd @@ -67,7 +67,7 @@ Type \code{html} embeds via \code{"