Skip to content

Commit

Permalink
tidying
Browse files Browse the repository at this point in the history
  • Loading branch information
SymbolixAU committed Jan 28, 2018
1 parent 3043991 commit ef631f8
Show file tree
Hide file tree
Showing 9 changed files with 11 additions and 255 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## Version 2.3.0 (development)

* `update_heatmap` accepts `option_` arguments
* `update_heatmap` gets `update_map_view` argument
* `sf` objects supported
* Vignette updated to include all api calls and map layers
Expand Down
3 changes: 2 additions & 1 deletion R/google_map_layer_geojson.R
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,15 @@ clear_geojson <- function(map, layer_id = NULL){
#' google_map(key = map_key) %>%
#' add_geojson(data = geo_melbourne) %>%
#' update_geojson(style = lst_style)
#' }
#'
#' ## Styling a specific feature
#' style <- '{"property" : "SA2_NAME", "value" : "Abbotsford", "features" : { "fillColor" : "red" } }'
#' google_map(key = map_key) %>%
#' add_geojson(data = geo_melbourne) %>%
#' update_geojson(style = style)
#'
#' }
#'
#' @export
update_geojson <- function(map, layer_id = NULL, style){

Expand Down
8 changes: 0 additions & 8 deletions R/google_map_layer_heatmap.R
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,6 @@ update_heatmap <- function(map,
legend = F,
legend_options = NULL){

## TODO: update_map_view options

objArgs <- match.call(expand.dots = F)
if(!dataCheck(data, "update_heatmap")) data <- heatmapDefaults(1)
layer_id <- layerId(layer_id)
Expand All @@ -235,7 +233,6 @@ update_heatmap <- function(map,
radius = option_radius,
opacity = option_opacity)

## TODO: should this be the same as the add_heatmap function??
if(!is.null(option_gradient)){

if(length(option_gradient) == 1)
Expand All @@ -253,11 +250,6 @@ update_heatmap <- function(map,
rampColours <- option_gradient[2:length(option_gradient)]
heatmap_options$gradient <- list(g)

## TODO: this is what it used to be. Need to test the new code is correct
## by making a shiny and ensurin gall the update features work as expected.
## Also need to note / document how to use the 'update' features of heatmaps
## as they are different to the other 'udpate_' functions
#rampColours <- option_gradient[2:length(option_gradient)]
}else{
rampColours <- c("green", "red")
}
Expand Down
3 changes: 2 additions & 1 deletion R/google_map_layer_parameters.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#
# checks the data is the correct type(s)
# @param data the data passed into the map layer funciton
# @param callingFunc the function calling the data check
dataCheck <- function(data, callingFunc){

if(is.null(data)){
Expand All @@ -10,7 +11,7 @@ dataCheck <- function(data, callingFunc){
}

if(!inherits(data, "data.frame")){
warning(paste0(callingFunc, ": currently only data.frames are supported"))
warning(paste0(callingFunc, ": currently only data.frames, sf and sfencoded objects are supported"))
return(FALSE)
}

Expand Down
4 changes: 0 additions & 4 deletions R/google_map_layer_polygon.R
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,7 @@ add_polygons <- function(map,
legend_options = NULL,
load_interval = 0){

## TODO:
## - holes must be wound in the opposite direction?

objArgs <- match.call(expand.dots = F)
# callingFunc <- as.character(objArgs[[1]])

data <- normaliseSfData(data, "POLYGON")
polyline <- findEncodedColumn(data, polyline)
Expand Down
1 change: 0 additions & 1 deletion R/googleway-package.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

## TODO:
## - dataCheck() - change message as now more than data.frames are supported
## - plot bbox as rectangle (if requested?)

#' @useDynLib googleway
Expand Down
6 changes: 3 additions & 3 deletions R/legend.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ formatPalette <- function(palette, type){
if(type == "gradient"){

## TODO:
## - better representation of the min & max values on teh legend
## - better representation of the min & max values on the legend
## - options:
## -- show the min & max at teh extremeties of the legend
## -- show the min & max at the extremeties of the legend
## -- have an option to 'turn off maximum/minimum values
## -- which will then remove the maximua, and instead use < and + as a
## -- which will then remove the maxima, and instead use < and + as a
## -- prefix and suffix to the min/max values

# rows <- 1:32434
Expand Down
237 changes: 1 addition & 236 deletions R/scratch.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,241 +2,6 @@

## TODO:
## TESTS
## - polylines - works with and withotu ID, for polyline and lat/lon columns
## - polylines - works with and without ID, for polyline and lat/lon columns
## - polygons - ditto






### geoJSON

# geojson_txt <- '{
# "type" : "Feature",
# "properties" : {
# "id" : 1,
# "color" : "green",
# "strokeColor" : "blue"
# },
# "geometry" : {
# "type" : "Polygon", "coordinates" : [
# [
# [144.88, -37.85],
# [145.02, -37.85],
# [145.02, -37.80],
# [144.88, -37.80],
# [144.88, -37.85]
# ]
# ]
# }
# }'
#
# geojson_txt2 <- '{
# "type" : "FeatureCollection",
# "features" : [
# {
# "type" : "Feature",
# "properties" : {
# "id" : 1,
# "fillColor" : "red",
# "strokeColor" : "green",
# "strokeWeight" : 1
# },
# "geometry" : {
# "type" : "Polygon", "coordinates" : [
# [
# [144.80, -37.85],
# [144.88, -37.85],
# [144.88, -37.80],
# [144.80, -37.80],
# [144.80, -37.85]
# ]
# ]
# }
# }
# ]
# }'
#
# mapKey <- read.dcf("~/Documents/.googleAPI", fields = "GOOGLE_MAP_KEY")
#
#
# style <- '{ "property" : "id", "value" : 1, "features" : { "fillColor" : "white" } }'
#
#
# google_map(key = mapKey) %>%
# add_geojson(geojson = geojson_txt, layer_id = "hi") %>%
# add_geojson(geojson = geojson_txt2, layer_id = "world") %>%
# update_geojson(style = style, layer_id = "world")

### style object
# style <- ' { "fillColor" : "red" } '
#
### style specifies the node of the geoJSON

# style <- '{ "fillColor" : "yellow" }'
# google_map(key = mapKey) %>%
# add_geojson(geojson = geojson_txt, style = style)









# library(sf)
# library(geojsonio)
#
# nc <- st_read(system.file("shape/nc.shp", package="sf"))
#
# nc$fillColor <- "red"
# nc$strokeWeight <- 0.1
#
# geo_nc <- geojson_json(nc)
#
# mapKey <- read.dcf("~/Documents/.googleAPI", fields = "GOOGLE_MAP_KEY")
#
# google_map(key = mapKey, location = c(34.2, -80), zoom = 6) %>%
# add_geojson(geo_nc)
# #
#
# style <- '{ "fillColor" : "green" , "strokeColor" : "blue"}'
#
# google_map(key = mapKey) %>%
# add_geojson(geo_nc, style = style)
#
#
# style <- '{
# "property" : "AREA",
# "value" : 0.1263,
# "operator" : "<=",
# "features" : {
# "fillColor" : "blue"
# }
# }'
#
#
# google_map(key = mapKey) %>%
# add_geojson(geo_nc) %>%
# update_geojson(style = style)

# google_map(key = mapKey) %>%
# add_polygons(data = melbourne, polyline = "polyline",
# fill_colour = "SA2_NAME", fill_opacity = 0.9)

#
#
#
# library(ggplot2)
#
#
# unemp <- read.csv("http://datasets.flowingdata.com/unemployment09.csv",
# header = FALSE, stringsAsFactors = FALSE)
# names(unemp) <- c("id", "state_fips", "county_fips", "name", "year",
# "?", "?", "?", "rate")
# unemp$county <- tolower(gsub(" County, [A-Z]{2}", "", unemp$name))
# unemp$county <- gsub("^(.*) parish, ..$","\\1", unemp$county)
# unemp$state <- gsub("^.*([A-Z]{2}).*$", "\\1", unemp$name)
#
# county_df <- map_data("county", parameters = c(39, 45))
#
# names(county_df) <- c("long", "lat", "group", "order", "state_name", "county")
# county_df$state <- state.abb[match(county_df$state_name, tolower(state.name))]
# county_df$state_name <- NULL
#
# state_df <- map_data("state", parameters = c(39, 45))
#
# choropleth <- merge(county_df, unemp, by = c("state", "county"))
# choropleth <- choropleth[order(choropleth$order), ]
#
# google_map(key = mapKey) %>%
# add_polygons(data = choropleth, lat = "lat",
# lon = "long", id = "id", pathId = "group",
# fill_colour = "rate")
#
#
# library(data.table)
#
# setDT(choropleth)
#
# dt <- choropleth[, .(polyline = encode_pl(lat, long)), by = .(state, county, group, id, rate)]
#
# google_map(key = mapKey) %>%
# add_polygons(data = dt, polyline = "polyline",
# id = "id", pathId = "group",
# fill_colour = "rate", stroke_weight = 0.1, palette = viridisLite::magma)





# library(geojsonio)
# library(sf)
# library(spatialdatatable)
# library(symbolix.utils)
# library(googleway)
#
# # usCounties <- geojson_read("http://eric.clst.org/wupl/Stuff/gz_2010_us_050_00_500k.json")
#
# # sfCounties <- st_read("http://eric.clst.org/wupl/Stuff/gz_2010_us_050_00_500k.json")
# #
# ## US census shapes
# ## https://www.census.gov/geo/maps-data/data/cbf/cbf_counties.html
# sf <- st_read("~/Downloads/cb_2016_us_county_500k/")
#
# sdtCounties <- EncodeSF(sf)
# sdtCounties
#
# mapKey <- read.dcf("~/Documents/.googleAPI", fields = "GOOGLE_MAP_KEY")
#
# google_map(key = mapKey) %>%
# add_polygons(data = sdtCounties, polyline = "polyline", id = ".id",
# fill_opacity = 0.8, stroke_weight = 0.3,
# stroke_colour = "#FFFFFF", fill_colour = "COUNTYFP")
#
# library(tidycensus)
#
# dt_fips <- fips_codes
# setDT(dt_fips)
#
#
#
#
# sdtCounties[, `:=`(COUNTYFP = as.numeric(COUNTYFP),
# STATEFP = as.numeric(STATEFP))]
#
# sdtCounties[, `:=`(NAME = tolower(as.character(iconv(NAME))))]
#
# google_map(key = mapKey) %>%
# add_polygons(data = sdtCounties[STATEFP == 7], polyline = "polyline")
#
#
# sdt <- sdtCounties[
# unique(unemp[, .(state_fips, county_fips, rate)])
# , on = c(COUNTY = "county_fips", STATE = "state_fips")
# , nomatch = 0
# ]
#
# google_map(key = mapKey()) %>%
# add_polygons(data = sdt, polyline = "polyline", fill_opacity = 0.8,
# stroke_weight = 0.3, stroke_colour = "#FFFFFF", fill_colour = "rate")
#


# library(shiny)
# ui <- fluidPage(
# google_mapOutput('map')
# )
# server <- function(input, output){
# output$map <- renderGoogle_map({
# google_map(key = mapKey, event_return_type = "json") %>%
# add_polygons(data = melbourne, polyline = "polyline")
# })
# observeEvent(input$map_polygon_click, {
# print(input$map_polygon_click)
# })
# }
# shinyApp(ui, server)

3 changes: 2 additions & 1 deletion man/update_geojson.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ef631f8

Please sign in to comment.