| R6Map | R Documentation |
Create interactive visualizations of spatial EE objects
(ee$Geometry, ee$Image, ee$Feature, and ee$FeatureCollection)
using leaflet.
R6Map uses the Earth Engine method
getMapId to fetch and return an ID dictionary used to create
layers in a leaflet object. Users can specify visualization
parameters to Map$addLayer by using the visParams argument. Each Earth
Engine spatial object has a specific format. For
ee$Image, the
parameters available are:
| Parameter | Description | Type |
| bands | Comma-delimited list of three band (RGB) | list |
| min | Value(s) to map to 0 | number or list of three numbers, one for each band |
| max | Value(s) to map to 1 | number or list of three numbers, one for each band |
| gain | Value(s) by which to multiply each pixel value | number or list of three numbers, one for each band |
| bias | Value(s) to add to each Digital Number value | number or list of three numbers, one for each band |
| gamma | Gamma correction factor(s) | number or list of three numbers, one for each band |
| palette | List of CSS-style color strings (single-band only) | comma-separated list of hex strings |
| opacity | The opacity of the layer (from 0 to 1) | number |
If you add an ee$Image to Map$addLayer without any additional
parameters. By default it assigns the first three bands to red,
green, and blue bands, respectively. The default stretch is based on the
min-max range. On the other hand, the available parameters for
ee$Geometry, ee$Feature, and ee$FeatureCollection
are:
color: A hex string in the format RRGGBB specifying the color to use for drawing the features. By default #000000.
pointRadius: The radius of the point markers. By default 3.
strokeWidth: The width of lines and polygon borders. By default 3.
Object of class leaflet and EarthEngineMap, with the
following extra parameters: tokens, name, opacity, shown, min, max, palette,
position, and legend. Use the $ method to retrieve the data (e.g., m$rgee$min).
lonThe longitude of the center, in degrees.
latThe latitude of the center, in degrees.
zoomThe zoom level, from 1 to 24.
save_mapsShould R6Map save the previous maps?. If TRUE, Map
will work in an OOP style. Otherwise it will be a functional programming
style.
previous_map_leftContainer on maps in the left side.
previous_map_rightContainer on maps in the right side.
new()Constructor of R6Map.
R6Map$new(lon = 0, lat = 0, zoom = 1, save_maps = TRUE)
lonThe longitude of the center, in degrees. By default -76.942478.
latThe latitude of the center, in degrees. By default -12.172116.
zoomThe zoom level, from 1 to 24. By default 18.
save_mapsShould R6Map save previous maps?.
A new EarthEngineMap object.
reset()Reset to initial arguments.
R6Map$reset(lon = 0, lat = 0, zoom = 1, save_maps = TRUE)
lonThe longitude of the center, in degrees. By default -76.942478.
latThe latitude of the center, in degrees. By default -12.172116.
zoomThe zoom level, from 1 to 24. By default 18.
save_mapsShould R6Map save previous maps?.
A new EarthEngineMap object.
\dontrun{
library(rgee)
ee_Initialize()
# Load an Image
image <- ee$Image("LANDSAT/LC08/C01/T1/LC08_044034_20140318")
# Create
Map <- R6Map$new()
Map$centerObject(image)
# Simple display: Map just will
Map$addLayer(
eeObject = image,
visParams = list(min=0, max = 10000, bands = c("B4", "B3", "B2")),
name = "l8_01"
)
Map # display map
Map$reset() # Reset arguments
Map
}
print()Display a EarthEngineMap object.
R6Map$print()
An EarthEngineMap object.
setCenter()Centers the map view at the given coordinates with the given zoom level. If no zoom level is provided, it uses 10 by default.
R6Map$setCenter(lon = 0, lat = 0, zoom = 10)
lonThe longitude of the center, in degrees. By default -76.942478.
latThe latitude of the center, in degrees. By default -12.172116.
zoomThe zoom level, from 1 to 24. By default 18.
No return value, called to set initial coordinates and zoom.
\dontrun{
library(rgee)
ee_Initialize()
Map <- R6Map$new()
Map$setCenter(lon = -76, lat = 0, zoom = 5)
Map
# Map$lat
# Map$lon
# Map$zoom
}
setZoom()Sets the zoom level of the map.
R6Map$setZoom(zoom = 10)
zoomThe zoom level, from 1 to 24. By default 10.
No return value, called to set zoom.
\dontrun{
library(rgee)
ee_Initialize()
Map <- R6Map$new()
Map$setZoom(zoom = 4)
Map
# Map$lat
# Map$lon
# Map$zoom
}
centerObject()Centers the map view on a given object. If no zoom level is provided, it will be predicted according to the bounds of the Earth Engine object specified.
R6Map$centerObject( eeObject, zoom = NULL, maxError = ee$ErrorMargin(1), titiler_server = "https://api.cogeo.xyz/" )
eeObjectEarth Engine spatial object.
zoomThe zoom level, from 1 to 24. By default NULL.
maxErrorMax error when input image must be reprojected to an explicitly requested result projection or geodesic state.
titiler_serverTiTiler endpoint. Defaults to "https://api.cogeo.xyz/".
No return value, called to set zoom.
\dontrun{
library(rgee)
ee_Initialize()
Map <- R6Map$new()
image <- ee$Image("LANDSAT/LC08/C01/T1/LC08_044034_20140318")
Map$centerObject(image)
Map
}
addLayer()Adds a given Earth Engine spatial object to the map as a layer
R6Map$addLayer( eeObject, visParams = NULL, name = NULL, shown = TRUE, opacity = 1, position = NULL, titiler_viz_convert = TRUE, titiler_server = "https://api.cogeo.xyz/" )
eeObjectThe Earth Engine spatial object to display in the interactive map.
visParamsList of parameters for visualization. See details.
nameThe name of layers.
shownA flag indicating whether layers should be on by default.
opacityThe layer's opacity is represented as a number between 0 and 1. Defaults to 1.
positionCharacter. Activate panel creation. If "left" the map will be displayed in the left panel. Otherwise, if it is "right" the map will be displayed in the right panel. By default NULL (No panel will be created).
titiler_viz_convertLogical. If it is TRUE, Map$addLayer will transform the visParams to titiler style. Ignored if eeObject is not a COG file.
titiler_serverTiTiler endpoint. Defaults to "https://api.cogeo.xyz/".
An EarthEngineMap object.
\dontrun{
library(rgee)
ee_Initialize()
# Load an Image
image <- ee$Image("LANDSAT/LC08/C01/T1/LC08_044034_20140318")
# Create
Map <- R6Map$new()
Map$centerObject(image)
# Simple display: Map just will
Map$addLayer(
eeObject = image,
visParams = list(min=0, max = 10000, bands = c("B4", "B3", "B2")),
name = "l8_01"
)
Map$addLayer(
eeObject = image,
visParams = list(min=0, max = 20000, bands = c("B4", "B3", "B2")),
name = "l8_02"
)
# Simple display: Map just will (if the position is not specified it will
# be saved on the right side)
Map$reset() # Reset Map to the initial arguments.
Map$centerObject(image)
Map$addLayer(
eeObject = image,
visParams = list(min=0, max=10000, bands = c("B4", "B3", "B2")),
name = "l8_left",
position = "left"
)
Map$addLayer(
eeObject = image,
visParams = list(min=0, max=20000, bands = c("B4", "B3", "B2")),
name = "l8_right"
)
Map$reset()
}
addLayers()Adds a given ee$ImageCollection to the map as multiple layers.
R6Map$addLayers( eeObject, visParams = NULL, nmax = 5, name = NULL, shown = TRUE, position = NULL, opacity = 1 )
eeObjectee$ImageCollection to display in the interactive map.
visParamsList of parameters for visualization. See details.
nmaxNumeric. The maximum number of images to display. By default 5.
nameThe name of layers.
shownA flag indicating whether layers should be on by default.
positionCharacter. Activate panel creation. If "left" the map will be displayed in the left panel. Otherwise, if it is "right" the map will be displayed in the right panel. By default NULL (No panel will be created).
opacityThe layer's opacity is represented as a number between 0 and 1. Defaults to 1.
A EarthEngineMap object.
\dontrun{
library(sf)
library(rgee)
ee_Initialize()
Map <- R6Map$new()
nc <- st_read(system.file("shape/nc.shp", package = "sf")) %>%
st_transform(4326) %>%
sf_as_ee()
ee_s2 <- ee$ImageCollection("COPERNICUS/S2")$
filterDate("2016-01-01", "2016-01-31")$
filterBounds(nc)
ee_s2 <- ee$ImageCollection(ee_s2$toList(2))
Map$centerObject(nc$geometry())
Map$addLayers(eeObject = ee_s2,position = "right")
# digging up the metadata
Map$previous_map_right$rgee$tokens
Map$reset()
}
addLegend()Adds a color legend to an EarthEngineMap.
R6Map$addLegend(
visParams,
name = "Legend",
position = c("bottomright", "topright", "bottomleft", "topleft"),
color_mapping = "numeric",
opacity = 1,
...
)visParamsList of parameters for visualization.
nameThe title of the legend.
positionCharacter. The position of the legend. By default bottomright.
color_mappingMap data values (numeric or factor/character) to colors according to a given palette. Use "numeric" ("discrete") for continuous (categorical) data. For display characters use "character" and add to visParams the element "values" containing the desired character names.
opacityThe legend's opacity is represented as a number between 0 and 1. Defaults to 1.
...Extra legend creator arguments. See addLegend.
A EarthEngineMap object.
\dontrun{
library(leaflet)
library(rgee)
ee_Initialize()
Map$reset()
# Load MODIS ImageCollection
imgcol <- ee$ImageCollection$Dataset$MODIS_006_MOD13Q1
# Parameters for visualization
labels <- c("good", "marginal", "snow", "cloud")
cols <- c("#999999", "#00BFC4", "#F8766D", "#C77CFF")
vis_qc <- list(min = 0, max = 3, palette = cols, bands = "SummaryQA", values = labels)
# Create interactive map
m_qc <- Map$addLayer(imgcol$median(), vis_qc, "QC")
# continous palette
Map$addLegend(vis_qc)
# categorical palette
Map$addLegend(vis_qc, name = "Legend1", color_mapping = "discrete")
# character palette
Map$addLegend(vis_qc, name = "Legend2", color_mapping = "character")
}
clone()The objects of this class are cloneable with this method.
R6Map$clone(deep = FALSE)
deepWhether to make a deep clone.
## ------------------------------------------------
## Method `R6Map$reset`
## ------------------------------------------------
## Not run:
library(rgee)
ee_Initialize()
# Load an Image
image <- ee$Image("LANDSAT/LC08/C01/T1/LC08_044034_20140318")
# Create
Map <- R6Map$new()
Map$centerObject(image)
# Simple display: Map just will
Map$addLayer(
eeObject = image,
visParams = list(min=0, max = 10000, bands = c("B4", "B3", "B2")),
name = "l8_01"
)
Map # display map
Map$reset() # Reset arguments
Map
## End(Not run)
## ------------------------------------------------
## Method `R6Map$setCenter`
## ------------------------------------------------
## Not run:
library(rgee)
ee_Initialize()
Map <- R6Map$new()
Map$setCenter(lon = -76, lat = 0, zoom = 5)
Map
# Map$lat
# Map$lon
# Map$zoom
## End(Not run)
## ------------------------------------------------
## Method `R6Map$setZoom`
## ------------------------------------------------
## Not run:
library(rgee)
ee_Initialize()
Map <- R6Map$new()
Map$setZoom(zoom = 4)
Map
# Map$lat
# Map$lon
# Map$zoom
## End(Not run)
## ------------------------------------------------
## Method `R6Map$centerObject`
## ------------------------------------------------
## Not run:
library(rgee)
ee_Initialize()
Map <- R6Map$new()
image <- ee$Image("LANDSAT/LC08/C01/T1/LC08_044034_20140318")
Map$centerObject(image)
Map
## End(Not run)
## ------------------------------------------------
## Method `R6Map$addLayer`
## ------------------------------------------------
## Not run:
library(rgee)
ee_Initialize()
# Load an Image
image <- ee$Image("LANDSAT/LC08/C01/T1/LC08_044034_20140318")
# Create
Map <- R6Map$new()
Map$centerObject(image)
# Simple display: Map just will
Map$addLayer(
eeObject = image,
visParams = list(min=0, max = 10000, bands = c("B4", "B3", "B2")),
name = "l8_01"
)
Map$addLayer(
eeObject = image,
visParams = list(min=0, max = 20000, bands = c("B4", "B3", "B2")),
name = "l8_02"
)
# Simple display: Map just will (if the position is not specified it will
# be saved on the right side)
Map$reset() # Reset Map to the initial arguments.
Map$centerObject(image)
Map$addLayer(
eeObject = image,
visParams = list(min=0, max=10000, bands = c("B4", "B3", "B2")),
name = "l8_left",
position = "left"
)
Map$addLayer(
eeObject = image,
visParams = list(min=0, max=20000, bands = c("B4", "B3", "B2")),
name = "l8_right"
)
Map$reset()
## End(Not run)
## ------------------------------------------------
## Method `R6Map$addLayers`
## ------------------------------------------------
## Not run:
library(sf)
library(rgee)
ee_Initialize()
Map <- R6Map$new()
nc <- st_read(system.file("shape/nc.shp", package = "sf")) %>%
st_transform(4326) %>%
sf_as_ee()
ee_s2 <- ee$ImageCollection("COPERNICUS/S2")$
filterDate("2016-01-01", "2016-01-31")$
filterBounds(nc)
ee_s2 <- ee$ImageCollection(ee_s2$toList(2))
Map$centerObject(nc$geometry())
Map$addLayers(eeObject = ee_s2,position = "right")
# digging up the metadata
Map$previous_map_right$rgee$tokens
Map$reset()
## End(Not run)
## ------------------------------------------------
## Method `R6Map$addLegend`
## ------------------------------------------------
## Not run:
library(leaflet)
library(rgee)
ee_Initialize()
Map$reset()
# Load MODIS ImageCollection
imgcol <- ee$ImageCollection$Dataset$MODIS_006_MOD13Q1
# Parameters for visualization
labels <- c("good", "marginal", "snow", "cloud")
cols <- c("#999999", "#00BFC4", "#F8766D", "#C77CFF")
vis_qc <- list(min = 0, max = 3, palette = cols, bands = "SummaryQA", values = labels)
# Create interactive map
m_qc <- Map$addLayer(imgcol$median(), vis_qc, "QC")
# continous palette
Map$addLegend(vis_qc)
# categorical palette
Map$addLegend(vis_qc, name = "Legend1", color_mapping = "discrete")
# character palette
Map$addLegend(vis_qc, name = "Legend2", color_mapping = "character")
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.