Skip to content

Commit

Permalink
Improve map_stations.
Browse files Browse the repository at this point in the history
  • Loading branch information
ConorIA committed Jun 26, 2017
1 parent dd707e2 commit 5e0a3cc
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Imports:
dplyr,
geosphere,
leaflet,
magrittr,
readr,
RMySQL,
shiny,
Expand Down
5 changes: 3 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ importFrom(curl,curl_download)
importFrom(dplyr,filter)
importFrom(dplyr,select)
importFrom(geosphere,distGeo)
importFrom(leaflet,"%>%")
importFrom(leaflet,addMarkers)
importFrom(leaflet,addAwesomeMarkers)
importFrom(leaflet,addTiles)
importFrom(leaflet,awesomeIcons)
importFrom(leaflet,leaflet)
importFrom(leaflet,setView)
importFrom(magrittr,"%>%")
importFrom(readr,read_csv)
importFrom(readr,write_csv)
importFrom(shiny,br)
Expand Down
36 changes: 31 additions & 5 deletions R/map_stations.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
##' @param station character; one or more station id numbers to show on the map.
##' @param zoom numeric; the level to zoom the map to.
##'
##' @importFrom leaflet "%>%" leaflet addTiles setView addMarkers
##' @importFrom leaflet addAwesomeMarkers addTiles awesomeIcons leaflet setView
##' @importFrom magrittr %>%
##'
##' @export
##'
Expand Down Expand Up @@ -53,8 +54,33 @@ map_stations <- function(station, zoom) {
} else zoom = 10
}

leaflet() %>% addTiles() %>%
defIcons <-function(dat) {
sapply(dat$Configuration, function(Configuration) {
if(Configuration %in% c("M", "M1", "M2")) {
"thermometer"
} else {
"waterdrop"
} })
}

defColours <-function(dat) {
sapply(dat$Configuration, function(Configuration) {
if(Configuration %in% c("M", "M1", "M2")) {
"orange"
} else {
"blue"
} })
}

icons <- awesomeIcons(
icon = defIcons(poi),
iconColor = 'black',
library = 'ion',
markerColor = defColours(poi)
)

leaflet(poi) %>% addTiles() %>%
setView(lng = lons, lat = lats, zoom = zoom) %>%
addMarkers(poi$Station, lng = poi$Longitude, lat = poi$Latitude,
popup = paste0(poi$StationID, " - ", poi$Station, " (", poi$Configuration, ")"))
}
addAwesomeMarkers(~Longitude, ~Latitude, icon = icons,
label = paste0(poi$StationID, " - ", poi$Station, " (", poi$Configuration, ")"))
}

0 comments on commit 5e0a3cc

Please sign in to comment.