SymbolixAU / googleway

R Package for accessing and plotting Google Maps
http://symbolixau.github.io/googleway/
Other
234 stars 46 forks source link

add_markers cluster size #224

Closed zeehasham closed 4 years ago

zeehasham commented 4 years ago

Hi, Is it possible to pass minimum size of points in cluster as a parameter to add_markers function when cluster=TRUE? There are two benefits

  1. We will get rid of small cluster sizes.
  2. What I found is if you have two points with the same latitude/longitude then cluster will never show you pins and remains in the cluster form even with maximum zoom. Thanks, Zee
dcooley commented 4 years ago

Thanks for the suggestion @zeehasham . Yes I think this is possible given it's one of the available options.

I've made a branch where I've had a go at starting this. Would you mind testing it for me and seeing if it does what you're expecting.

remotes::install_github("SymbolixAU/googleway", ref = "issue224")

Example

library(googleway)
library(sf)                
library(sfheaders)  ## for converting LINESTRINGS to POINTS
library(mapdeck)   ## using the 'roads' data

set_key( secret::get_secret("googleway") )

sf <- mapdeck::roads
sf_pts <- sfheaders::sf_cast( sf, "POINT") 

sf_pts <- sf_pts[1:100, ]

The default clustering

google_map() %>%
  add_markers(
    data = sf_pts
    , cluster = T
  )

Screen Shot 2020-08-06 at 8 35 31 am

And using min_cluster_size = 5

google_map() %>%
  add_markers(
    data = sf_pts
    , cluster = T
    , cluster_options = list(minimumClusterSize = 5)
  )

Screen Shot 2020-08-06 at 8 44 18 am

zeehasham commented 4 years ago

@dcooley Thanks Dave for the prompt response. I tested it and confirm that this works exactly as was required. Let me know when this features becomes a part of release.

dcooley commented 4 years ago

I've added all the options, updated the docs for ?add_markers and merged into master branch.

I'm not sure when I'll have an update on CRAN though. Could be a few weeks.