Learn R Programming

leafem (version 0.2.3)

addImageQuery: Add image query functionality to leaflet/mapview map.

Description

Add image query functionality to leaflet/mapview map.

Usage

addImageQuery(
  map,
  x,
  band = 1,
  group = NULL,
  layerId = NULL,
  project = TRUE,
  type = c("mousemove", "click"),
  digits,
  position = "topright",
  prefix = "Layer",
  className = "",
  ...
)

Value

A leaflet map object.

Arguments

map

the map with the RasterLayer to be queried.

x

the RasterLayer that is to be queried.

band

for stars layers, the band number to be queried.

group

the group of the RasterLayer to be queried.

layerId

the layerId of the RasterLayer to be queried. Needs to be the same as supplied in addRasterImage or addStarsImage.

project

whether to project the RasterLayer to conform with leaflets expected crs. Defaults to TRUE and things are likely to go haywire if set to FALSE.

type

whether query should occur on 'mousemove' or 'click'. Defaults to 'mousemove'.

digits

the number of digits to be shown in the display field.

position

where to place the display field. Default is 'topright'.

prefix

a character string to be shown as prefix for the layerId.

className

a character string to append to the control legend.

...

currently not used.

Details

This function enables Raster*/stars objects added to leaflet/mapview maps to be queried. Standard query is on 'mousmove', but can be changed to 'click'. Note that for this to work, the layerId needs to be the same as the one that was set in addRasterImage or addStarsImage. Currently only works for numeric values (i.e. numeric/integer and factor values are supported).

Examples

Run this code
if (interactive()) {
  if (requireNamespace("plainview")) {
    library(leaflet)
    library(plainview)

    leaflet() %>%
      addProviderTiles("OpenStreetMap") %>%
      addRasterImage(poppendorf[[1]], project = TRUE, group = "poppendorf",
                     layerId = "poppendorf") %>%
      addImageQuery(poppendorf[[1]], project = TRUE,
                    layerId = "poppendorf") %>%
      addLayersControl(overlayGroups = "poppendorf")
  }
}

Run the code above in your browser using DataLab