Learn R Programming

leafem (version 0.1.3)

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, epsg = NULL, proj4string = NULL, native.crs = FALSE)

removeMouseCoordinates(map)

clip2sfc(x, clipboard = TRUE)

Arguments

map

a mapview or leaflet object.

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.

x

a charcter string with valid longitude and latitude values. Order matters! If missing and clipboard = TRUE (the default) contents will be read from the clipboard.

clipboard

whether to read contents from the clipboard. Default is TRUE.

Functions

  • removeMouseCoordinates: remove mouse coordinates information from a map

  • clip2sfc: convert mouse coordinates from clipboard to sfc

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

By default, only 'lat', 'lon' and 'zoom' are shown. To show the details about epsg, proj4 press and hold 'Ctrl' and move the mouse. 'Ctrl' + click will copy the current contents of the box/strip at the top of the map to the clipboard, though currently only copying of 'lon', 'lat' and 'zoom' are supported, not 'epsg' and 'proj4' as these do not change with pan and zoom.

Examples

Run this code
# NOT RUN {
library(leaflet)

leaflet() %>%
  addProviderTiles("OpenStreetMap") # without mouse position info
m = leaflet() %>%
  addProviderTiles("OpenStreetMap") %>%
  addMouseCoordinates()

m

removeMouseCoordinates(m)

# }

Run the code above in your browser using DataLab