Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

map-methods

Methods to manipulate the map widget


Description

A series of methods to manipulate the map.

Usage

setView(map, lng, lat, zoom, options = list())

flyTo(map, lng, lat, zoom, options = list())

fitBounds(map, lng1, lat1, lng2, lat2, options = list())

flyToBounds(map, lng1, lat1, lng2, lat2, options = list())

setMaxBounds(map, lng1, lat1, lng2, lat2)

clearBounds(map)

Arguments

map

a map widget object created from leaflet()

lng

The longitude of the map center

lat

The latitude of the map center

zoom

the zoom level

options

a list of zoom/pan options (see https://leafletjs.com/reference-1.3.4.html#zoom/pan-options)

lng1, lat1, lng2, lat2

the coordinates of the map bounds

Value

The modified map widget.

Functions

  • setView: Set the view of the map (center and zoom level)

  • flyTo: Flys to a given location/zoom-level using smooth pan-zoom.

  • fitBounds: Set the bounds of a map

  • flyToBounds: Flys to given bound using smooth pan/zoom.

  • setMaxBounds: Restricts the map view to the given bounds

  • clearBounds: Clear the bounds of a map, and the bounds will be automatically determined from latitudes and longitudes of the map elements if available (otherwise the full world view is used)

References

Examples

m <- leaflet() %>% addTiles() %>% setView(-71.0382679, 42.3489054, zoom = 18)
m  # the RStudio 'headquarter'
m %>% fitBounds(-72, 40, -70, 43)
m %>% clearBounds()  # world view

leaflet

Create Interactive Web Maps with the JavaScript 'Leaflet' Library

v2.0.4.1
GPL-3
Authors
Joe Cheng [aut, cre], Bhaskar Karambelkar [aut], Yihui Xie [aut], Hadley Wickham [ctb], Kenton Russell [ctb], Kent Johnson [ctb], Barret Schloerke [ctb], jQuery Foundation and contributors [ctb, cph] (jQuery library), Vladimir Agafonkin [ctb, cph] (Leaflet library), CloudMade [cph] (Leaflet library), Leaflet contributors [ctb] (Leaflet library), Brandon Copeland [ctb, cph] (leaflet-measure plugin), Joerg Dietrich [ctb, cph] (Leaflet.Terminator plugin), Benjamin Becquet [ctb, cph] (Leaflet.MagnifyingGlass plugin), Norkart AS [ctb, cph] (Leaflet.MiniMap plugin), L. Voogdt [ctb, cph] (Leaflet.awesome-markers plugin), Daniel Montague [ctb, cph] (Leaflet.EasyButton plugin), Kartena AB [ctb, cph] (Proj4Leaflet plugin), Robert Kajic [ctb, cph] (leaflet-locationfilter plugin), Mapbox [ctb, cph] (leaflet-omnivore plugin), Michael Bostock [ctb, cph] (topojson), RStudio [cph]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.