Open sm2607 opened 2 years ago
can you give me the code you're using please?
geo <- sf_geojson(sf_data) style <- list(fillColor = 'color',fillOpacity=0.4, strokeColor = "blue", strokeWeight = 0) map1<-map1 %>% add_geojson(data = geo, style = style, mouse_over=T)
Can you make it reproducible please, so I can copy it into my own R session and reproduce what you're doing?
As in this example, if we need to add label to each polygon/shape , eg. as we hover over shape it shows "area" and "name" of that shape
library(googleway) style <- list(fillColor = "red" , strokeColor = "blue", strokeWeight = 0.5) google_map(key = api_key) %>% add_geojson(data = geo_melbourne, style = style)
The only way this is possible is to convert the geojosn to an sf
object and use the add_polygons()
sf <- geojsonsf::geojson_sf(geo_melbourne)
google_map(key = secret::get_secret("GOOGLE")) %>%
add_polygons(data = sf, mouse_over = "SA2_NAME")
Firstly I tried with "add_polygon" function, but my shapefile has almost ~300 circles, and "add_polygon" function is not able to load shapefile even after ~30 minutes, So, as a workaround I was trying geojson
hi, I tried both (example from article and in comment), but layer is not loading in my case. Can you please suggest what is missing here.
library(mapdeck) library(googleway) set_key(api_key)
googleway::google_map() %>% mapdeck::add_dependencies() %>% mapdeck::add_path( data = roads , stroke_colour = "ROAD_TYPE" , legend = T )
could you try openeing it in a browser?
I tried below example code,
library(shiny)
library(shinydashboard)
library(mapdeck)
library(googleway)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(
mapdeck::mapdeck_dependencies()
, box(
width = 12
, google_mapOutput(
outputId = "map"
, height = "600"
)
)
)
)
server <- function(input, output) {
output$map <- renderGoogle_map({
sf <- geojsonsf::geojson_sf(geo_melbourne)
google_map() %>%
mapdeck::add_dependencies() %>%
mapdeck::add_polygon(data = sf,stroke_width = 5,stroke_colour = 'black', tooltip = "SA2_NAME")
})
}
shinyApp(ui, server)
In browser, able to see shapefile but tooltip, stroke_width etc. features are not working
stroke_colour
is expecting either a value / column from sf
, or a hex String:
output$map <- renderGoogle_map({
sf <- geojsonsf::geojson_sf(geo_melbourne)
google_map() %>%
mapdeck::add_dependencies() %>%
mapdeck::add_polygon(data = sf,stroke_width = 5,stroke_colour = '#000000', tooltip = "SA2_NAME")
})
For me the tooltip is working:
Do you get any errors in the javascript console? (In Chrome press Ctrl / Cmd + Shift + C, and go to the 'console' tab)?
Next thing to try is to install the github / dev versions:
remotes::install_github("SymbolixAU/googleway")
remotes::install_github("dcooley/geometries")
remotes::install_github("dcooley/sfheaders")
remotes::install_github("SymbolixAU/spatialwidget")
remotes::install_github("SymbolixAU/mapdeck")
yes I got below console error:-
That's not an error I recognise.
I can see the stroke_colour
is working. Are you certain the tooltip is not? Do you get an error in the console when you over the mouse over a polygon?
It was not working earlier but than I installed all below packages from github and update their dependent packages after removing their previous version, now its working. thankyou so much for your support. But its still slow with my data compared to googlway add_geojson and leaflet addPolygon function
remotes::install_github("SymbolixAU/googleway")
remotes::install_github("dcooley/geometries")
remotes::install_github("dcooley/sfheaders")
remotes::install_github("SymbolixAU/spatialwidget")
remotes::install_github("SymbolixAU/mapdeck")
Also, is there any feature available in any googleway or mapdeck package similar to leaflet function GroupLayer/ControlGroupLayer? or any workaround for this?
Also, is there any feature available in any googleway or mapdeck package similar to leaflet function GroupLayer/ControlGroupLayer? or any workaround for this?
There is no such featuer in googleway or mapdeck. The work-around is to to use a radiobutton / checkboxgroup in shiny to toggle layers on / off.
Hi, I was trying to add label to geojson, similar to polygon with attribute, mouse_over, but it through an error that its only accept TRUE/FALSE, can you please suggest how to add label to geojson feature.