-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshow_locations.R
84 lines (76 loc) · 3.31 KB
/
show_locations.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
show_locations_UI <- function(id, settings=NULL){
ns <- NS(id)
list(
div(class="flex-container",
div(class="flex-sidebar",
p("Standorte"),
actionButton(ns("show_my_locations"), "Meine Standorte anzeigen"),
actionButton(ns("show_all_locations"), "Alle Standorte anzeigen")
),
div(class="flex-main-panel",
maplibreOutput(ns("map"), height = "100%")
)
)
)
}
show_locations_server <- function(id, userID){
moduleServer(id, function(input, output, session){
ns = session$ns
output$map <- renderMaplibre({
maplibre("./neutrino.de.json",
center=c(14.324609,51.759617), zoom=12, maxzoom=19, minzoom=12,
) %>%
add_navigation_control() %>%
add_fullscreen_control() %>%
add_geocoder_control(collapsed = T) %>%
add_line_layer(id = "streets", source = splitted_streets, before_id = "label-street-pedestrian", line_opacity = 1, line_width = interpolate(property = "zoom", type = list("exponential", 2), values = c(12,19), stops = c(1,60)), line_color = match_expr(
"maxspeed",
values = c("30", "50", "60", "100"),
stops = c("#1f78b4", "#33a02c","#e31a1c", "#ff7f00"),
default = "gray"
)
#popup = c("name", "maxspeed"),
#tooltip = "name", hover_options = list(line_width=4)
) %>%
add_legend(position="bottom-left", legend_title = "max speed", type="categorical",
values = c("30", "50", "60", "100"),
colors = c("#1f78b4", "#33a02c", "#e31a1c", "#ff7f00")) %>%
add_layers_control(layers=list("streets", "Luftbild"), collapsible = TRUE)
})
locations <- reactiveVal()
observeEvent(input$show_my_locations, {
count_query = str_glue("SELECT count(id) FROM sensor_locations WHERE username = '{userID()}';")
query=str_glue("SELECT id, username, date_created, street_name, 'street_name.hsb', user_speedlimit, osm_speedlimit, direction, oneway, lanes, location_geom FROM sensor_locations WHERE username = \'{userID()}\';")
count <- dbGetQuery(content, count_query)
if(count>0){
locations <- pgGetGeom(content, query=query, geom="location_geom")
locations(locations)
maplibre_proxy("map", session) %>%
clear_markers() %>%
add_markers(marker_id = "id", data=locations, popup = "street_name")
}else{
locations()
maplibre_proxy("map", session) %>%
clear_markers()
showNotification("Keine Standorte vorhanden")
}
})
observeEvent(input$show_all_locations, {
count_query = "SELECT count(id) FROM sensor_locations;"
query="SELECT id, username, date_created, street_name, 'street_name.hsb', user_speedlimit, osm_speedlimit, direction, oneway, lanes, location_geom FROM sensor_locations;"
count <- dbGetQuery(content, count_query)
if(count>0){
locations <- pgGetGeom(content, query=query, geom="location_geom")
locations(locations)
maplibre_proxy("map", session) %>%
clear_markers() %>%
add_markers(marker_id = "id", data=locations, popup = "street_name")
}else{
locations()
maplibre_proxy("map", session) %>%
clear_markers()
showNotification("Keine Standorte vorhanden")
}
})
})
}