Add Section click detection
This commit is contained in:
@@ -9,9 +9,12 @@ crime_json <- fromJSON(file="data.json")
|
|||||||
|
|
||||||
geo_bezirke <- st_read("geobezirke-parsed.json")
|
geo_bezirke <- st_read("geobezirke-parsed.json")
|
||||||
geo_bezirke <- st_transform(geo_bezirke, crs = 4326)
|
geo_bezirke <- st_transform(geo_bezirke, crs = 4326)
|
||||||
|
geo_bezirke$leaflet_id <- paste("bez_", geo_bezirke$bezirk, sep="")
|
||||||
|
|
||||||
|
|
||||||
geo_stadtteile <- st_read("geostadtteile-parsed.json")
|
geo_stadtteile <- st_read("geostadtteile-parsed.json")
|
||||||
geo_stadtteile <- st_transform(geo_stadtteile, crs = 4326)
|
geo_stadtteile <- st_transform(geo_stadtteile, crs = 4326)
|
||||||
|
geo_stadtteile$leaflet_id <- paste("std_", geo_stadtteile$stadtteil, sep="")
|
||||||
|
|
||||||
bezirke <- names(crime_json)
|
bezirke <- names(crime_json)
|
||||||
|
|
||||||
@@ -35,7 +38,9 @@ ui <- page_fillable(
|
|||||||
)
|
)
|
||||||
),
|
),
|
||||||
leafletOutput("hhmap"),
|
leafletOutput("hhmap"),
|
||||||
card("Card rechts"),
|
card(
|
||||||
|
textOutput("txt_map_selection")
|
||||||
|
),
|
||||||
col_widths = c(3, 6, 3)
|
col_widths = c(3, 6, 3)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@@ -75,11 +80,26 @@ server <- function(input, output, session){
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
observeEvent(input$hhmap_shape_click, {
|
||||||
|
click_event <- input$hhmap_shape_click
|
||||||
|
# Check if an ID was returned (meaning a polygon was clicked)
|
||||||
|
if (!is.null(click_event$id)) {
|
||||||
|
|
||||||
|
# The ID of the clicked polygon
|
||||||
|
clicked_polygon_id <- click_event$id
|
||||||
|
output$txt_map_selection <- renderText({
|
||||||
|
clicked_polygon_id
|
||||||
|
})
|
||||||
|
print(paste("Polygon with ID", clicked_polygon_id, "was clicked."))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
output$hhmap <- renderLeaflet({
|
output$hhmap <- renderLeaflet({
|
||||||
leaflet() %>%
|
leaflet() %>%
|
||||||
addProviderTiles(providers$CartoDB.Positron) %>%
|
addProviderTiles(providers$CartoDB.Positron) %>%
|
||||||
addPolygons(
|
addPolygons(
|
||||||
data = geo_bezirke,
|
data = geo_bezirke,
|
||||||
|
layerId = ~leaflet_id,
|
||||||
group = "layer_bezirke",
|
group = "layer_bezirke",
|
||||||
color = "#7bb5ab",
|
color = "#7bb5ab",
|
||||||
fillColor = "#bdf0e7",
|
fillColor = "#bdf0e7",
|
||||||
@@ -94,6 +114,7 @@ server <- function(input, output, session){
|
|||||||
addPolygons(
|
addPolygons(
|
||||||
data = geo_stadtteile,
|
data = geo_stadtteile,
|
||||||
group = "layer_stadtteile",
|
group = "layer_stadtteile",
|
||||||
|
layerId = ~leaflet_id,
|
||||||
color = "#7bb5ab",
|
color = "#7bb5ab",
|
||||||
fillColor = "#bdf0e7",
|
fillColor = "#bdf0e7",
|
||||||
options = pathOptions(pane = "overlayPane"), # Use a leaflet option to ensure it's hidden
|
options = pathOptions(pane = "overlayPane"), # Use a leaflet option to ensure it's hidden
|
||||||
|
|||||||
Reference in New Issue
Block a user