Skip to main content
layers

Polyline Layer

PolylineLayer draws lines on the ground: routes, borders, GPS traces. Polyline supports border strokes (borderStrokeWidth draws a second, wider line beneath), dash and dot patterns in logical pixels, and a width given in metres on the ground.

PolylineLayer(
  polylines: [
    Polyline(points: route, strokeWidth: 6, borderStrokeWidth: 3, borderColor: Color(0xFFFFFFFF)),
    Polyline(points: detour, pattern: StrokePattern.dashed(segments: [12, 8])),
  ],
)

The demo draws the EU institutions as a GPS star: from the Commission in Brussels to the Parliament in Strasbourg, the Court of Justice in Luxembourg and the ECB in Frankfurt:

Apple MapKit (iOS)Google Maps (Android)
Routes between the EU institutionsRoutes between the EU institutions, on Google Maps

Width in metres on the ground​

useStrokeWidthInMeter: true measures strokeWidth (and borderStrokeWidth) in metres instead of logical pixels, so the line keeps its width on the ground as the zoom changes — a 10 m corridor stays 10 m wide:

Polyline(points: corridor, strokeWidth: 10, useStrokeWidthInMeter: true)
Android (Google Maps)iOS, macOS (MapKit)Web, Windows, Linux (flutter_map)
width recomputed at the camera's zoom, on every camera moveconverted at every draw by the renderer, exact at any scaleflutter_map's own behaviour

On Android the width follows the camera rather than each frame, so it lags very slightly inside a pinch and lands on the right value when the gesture ends; before the first camera position is known, the metres are drawn as pixels and the next camera move corrects them.

Caps, joins and dashes​

strokeCap, strokeJoin and pattern reach both native maps, not only flutter_map:

Android (Google Maps)iOS, macOS (MapKit)
strokeCapstartCap / endCaplineCap
strokeJoinjointTypelineJoin, with Flutter's miter limit of 4
patternDash / Gap items, in physical pixelslineDashPattern

A dashed line paints the same runs everywhere. Core Graphics puts a line cap on each dash, which makes every painted run one stroke width longer and every gap that much shorter, so the Apple pattern is compensated for it; an odd pattern, which Google needs in pairs, is repeated once. StrokePattern.dashed's and .dotted's patternFit is applied by the core, which rescales the segments to the line's length on screen when the camera settles — so the fit drifts a little during a pinch and snaps back at the end.