Skip to content

Add per-vertex multicolor polylines for geospatial data visualization - #2279

Draft
richyo-codes wants to merge 3 commits into
fleaflet:masterfrom
richyo-codes:multicolorpolyline-pr-261010
Draft

richyo-codes wants to merge 3 commits into
fleaflet:masterfrom
richyo-codes:multicolorpolyline-pr-261010

Conversation

@richyo-codes

Copy link
Copy Markdown

Summary

Adds MulticolorPolyline, enabling polylines to render different colors along their path, with smooth interpolation between colors assigned to individual vertices.

Unlike existing Polyline.gradientColors, this allows colors to represent measurements associated with individual geographic coordinates rather than applying a gradient across the overall line.

Motivation and use cases

Many mapping applications associate measurements or other metadata with geographic coordinates. Visualizing these values directly along a route or path can provide useful context without requiring additional markers or overlays.

Potential applications include:

  • Traffic and transportation: Visualize vehicle speeds, congestion, or delays along roads and journeys.
  • Elevation and terrain: Show elevation, slope, or gradient changes along geographic paths.
  • Vehicle and IoT telemetry: Represent sensor readings, energy consumption, or other location-associated measurements.
  • Geospatial analysis: Highlight changes in arbitrary sampled datasets along geographic paths.

The API is independent of the underlying data, allowing applications to map any measurement to a color scale.

Implementation

  • Introduces MulticolorPolyline as a subclass of Polyline, compatible with the existing PolylineLayer.
  • Supports one color per coordinate through vertexColors, with smooth interpolation between adjacent vertices.
  • Supports stroke widths, borders, transparency, caps, and existing polyline hit detection.
  • Preserves original vertex indices through projection, simplification, and viewport culling so colors remain associated with their source coordinates.
  • Adds color-aware simplification to preserve meaningful color transitions alongside geometric detail.
  • Uses the existing batched path renderer for uniform opaque colors.
  • Optimizes gradient rendering using Canvas.drawLine for individual segments.
  • Supports disabling simplification with simplificationTolerance: 0 when all original samples must be retained.

Existing Polyline behavior remains unchanged.

Example

The polyline example page demonstrates mapping GPS-associated speed measurements to a color scale and rendering the resulting per-vertex colors using MulticolorPolyline.

The same approach can be applied to any numeric or categorical data that can be represented as colors.

Testing and performance

Adds tests covering:

  • Vertex color interpolation and fallback colors.
  • Validation of vertex and color counts.
  • Color preservation through simplification and viewport culling.
  • Transparency, joins, caps, borders, and duplicate coordinates.
  • Rendering consistency for uniform-color polylines.
  • Zero-tolerance simplification and zoom changes.

Includes synthetic benchmarks for 5,000- and 20,000-point paths, comparing ordinary polylines, uniform-color multicolor polylines, gradients, and outlined routes during pan and zoom.

The benchmarks measure CPU build/paint performance rather than GPU frame times or FPS.

Introduce MulticolorPolyline with per-vertex colors, border handling, and tests. Skip simplification and segmentation for multicolor polylines so gradients stay intact.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant