qfes / rdeck

Deck.gl widget for R
https://qfes.github.io/rdeck
MIT License
97 stars 0 forks source link

Can't see stroked outlines on polygon layers #91

Closed MikeLydeamore closed 1 year ago

MikeLydeamore commented 1 year ago

I'm trying to add a flat polygon layer, with a stroke on the outside. I can get a thin line by setting stroked = TRUE and extruded=TRUE, but I haven't managed to get a thick line, and the outline isn't really visible enough.

I have tried setting get_line_width to a large number, but it seems to have no effect.

Here is a short example showing the unexpected behaviour

library(rdeck)
library(dplyr)
library(sf)
library(absmapsdata)

shp <- sa32016 %>%
  filter(gcc_name_2016 == "Greater Melbourne")

rdeck(
  map_style = mapbox_dark(),
  # set the bounds of the map to include all of the manhattan data
  initial_bounds = st_bbox(shp),
  # add a 2 pixel buffer to each point, making it easier to hover
  picking_radius = 2
) |>
  add_polygon_layer(
    data = shp,
    get_polygon = geometry,
    filled = TRUE,
    opacity = 0.1,
    stroked = TRUE,
    get_line_color = "#663399ff"
  )
anthonynorth commented 1 year ago

The problem is that line_width_units defaults to "meters", so your lines 1m wide. This a bad default in my opinion.

Try this

library(rdeck)
library(dplyr)
library(sf)
library(absmapsdata)

shp <- sa32016 %>%
  filter(gcc_name_2016 == "Greater Melbourne")

rdeck(
  map_style = mapbox_dark(),
  # set the bounds of the map to include all of the manhattan data
  initial_bounds = st_bbox(shp),
  # add a 2 pixel buffer to each point, making it easier to hover
  picking_radius = 2
) |>
  add_polygon_layer(
    data = shp,
    get_polygon = geometry,
    filled = TRUE,
    opacity = 0.1,
    stroked = TRUE,
    get_line_color = "#663399ff",
    line_width_units = "pixels",
  )

melb

anthonynorth commented 1 year ago

Related #92

MikeLydeamore commented 1 year ago

Interesting, when I run that script I don't get any outlines at all:

image

> version
               _                           
platform       aarch64-apple-darwin20      
arch           aarch64                     
os             darwin20                    
system         aarch64, darwin20           
status                                     
major          4                           
minor          1.2                         
year           2021                        
month          11                          
day            01                          
svn rev        81115                       
language       R                           
version.string R version 4.1.2 (2021-11-01)
nickname       Bird Hippie              

I also have a broken display in the RStudio Viewer, so I'm looking in the webpage. Not sure if that's connected or not, or perhaps it is an R version issue?

MikeLydeamore commented 1 year ago

Oh never mind, this is solved with a line_width_min_pixels argument, so I guess it is related to a default zoom level or something like that.

I'll consider this one closed.

anthonynorth commented 1 year ago

The above (https://github.com/qfes/rdeck/issues/91#issuecomment-1447564187) should have just worked as is, because the default get_line_width = 1. line_width_min_pixels = 1 also works in this case, since you'll (likely) not get > 1 pixel for 1m lines.

anthonynorth commented 1 year ago

I also have a broken display in the RStudio Viewer, so I'm looking in the webpage. Not sure if that's connected or not, or perhaps it is an R version issue?

If you're using a QtWebEngine version RStudio, rdeck probably won't render in the viewer. I removed legacy browser support (QtWebEngine-RStudio viewer was locked to Chrome 69) from rdeck in v0.5.1.

Rdeck renders in the Electron-RStudio viewer. I've just run the above script on the latest RStudio release for windows: image