Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add offset possibility to Paths (add offset argument to add_path) #300

Closed
3 tasks done
AntonWijbenga opened this issue May 5, 2020 · 6 comments
Closed
3 tasks done
Labels
enhancement New feature or request

Comments

@AntonWijbenga
Copy link

AntonWijbenga commented May 5, 2020

When plotting traffic information on a map, each road has two directions. The road itself is often a single path, but the directions are actually two paths on the same road (with opposite directions). Via Leaflet there is an offset plugin to offset the lines a few pixels (indpendent of zoom level). That enables the two paths on the same road to always be shown in parallel (next to each other). An example of how I used that with Leaflet (using R Shiny) is here:
https://services.maptm.nl/tvdemo/?place=groningen
move the slider on the top left to 1 (instead of 0.5) to show all traffic and not only congested traffic and clearly see the offset at work for the lines/paths shown

The deck.gl solution also has such an offset feature as documented here:
Path Sytle Extension

I believe the dash option of the same extention was implemented last year into Mapdeck:
Dash feature announcement on twitter

Since the offset function is similar to the dash function, I would think it is relatively straightforward to add that as well, but I'm no expert at this.

It would be great if adding the path offset option can be added. I would like to switch to Mapdeck instead of Leaflet because of the performance and the offset option is critical for the application.


TODO

  • document width_* arguments
  • document offset argument
  • NEWS item
@AntonWijbenga AntonWijbenga added the enhancement New feature or request label May 5, 2020
@dcooley
Copy link
Collaborator

dcooley commented May 6, 2020

I've made a prototype on branch issue300. Could you install it and let me know what you think?

remotes::install_github("SymbolixAU/mapdeck", ref = "issue300")

library(sf)

sf <- mapdeck::roads
sf$offset <- sample(-10:10, size = nrow( sf ), replace = TRUE )

set_token( secret::get_secret("mapbox"))

mapdeck(
  style = mapdeck_style("light")
) %>%
  add_path(
    data = sf
    , stroke_colour = "ROAD_NAME"
    , offset = "offset"
  )

Screen Shot 2020-05-06 at 7 49 49 pm

@AntonWijbenga
Copy link
Author

AntonWijbenga commented May 6, 2020

That was fast! … and yes, it works. Great! Thank you very much.
You can see it in the screenshot below.

I really appreciate the quick update and I'm sorry if the part below sounds too greedy....

I noticed that the line width changes when zooming which is unfortunate. On a high level overview the lines are hard to distinguish (and hard to click on for additional info). When you zoom in, it’s OK.
Or… if you set the line width very wide, it is OK when zoomed out, but lines become very thick and sometimes weird in curves.

The example from deck.gl also include withMinPixels and withMaxPixels, or lets you specify the unit of the width in meters or pixels via the withUnits parameter.
I would assume if you set it at pixels, the width is independent of zoom-level, but I can’t easily test that.
Path Layer API
Playing with the example (second screenshot below) when setting withMinPixels and withMaxPixels results in the ideal behaviour of the map (see sliders in the bottom-right).

Having some control over how the width of the line is displayed would be good and probably a good addition to the package as well.

left with offset, right without
image

deck.gl example:
image

SymbolixAU pushed a commit that referenced this issue May 6, 2020
@dcooley
Copy link
Collaborator

dcooley commented May 6, 2020

in 4d85ad2 I've exposed the arguments

  • width_units
  • width_scale
  • width_min_pixels
  • width_max_pixels

Can you reinstall branch issue300 and let me know if they work as intended?

@AntonWijbenga
Copy link
Author

They work perfectly! Thank you.

In my experience you get the slickest result when using a min and max in pixels.

Then, when zooming in the lines become a bit thicker, which feels natural (roads / streets etc. also become wider when zooming in). When zooming out, they become thinner just as the roads.
Also, when zoomed in, there are less lines in view, so it's ok if they are thicker / take up more space. The zoomed out view with thinner lines gives a much cleaner look, than when they remain as thick as when zoomed in.

Thank you again for the quick responses.

@dcooley
Copy link
Collaborator

dcooley commented May 7, 2020

I'm going to leave this open until I merge it into master - I still need to update the docs.

@dcooley dcooley reopened this May 7, 2020
@AntonWijbenga
Copy link
Author

Of course.
I noticed a small typo in the R-help. In the explanation of 'offset' it says 'offest' with the e and s reversed.

@SymbolixAU SymbolixAU removed their assignment Jan 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants