@@ -32,11 +32,19 @@ server <- function(input, output, session) {
3232 )
3333 origin_proj <- c(median(lonInEPSG3857 ), median(latInEPSG3857 ))
3434
35+ # Convert lat-lon into ind
36+ latlon2ind <- function (lat , lon ) {
37+ lat_ind <- round(stats :: approx(g $ lat , seq(1 , length(g $ lat )), lat , rule = 2 )$ y )
38+ lon_ind <- round(stats :: approx(g $ lon , seq(1 , length(g $ lon )), lon , rule = 2 )$ y )
39+ ind <- (lon_ind - 1 ) * g $ dim [1 ] + lat_ind
40+ return (ind )
41+ }
3542 session $ onSessionEnded(function () {
3643 stopApp()
3744 })
3845
3946 observe({
47+ # Store current path as path_geopressureviz in global env.
4048 .GlobalEnv $ path_geopressureviz <- reactVal $ path
4149 })
4250
@@ -261,6 +269,7 @@ server <- function(input, output, session) {
261269 }
262270 if (! input $ full_track ) {
263271 reactVal $ path [as.numeric(input $ stap_id ), c(" lon" , " lat" )] <- c(click $ lng , click $ lat )
272+ reactVal $ path [as.numeric(input $ stap_id ), " ind" ] <- latlon2ind(click $ lat , click $ lng )
264273
265274 if (input $ edit_position_interpolate ) {
266275 if (idx() != 1 ) {
@@ -294,11 +303,6 @@ server <- function(input, output, session) {
294303
295304 reactVal $ path [stap_prev_to_next , ] <- path_prev_to_next
296305 }
297-
298- lat_ind <- round(stats :: approx(g $ lat , seq(1 , length(g $ lat )), reactVal $ path $ lat , rule = 2 )$ y )
299- lon_ind <- round(stats :: approx(g $ lon , seq(1 , length(g $ lon )), reactVal $ path $ lon , rule = 2 )$ y )
300-
301- # reactVal$path$ind <- (lon_ind - 1) * g$dim[1] + lat_ind
302306 }
303307 })
304308
@@ -484,6 +488,7 @@ server <- function(input, output, session) {
484488 # update lat lon in case over water
485489 reactVal $ path $ lon [stap_id ] <- pressuretimeseries $ lon [1 ]
486490 reactVal $ path $ lat [stap_id ] <- pressuretimeseries $ lat [1 ]
491+ reactVal $ path $ ind [stap_id ] <- latlon2ind(pressuretimeseries $ lat [1 ], pressuretimeseries $ lon [1 ])
487492
488493 # Merge the two data.frame
489494 if (nrow(reactVal $ pressurepath ) > 0 ) {
0 commit comments