Method new()
Constructor of R6Map.
Usage
R6Map$new(lon = 0, lat = 0, zoom = 1, save_maps = TRUE)
Arguments
lon
The longitude of the center, in degrees. By default -76.942478.
lat
The latitude of the center, in degrees. By default -12.172116.
zoom
The zoom level, from 1 to 24. By default 18.
save_maps
Should R6Map
save previous maps?.
Returns
A new EarthEngineMap
object.
Method reset()
Reset to initial arguments.
Usage
R6Map$reset(lon = 0, lat = 0, zoom = 1, save_maps = TRUE)
Arguments
lon
The longitude of the center, in degrees. By default -76.942478.
lat
The latitude of the center, in degrees. By default -12.172116.
zoom
The zoom level, from 1 to 24. By default 18.
save_maps
Should R6Map
save previous maps?.
Returns
A new EarthEngineMap
object.
Examples
\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
}
Display a EarthEngineMap
object.
Returns
An EarthEngineMap
object.
Method 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.
Usage
R6Map$setCenter(lon = 0, lat = 0, zoom = 10)
Arguments
lon
The longitude of the center, in degrees. By default -76.942478.
lat
The latitude of the center, in degrees. By default -12.172116.
zoom
The zoom level, from 1 to 24. By default 18.
Returns
No return value, called to set initial coordinates and zoom.
Examples
\dontrun{
library(rgee)ee_Initialize()
Map <- R6Map$new()
Map$setCenter(lon = -76, lat = 0, zoom = 5)
Map
# Map$lat
# Map$lon
# Map$zoom
}
Method setZoom()
Sets the zoom level of the map.
Usage
R6Map$setZoom(zoom = 10)
Arguments
zoom
The zoom level, from 1 to 24. By default 10.
Returns
No return value, called to set zoom.
Examples
\dontrun{
library(rgee)ee_Initialize()
Map <- R6Map$new()
Map$setZoom(zoom = 4)
Map
# Map$lat
# Map$lon
# Map$zoom
}
Method 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.
Usage
R6Map$centerObject(
eeObject,
zoom = NULL,
maxError = ee$ErrorMargin(1),
titiler_server = "https://api.cogeo.xyz/"
)
Arguments
eeObject
Earth Engine spatial object.
zoom
The zoom level, from 1 to 24. By default NULL.
maxError
Max error when input image must be reprojected to an
explicitly requested result projection or geodesic state.
titiler_server
TiTiler endpoint. Defaults to "https://api.cogeo.xyz/".
Returns
No return value, called to set zoom.
Examples
\dontrun{
library(rgee)ee_Initialize()
Map <- R6Map$new()
image <- ee$Image("LANDSAT/LC08/C01/T1/LC08_044034_20140318")
Map$centerObject(image)
Map
}
Method addLayer()
Adds a given Earth Engine spatial object to the map as a layer
Usage
R6Map$addLayer(
eeObject,
visParams = NULL,
name = NULL,
shown = TRUE,
opacity = 1,
position = NULL,
titiler_viz_convert = TRUE,
titiler_server = "https://api.cogeo.xyz/"
)
Arguments
eeObject
The Earth Engine spatial object to display in the interactive map.
visParams
List of parameters for visualization. See details.
name
The name of layers.
shown
A flag indicating whether layers should be on by default.
opacity
The layer's opacity is represented as a number between 0 and 1. Defaults to 1.
position
Character. 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_convert
Logical. If it is TRUE, Map$addLayer will transform the
visParams to titiler style. Ignored if eeObject is not a COG file.
titiler_server
TiTiler endpoint. Defaults to "https://api.cogeo.xyz/".
Returns
An EarthEngineMap
object.
Examples
\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()
}
Method addLayers()
Adds a given ee$ImageCollection to the map as multiple layers.
Usage
R6Map$addLayers(
eeObject,
visParams = NULL,
nmax = 5,
name = NULL,
shown = TRUE,
position = NULL,
opacity = 1
)
Arguments
eeObject
ee$ImageCollection to display in the interactive map.
visParams
List of parameters for visualization. See details.
nmax
Numeric. The maximum number of images to display. By default 5.
name
The name of layers.
shown
A flag indicating whether layers should be on by default.
position
Character. 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).
opacity
The layer's opacity is represented as a number between 0 and 1. Defaults to 1.
Returns
A EarthEngineMap
object.
Examples
\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()
}
Method addLegend()
Adds a color legend to an EarthEngineMap.
Usage
R6Map$addLegend(
visParams,
name = "Legend",
position = c("bottomright", "topright", "bottomleft", "topleft"),
color_mapping = "numeric",
opacity = 1,
...
)
Arguments
visParams
List of parameters for visualization.
name
The title of the legend.
position
Character. The position of the legend. By default bottomright.
color_mapping
Map 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.
opacity
The legend's opacity is represented as a number between 0
and 1. Defaults to 1.
...
Extra legend creator arguments. See addLegend.
Returns
A EarthEngineMap
object.
Examples
\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")
}
Method clone()
The objects of this class are cloneable with this method.
Usage
R6Map$clone(deep = FALSE)
Arguments
deep
Whether to make a deep clone.