From 133827c2bd46a7ad6f1a6e6cbc0d9d73c172a1c1 Mon Sep 17 00:00:00 2001 From: lukasadrion Date: Wed, 21 Jan 2026 12:54:03 +0100 Subject: [PATCH] add interactive map with leaflet --- src/app.Rmd | 8 +++----- src/main.Rmd | 34 +++++++++++++++++++++++++--------- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/src/app.Rmd b/src/app.Rmd index 7cf976f..ea0c84f 100644 --- a/src/app.Rmd +++ b/src/app.Rmd @@ -60,7 +60,7 @@ ui <- fluidPage( tabPanel("Single Flight Analysis", fluidRow( - column(6, plotOutput("route_plot", height = "400px")), + column(6, leafletOutput("route_plot", height = "400px")), column(6, plotOutput("altitude_plot", height = "400px")) ), fluidRow( @@ -214,11 +214,9 @@ server <- function(input, output, session) { }) # Route plot - output$route_plot <- renderPlot({ + output$route_plot <- renderLeaflet({ req(rv$current_route) - plot(rv$current_route$lon, rv$current_route$lat, type = "o", pch = 20, col = "blue", - main = paste("Geographic Route of", rv$current_icao), - xlab = "Longitude", ylab = "Latitude") + createInteractiveMap(rv$current_route) }) # Altitude plot diff --git a/src/main.Rmd b/src/main.Rmd index d1dfb3d..56ae614 100644 --- a/src/main.Rmd +++ b/src/main.Rmd @@ -2,8 +2,8 @@ title: "Topic 8 - Flight Trajectory Analysis" subtitle: "Erik Neller, Patrik Mišura, Lukas Adrion" output: - pdf_document: default html_document: default + pdf_document: default date: "`r Sys.Date()`" --- @@ -23,6 +23,7 @@ library(httr) library(jsonlite) library(trajr) library(shiny) +library(leaflet) ``` ```{r opensky, include=FALSE} @@ -208,6 +209,27 @@ calculateStatsSummary <- function(trajectory_stats_df) { ```{r viz-functions, include=FALSE} # Visualization Functions +# Create interactive map with leaflet +createInteractiveMap <- function(route) { + leaflet(route) %>% + addTiles() %>% + addPolylines(lng=~lon, lat=~lat, color="blue", weight=3, opacity=0.8) %>% + addCircleMarkers( + lng = ~lon[1], + lat = ~lat[1], + color = "green", + radius = 6, + popup = "Origin" + ) %>% + addCircleMarkers( + lng = ~lon[nrow(route)], + lat = ~lat[nrow(route)], + color = "red", + radius = 6, + popup = "Destination" + ) +} + # Create boxplots for trajectory statistics createBoxplots <- function(trajectory_stats_df) { p <- getTrajectoryParams() @@ -417,17 +439,11 @@ if (is.null(route_df)) { ## Step 4: Spatial Visualization -The geographic trajectory is visualized in a Cartesian coordinate system. Green and red markers indicate departure and current/final position, respectively. +The geographic trajectory is visualized on an interactive map with leaflet using the `createInteractiveMap()` function. Green and red markers indicate departure and current/final position, respectively. ```{r demo-route-plot, fig.width=7, fig.height=5} if (!is.null(route_df)) { - plot(route_df$lon, route_df$lat, type = "o", pch = 20, col = "blue", - main = paste("Flight Trajectory -", icao), - xlab = "Longitude (°)", ylab = "Latitude (°)") - points(route_df$lon[1], route_df$lat[1], pch = 17, col = "green", cex = 2) - points(route_df$lon[nrow(route_df)], route_df$lat[nrow(route_df)], pch = 15, col = "red", cex = 2) - legend("topright", legend = c("Origin", "Destination", "Trajectory"), - pch = c(17, 15, 20), col = c("green", "red", "blue")) + createInteractiveMap(route_df) } else { cat("Insufficient data for visualization\n") }