Atlaslog
Atlaslog / deck.gl / API / PathStyleExtension
deck.gl · API reference

PathStyleExtension

Quick answer

The PathStyleExtension adds dashes and offsets to the PathLayer and composite layers that render paths, such as PolygonLayer and GeoJsonLayer. It can al.

Last verified 2026-11-03 · deck.gl 9.0 · Cite this page
Runnable examplesChinese noteAll API topics

The PathStyleExtension adds dashes and offsets to the PathLayer and composite layers that render paths, such as PolygonLayer and GeoJsonLayer. It can also dash ScatterplotLayer outlines and TextLayer backgrounds.

import {PathLayer} from '@deck.gl/layers';
import {PathStyleExtension} from '@deck.gl/extensions';

// `path` is the road's centerline, an array of [longitude, latitude] positions
function getRoadLayer(path) {
return new PathLayer({
id: 'road',
data: [
{path, dashArray: [4, 3], offset: 0, color: [60, 100, 160]}, // center line
{path, dashArray: [0, 0], offset: -5, color: [0, 0, 0]}, // left edge
{path, dashArray: [0, 0], offset: 5, color: [0, 0, 0]} // right edge
],
getPath: d => d.path,
getColor: d => d.color,
getWidth: 2,

// props added by PathStyleExtension
getDashArray: d => d.dashArray,
dashUnits: 'widths',
getOffset: d => d.offset,

extensions: [new PathStyleExtension({dashMode: 'path', offset: true})]
});
}

PathStyleExtension currently requires WebGL. Layers that use it do not render on WebGPU.

Installation​

To install the dependencies from NPM:

npm install deck.gl
# or
npm install @deck.gl/core @deck.gl/layers @deck.gl/extensions
import {PathStyleExtension} from '@deck.gl/extensions';
new PathStyleExtension({});

To use pre-bundled scripts:

<script src="https://unpkg.com/deck.gl@^9.0.0/dist.min.js"></script>
<!-- or -->
<script src="https://unpkg.com/@deck.gl/core@^9.0.0/dist.min.js"></script>
<script src="https://unpkg.com/@deck.gl/layers@^9.0.0/dist.min.js"></script>
<script src="https://unpkg.com/@deck.gl/extensions@^9.0.0/dist.min.js"></script>
new deck.PathStyleExtension({});

Constructor​

new PathStyleExtension({dash, dashMode, offset});

Layer Properties​

When added to a layer via the extensions prop, the PathStyleExtension adds the following properties to the layer:

getDashArray (Accessor<number[2]>)​

The dash pattern to draw each path with: [dashSize, gapSize], measured in dashUnits. With the default units, [4, 5] on a 10 pixel wide path draws 20 pixel dashes separated by 25 pixel gaps.

dashUnits (string, optional)​

The units of getDashArray:

Only applies to PathLayer and its composites. ScatterplotLayer and TextLayer always use 'widths'.

dashJustified (boolean, optional)​

If true, stretch or shrink the gaps so the pattern starts and ends on half a dash. In 'segment' mode this fits the pattern to every segment, so each corner lands on a dash. In 'path' mode it fits the pattern to the path's two ends. Leave it off when gap spacing must be exact.

Only applies to PathLayer and its composites.

dashGapPickable (boolean, optional)​

If true, the gaps between dashes are pickable. If false, only the dashes are pickable.

getOffset (Accessor<number>)​

The distance to shift each path sideways, in multiples of the stroke width. Positive values shift to the right of the path's direction and negative values to the left. 0 centers the line on its path.

To offset by a fixed distance, divide it by the width: a 4 pixel wide line with getOffset: 2 sits 8 pixels to the right.

Remarks​

Choosing a dash mode​

dashMode decides where the pattern starts over.

new PathLayer({
// ...
getDashArray: [3, 2],
dashJustified: false,
extensions: [new PathStyleExtension({dashMode: 'path'})]
});

'path' mode measures each path on the CPU and uses one more vertex attribute.

Coming from MapLibre or SVG​

To getMapLibreSVGdeck.gl
Dashes that scale with the lineline-dasharray: [2, 1]—getDashArray: [4, 2]
Dashes with a fixed screen size—stroke-dasharray="20 10"getDashArray: [20, 10], dashUnits: 'pixels'
A pattern that runs continuouslyAlwaysAlwaysdashMode: 'path'
A line shifted to one sideline-offset: 8 (pixels)—getOffset: 2 on a 4 pixel line

Three differences cause most surprises:

deck.gl v10 plans breaking changes to this extension to match other tools more closely. See the v10 tracker.

Troubleshooting​

Limitations​

Source​

modules/extensions/src/path-style

The design of dashMode and dashUnits is described in the path dash RFC.

TutorialsAPI index
English reference text adapted from the official deck.gl documentation, © vis.gl contributors, licensed under MIT.
Original page: https://deck.gl/docs/api-reference/extensions/path-style-extension · Chinese note: /deckgl/api/path-style-extension.html
Cite this page

Atlaslog (2026). PathStyleExtension. https://www.jingweizhi.com/en/deckgl/api/path-style-extension.html (accessed 2026-11-03).