-
Notifications
You must be signed in to change notification settings - Fork 506
/
easyButton.R
61 lines (58 loc) · 1.96 KB
/
easyButton.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
library(leaflet)
#' Add two easy buttons.
#' first to set zoom level to 1,
#' second to find your self
leaflet() %>% addTiles() %>%
addEasyButton(easyButton(
icon = "fa-globe", title = "Zoom to Level 1",
onClick = JS("function(btn, map){ map.setZoom(1);}"))) %>%
addEasyButton(easyButton(
icon = "fa-crosshairs", title = "Locate Me",
onClick = JS("function(btn, map){ map.locate({setView: true});}")))
#' <br/><br/>Toggle Button to freeze/unfreeze clustering at a zoom level.
leaflet() %>% addTiles() %>%
addMarkers(data = quakes,
clusterOptions = markerClusterOptions(),
clusterId = "quakesCluster") %>%
addEasyButton(easyButton(
states = list(
easyButtonState(
stateName = "unfrozen-markers",
icon = "ion-toggle",
title = "Freeze Clusters",
onClick = JS("
function(btn, map) {
var clusterManager =
map.layerManager.getLayer('cluster',
'quakesCluster');
clusterManager.freezeAtZoom();
btn.state('frozen-markers');
}")
),
easyButtonState(
stateName = "frozen-markers",
icon = "ion-toggle-filled",
title = "UnFreeze Clusters",
onClick = JS("
function(btn, map) {
var clusterManager =
map.layerManager.getLayer('cluster',
'quakesCluster');
clusterManager.unfreeze();
btn.state('unfrozen-markers');
}")
)
)
))
#' <br/><br/>Add two easy buttons in a bar
#' first to set zoom level to 1
#' second to find your self
leaflet() %>% addTiles() %>%
addEasyButtonBar(
easyButton(
icon = "fa-globe", title = "Zoom to Level 1",
onClick = JS("function(btn, map){ map.setZoom(1);}")),
easyButton(
icon = "fa-crosshairs", title = "Locate Me",
onClick = JS("function(btn, map){ map.locate({setView: true});}"))
)