Commit b9d6c8d0 by Jan Wijffels

Use the S4 classes in the app

parent 6359503b
......@@ -26,21 +26,12 @@ library(sp)
data("BE_ADMIN_REGION")
dashinput <- list()
dashinput$user_file <- system.file(package = "citizenair", "data-raw", "test_dummy.xls")
dashinput$stationinfo <- content(GET("http://geo.irceline.be/sos/api/v1/stations?expanded=true"))
dashinput$meetstations <- lapply(dashinput$stationinfo, FUN=function(x){
data.frame(id = x$properties$id,
label = x$properties$label,
phenomena = sort(unique(sapply(x$properties$timeseries, FUN=function(x) x$phenomenon$label))), stringsAsFactors = FALSE)
})
dashinput$meetstations <- rbindlist(dashinput$meetstations)
dashinput$region <- subset(BE_ADMIN_REGION, TX_RGN_DESCR_NL %in% "Vlaams Gewest")
dashinput$endpoint <- as.Endpoint("http://sosrest.irceline.be/api/v1")
dashinput$endpoint <- as.Endpoint("http://geo.irceline.be/sos/api/v1")
dashinput$srv <- fetch(services(dashinput$endpoint))
dashinput$stations <- stations(dashinput$endpoint, service = dashinput$srv)
dashinput$stations_sp <- as.SpatialPointsDataFrame(dashinput$stations)
dashinput$stations_sp <- dashinput$stations_sp[sapply(1:nrow(dashinput$stations_sp), FUN=function(idx) gIntersects(dashinput$region, dashinput$stations_sp[idx, ])), ]
dashinput$ca <- new("CitizenAir", endpoint = dashinput$endpoint)
dashinput$region <- subset(BE_ADMIN_REGION, TX_RGN_DESCR_NL %in% "Vlaams Gewest")
dashinput$stations_sp <- as_sp(dashinput$ca@stations)
dashinput$stations_sp <- dashinput$stations_sp[sapply(1:nrow(dashinput$stations_sp),
FUN=function(idx) gIntersects(dashinput$region, dashinput$stations_sp[idx, ])), ]
```
......
......@@ -89,7 +89,11 @@ output$uiOutput_stations <- renderLeaflet({
map <- leaflet(data = dashinput$region)
map <- addTiles(map)
map <- addPolygons(map, weight = 3, fillOpacity = 0)
map <- addCircleMarkers(map = map, data = stations, radius = 5, opacity = 0.3, fillOpacity = 1, weight = 3, popup = as.character(stations$label))
map <- addCircleMarkers(map = map, data = stations, radius = 5, opacity = 0.3, fillOpacity = 1, weight = 3,
popup = as.character(mapply(label = stations$label, phenomena = stations$phenomena_label,
FUN=function(label, phenomena){
sprintf("<b>Station: %s</b> <br>Meetwaardes:<br> %s", label, paste(sprintf(" - %s ", phenomena), collapse = "<br>"))
})))
if(length(userdata$nearest_station) > 0){
stations <- subset(stations, id %in% userdata$nearest_station)
map <- addPopups(map, data = stations, popup = "Dichtstbijzijnd gevalideerd meetstation")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment