mapboxer
mapboxer copied to clipboard
add_draw_control not functional with shiny bindings (render_mapboxer)
I'm trying to edit polylines in an R shiny framework but invoking add_draw_control using an sfc_linestring as data does not work when called through render_mapboxer, but does work as a standalone in the standard R terminal. What I mean by not working is that the basemap and the scale control will render correctly, but there is no draw control (no lines, no ability to draw).
Thanks for any insight into this!
img is a url to an mbtiles object sf is an sfc_linestring data object
p <- mapboxer(source = mapbox_source(type = "raster",url=img,maxzoom=12,minzoom=8),doubleClickZoom=F,dragRotate=F,center = list(lon = (ranges[3]*.02),lat= ranges[2]/2),zoom=9,maxzoom=12,minzoom=8,clickTolerence=100,dragRotate=F,id="xxx,style= basemap_raster_style(tiles = img,attribution = "")) %>% add_scale_control() %>% add_draw_control(data = sf, boxSelect=F,Draw.modes='draw_line_string',pos = 'top-right')
@kswarts Maybe it is a problem with Shiny that it does not load the javascript file for the draw control correctly, because in this case it is an url as you can see here deps.yaml
@kswarts @crazycapivara It appears to be how the string is concatenated when sourcing the scripts. An extra "/" is added:
When looking at the JS console: "https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-draw/v1.2.0//mapbox-gl-draw.js", if you delete that extra slash the path is correct. I don't know where this is getting added. A workaround is to download the scripts and add to your header:
shiny::tags$head(
shiny::tags$link(rel = 'stylesheet', type = 'text/css', href = 'mapbox-gl-draw.css'),
shiny::tags$script(src='mapbox-gl-draw.js')
)