forked from petrpajdla/map_oao
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathleaflet_czechrep.R
64 lines (59 loc) · 2.17 KB
/
leaflet_czechrep.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
62
63
64
#' Leaflet map, Czech Republic extent
#'
#' Creates leaflet object with extent and zoom set to the Czech Republic.
#' Tiles include CartoDB Pozitron map, basic OSM and CUZK ZM.
#'
#' @param data Data passed to leaflet.
#'
#' @return Leaflet object.
#' @export
#'
#' @examples
leaflet_czechrep <- function(data) {
data %>% leaflet::leaflet(
options = leaflet::leafletOptions(minZoom = 7, maxZoom = 16)) %>%
leaflet::setView(zoom = 7, lng = 15.4730, lat = 49.8175) %>%
leaflet::setMaxBounds(11, 48, 20, 52) %>%
leaflet::addTiles(group = "Open Street Map") %>%
leaflet::addProviderTiles(
leaflet::providers$CartoDB.Positron,
group = "Desaturovaná mapa") %>%
leaflet::addTiles(
urlTemplate = paste0("https://ags.cuzk.cz/arcgis1/rest/services/ZTM_WM/",
#"http://ags.cuzk.cz/arcgis/rest/services/zmwm/",
"MapServer/tile/{z}/{y}/{x}?blankTile=false"),
attribution = paste0("Základní Mapy ČR ©",
"<a href='https://www.cuzk.cz/' target = '_blank'>ČÚZK</a>"),
group = "Základní mapy ČR") %>%
leaflet::addLayersControl(
baseGroups = c(
"Desaturovaná mapa",
"Open Street Map",
"Základní mapy ČR"),
options = leaflet::layersControlOptions(position = "bottomleft"))
}
leaflet_czechrep_add_marker <- function(click, url) {
leaflet::leafletProxy("clickmap") %>%
leaflet::clearMarkers() %>%
leaflet::addCircleMarkers(
layerId = "poi", click$lng, click$lat,
color = "#3E3F3A", radius = 16,
stroke = TRUE, fillOpacity = 0.6,
# popup = paste0(
# tags$b("Zvolený bod"), tags$br(),
# tags$a(
# href = paste0(client_url(), "?lat=", click$lat, "&lng=", click$lng),
# click$lat, "N ", click$lng, "E"))
)
}
click2sf <- function(click) {
sf::st_as_sf(data.frame(click),
coords = c("lng", "lat"),
crs = 4326)
}
leaflet_zoom <- function(ku, centroids) {
coords <- centroids[centroids$ku == ku, ] %>%
st_coordinates()
leaflet::leafletProxy("clickmap") %>%
leaflet::setView(zoom = 14, lng = coords[1], lat = coords[2])
}