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

Colour path segments / polygon vertices #177

Closed
1 task
SymbolixAU opened this issue May 3, 2019 · 2 comments
Closed
1 task

Colour path segments / polygon vertices #177

SymbolixAU opened this issue May 3, 2019 · 2 comments
Labels
enhancement New feature or request

Comments

@SymbolixAU
Copy link
Collaborator

SymbolixAU commented May 3, 2019

Some layers can accept a different colour per 'segment' (or vertex for polygon). For example we can have a multi-coloured path (eg ).

(and polygon )

The interleaved example is probably the way to go. (worked on here

mapdeck and/or spatialwidget should support colouring coordinates (or the segments between them

## gives the number of segments for each path
sapply( mapdeck::roads$geometry, function(x) ( length(x) / 2 ) - 1 )

So colouring could

  • default to 1:n_segments colours
  • user-supplied vector, the same length as n_segments, which will have colours applied (will be a list-column on an sf object
  • Z or M component of sf object

Use Cases

  • speeds (congestion) on roads
  • elevation
  • per-road attribute (parking, clearway, region, name, district, council... )

Implementation ideas

currently user specifies a column or a hex string. Need to know if the column is a list, and if so, it's the same length as the number of segments/vertices (or should the colours get recycled?)

If it's a list, spatialwidget will need to return a JSON array of hex strings for the colour.

If it's a list of hex strings, we will assume the list will apply to the segments directly

How do we let the user specify to use the sfc column, and and/or the Z/M attribute?

Maybe we could use a add_segmented_path() function, which will only accept list colours?


TODO

@SymbolixAU SymbolixAU added the enhancement New feature or request label May 3, 2019
@SymbolixAU SymbolixAU self-assigned this May 3, 2019
@mdsumner
Copy link
Contributor

mdsumner commented May 29, 2019

FWIW, recent rgl has a meshColor argument, which controls how input colours are recycled - by 'vertices', 'edges', or 'faces'. (face/edge is the same for lines, triangle/edge is distinct). I guess you'd add 'features' - in rgl feature- grouping is effectively stored indirectly as material properties, it's not reliable).

I'm actually writing up more about this now for mesh3d, but thought it might be worth knowing about if you are considering lower level colours.

@SymbolixAU SymbolixAU mentioned this issue Jun 11, 2019
11 tasks
@SymbolixAU SymbolixAU removed their assignment Jan 16, 2021
@dcooley
Copy link
Collaborator

dcooley commented Jan 2, 2024

Forgot to update this issue :s

This is possible by adding a value to each vertex

df_roads <- sfheaders::sf_to_df(mapdeck::roads, fill = TRUE)

## Add a random value for each coordinate
## These will become our colours at each vertex
df_roads$random <- sample(0:100, size = nrow(df_roads), replace = TRUE)

## rebuild the sf and include the `random` column as a `list`, so the value 
## persists per vertex
sf_roads <- sfheaders::sf_linestring(
	obj = df_roads
	, x = "x"
	, y = "y"
	, linestring_id = "linestring_id"
	, list_columns = "random"
	, keep = TRUE
)

mapdeck() %>%
	add_path(
		data = sf_roads
		, stroke_colour = "random"
		, stroke_width = 10
	)

Screenshot 2024-01-03 at 9 00 43 am

@dcooley dcooley closed this as completed Jan 2, 2024
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