Learn R Programming

mapview (version 2.5.0)

addMouseCoordinates: Add mouse coordinate information at top of map.

Description

This function adds a box displaying the current cursor location (latitude, longitude and zoom level) at the top of a rendered mapview or leaflet map. In case of mapview, this is automatically added. NOTE: The information will only render once a mouse movement has happened on the map.

Usage

addMouseCoordinates(map, style = c("detailed", "basic"), epsg = NULL,
  proj4string = NULL, native.crs = FALSE)

removeMouseCoordinates(map)

Arguments

map

a mapview or leaflet object.

style

whether to show 'detailed' or 'basic' mouse position info. See Details for an explanation.

epsg

the epsg string to be shown.

proj4string

the proj4string to be shown.

native.crs

logical. whether to use the native crs in the coordinates box.

Functions

  • removeMouseCoordinates: remove mouse coordinates information from a map

Details

If style is set to "detailed", the following information will be displayed:

  • x: x-position of the mouse cursor in projected coordinates

  • y: y-position of the mouse cursor in projected coordinates

  • epsg: the epsg code of the coordinate reference system of the map

  • proj4: the proj4 definition of the coordinate reference system of the map

  • lat: latitude position of the mouse cursor

  • lon: longitude position of the mouse cursor

  • zoom: the current zoom level

If style is set to "basic", only 'lat', 'lon' and 'zoom' are shown.

Examples

Run this code
# NOT RUN {
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


m = mapview(breweries)
removeMouseCoordinates(m)

# }

Run the code above in your browser using DataLab