From 56fdf437ed7f328ead342a6b9bf6dd99c1b6125e Mon Sep 17 00:00:00 2001
From: cpsievert Note that some tile set providers require you to register; see the project
+
+ Note that some tile set providers require you to register; see the project
page for more information. You can pass access tokens/keys, and
other options, to the tile provider by populating the
Default (OpenStreetMap) Tileslibrary(leaflet)
m <- leaflet() %>% setView(lng = -71.0589, lat = 42.3601, zoom = 12)
m %>% addTiles()
-
-
+
+
Third-Party Tiles
@@ -137,14 +137,14 @@
Third-Party Tiles
m %>% addProviderTiles(providers$Stadia.StamenToner)
+
+
m %>% addProviderTiles(providers$CartoDB.Positron)
+
+
m %>% addProviderTiles(providers$Esri.NatGeoWorldMap)
options
argument with the
@@ -171,8 +171,8 @@ WMS Tiles= WMSTileOptions(format = "image/png", transparent = TRUE),
attribution = "Weather data © 2012 IEM Nexrad"
)
leaflet(df) %>% addTiles() %>% addCircleMarkers()
Or customize their color, radius, stroke, opacity, etc.
+ +Or customize their color, radius, stroke, opacity, etc.
# Create a palette that maps factor levels to colors
pal <- colorFactor(c("navy", "red"), domain = c("ship", "pirate"))
@@ -308,8 +308,8 @@ Circle Markers color = ~pal(type),
stroke = FALSE, fillOpacity = 0.5
)
Use various options to customize the appearance and behavior of the +
+Use various options to customize the appearance and behavior of the
plugin (see ?addMeasure
for details).
m %>%
@@ -163,8 +163,8 @@ Leaflet Measure primaryAreaUnit = "sqmeters",
activeColor = "#3D535D",
completedColor = "#7D4479")
+ +- -m %>% addGraticule(interval = 40, style = list(color = "#FF0000", weight = 1))
You can use the
+group
argument to make the graticule +You can use the
group
argument to make the graticule toggleable.- - + +m %>% addGraticule(group = "Graticule") %>% addLayersControl(overlayGroups = c("Graticule"), options = layersControlOptions(collapsed = FALSE))
+ +- - + +# Custom Resolution + Custom Date and on a toggleable Layer leaflet() %>% addTiles() %>% @@ -212,8 +212,8 @@
Terminator (day/night indicator) addLayersControl( overlayGroups = "daylight", options = layersControlOptions(collapsed = FALSE))
You can use a specific basemap for the minimap via the +
+You can use a specific basemap for the minimap via the
tiles
parameter. This example also allows the minimap to be
hidden by setting toggleDisplay = TRUE
.
@@ -240,8 +240,8 @@Minimap addMiniMap( tiles = providers$Esri.WorldStreetMap, toggleDisplay = TRUE)
The next example demonstrates an easyButton with two distinct states: +
+The next example demonstrates an easyButton with two distinct states:
frozen-markers
and unfrozen-markers
, each of
which has a distinct icon, title, and click handler.
@@ -299,8 +299,8 @@EasyButton) ) ))
myMap.minimap.changeLayer(L.tileLayer.provider(e.name));
})
}")
A common use for popups is to have them appear when markers or shapes +
+A common use for popups is to have them appear when markers or shapes
are clicked. Marker and shape functions in the Leaflet package take a
popup
argument, where you can pass in HTML to easily attach
a simple popup.
In the preceding example, htmltools::htmlEscape
was used
+
In the preceding example, htmltools::htmlEscape
was used
to santize any characters in the name that might be interpreted as HTML.
While it wasn’t necessary for this example (as the restaurant names
contained no HTML markup), doing so is important in any situation where
@@ -162,8 +162,8 @@
You can customize marker labels using the labelOptions
@@ -200,8 +200,8 @@
Again, it’s critical to use basemap tiles that are in the same +
+Again, it’s critical to use basemap tiles that are in the same
projection that is specified in the leafletCRS
function. In
this case the api.geosition.com server does indeed uses EPSG:3006 for
its tiles.
The above example uses the highlightOptions
parameter to
@@ -211,8 +211,8 @@
The addLayersControl
function distinguishes between
+
The addLayersControl
function distinguishes between
base groups, which can only be viewed one group at a time, and
overlay groups, which can be individually checked or
unchecked.
Finally, you can remove the layers in a group using +
+Finally, you can remove the layers in a group using
clearGroup
. Note that this doesn’t just remove the layers
from the group, it also removes them from the map. (It does not,
however, remove the group itself from the map; it still exists, but is
@@ -243,8 +243,8 @@
+ +- - + +library(maps) mapStates = map("state", fill = TRUE, plot = FALSE) leaflet(data = mapStates) %>% addTiles() %>% addPolygons(fillColor = topo.colors(10, alpha = NULL), stroke = FALSE)