Skip to content

Commit c3db60c

Browse files
authored
Allow data-driven styling for line-dasharray (#1100)
* Implement data-driven styling for line-dasharray ref maplibre/maplibre-gl-js#1235 * Add dashes prop * Fix linter errors * Fix integration tests * Update v8.json * Update CHANGELOG.md * Update v8.json * Update docs
1 parent 5f35399 commit c3db60c

File tree

5 files changed

+32
-35
lines changed

5 files changed

+32
-35
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
- _...Add new stuff here..._
55
- Add note regarding visual artifacts that can appear with large width/size/offset values on vector tile layers, highlight remediation options ([#4160](https://github.com/maplibre/maplibre-gl-js/issues/4160))
66

7+
- Implement data-driven styling support for `line-dasharray` ([#5812](https://github.com/mapbox/mapbox-gl-js/pull/5812))
8+
79
### 🐞 Bug fixes
810
- _...Add new stuff here..._
911
- Replace additional spread operator (`...`) due to esbuild limitations ([#1297](https://github.com/maplibre/maplibre-style-spec/pull/1297))

src/expression/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ export type Feature = {
5151
'max': string;
5252
};
5353
};
54+
readonly dashes?: {
55+
[_: string]: {
56+
'min': string;
57+
'mid': string;
58+
'max': string;
59+
};
60+
};
5461
readonly geometry?: Array<Array<Point2D>>;
5562
};
5663

src/reference/v8.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@
566566
"android": "https://github.com/maplibre/maplibre-native/issues/2783"
567567
}
568568
}
569-
},
569+
},
570570
"baseShift": {
571571
"type": "number",
572572
"default": 0.0,
@@ -578,7 +578,7 @@
578578
"android": "https://github.com/maplibre/maplibre-native/issues/2783"
579579
}
580580
}
581-
},
581+
},
582582
"volatile": {
583583
"type": "boolean",
584584
"default": false,
@@ -5672,7 +5672,7 @@
56725672
"type": {
56735673
"type": "projectionDefinition",
56745674
"doc": "The projection definition type. Can be specified as a string, a transition state, or an expression.",
5675-
"default": "mercator",
5675+
"default": "mercator",
56765676
"property-type": "data-constant",
56775677
"transition": false,
56785678
"expression": {
@@ -6346,7 +6346,7 @@
63466346
"line-dasharray": {
63476347
"type": "array",
63486348
"value": "number",
6349-
"doc": "Specifies the lengths of the alternating dashes and gaps that form the dash pattern. The lengths are later scaled by the line width. To convert a dash length to pixels, multiply the length by the current line width. Note that GeoJSON sources with `lineMetrics: true` specified won't render dashed lines to the expected scale. Also note that zoom-dependent expressions will be evaluated only at integer zoom levels.",
6349+
"doc": "Specifies the lengths of the alternating dashes and gaps that form the dash pattern. The lengths are later scaled by the line width. To convert a dash length to pixels, multiply the length by the current line width. GeoJSON sources with `lineMetrics: true` specified won't render dashed lines to the expected scale. Zoom-dependent expressions will be evaluated only at integer zoom levels. The only way to create an array value is using `[\"literal\", [...]]`; arrays cannot be read from or derived from feature properties.",
63506350
"minimum": 0,
63516351
"transition": true,
63526352
"units": "line widths",
@@ -6370,10 +6370,11 @@
63706370
"expression": {
63716371
"interpolated": false,
63726372
"parameters": [
6373-
"zoom"
6373+
"zoom",
6374+
"feature"
63746375
]
63756376
},
6376-
"property-type": "cross-faded"
6377+
"property-type": "cross-faded-data-driven"
63776378
},
63786379
"line-pattern": {
63796380
"type": "resolvedImage",

test/integration/style-spec/tests/functions.input.json

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -934,15 +934,6 @@
934934
"fill-extrusion-opacity": ["get", "opacity"]
935935
}
936936
},
937-
{
938-
"id": "invalid expression - line-dasharray must use step interpolation",
939-
"type": "line",
940-
"source": "source",
941-
"source-layer": "layer",
942-
"paint": {
943-
"line-dasharray": ["interpolate", ["linear"], ["zoom"], 0, ["literal", [1, 2]], 1, ["literal", [3, 4]]]
944-
}
945-
},
946937
{
947938
"id": "invalid expression - heatmap-color must be zoom constant",
948939
"type": "heatmap",

test/integration/style-spec/tests/functions.output.json

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"line": 75
2929
},
3030
{
31-
"message": "layers[6].paint.line-dasharray.stops[0][0]: number expected, string found",
31+
"message": "layers[6].paint.line-dasharray.stops[0][0]: number expected, string found\nIf you intended to use a categorical function, specify `\"type\": \"categorical\"`.",
3232
"line": 89
3333
},
3434
{
@@ -184,39 +184,35 @@
184184
"line": 934
185185
},
186186
{
187-
"message": "layers[52].paint.line-dasharray: Type array<number> is not interpolatable.",
187+
"message": "layers[52].paint.heatmap-color: zoom expressions not supported",
188188
"line": 943
189189
},
190190
{
191-
"message": "layers[53].paint.heatmap-color: zoom expressions not supported",
192-
"line": 952
191+
"message": "layers[53].paint.heatmap-color: zoom functions not supported",
192+
"line": 951
193193
},
194194
{
195-
"message": "layers[54].paint.heatmap-color: zoom functions not supported",
196-
"line": 960
195+
"message": "layers[54].layout.line-join: \"feature-state\" data expressions are not supported with layout properties.",
196+
"line": 959
197197
},
198198
{
199-
"message": "layers[55].layout.line-join: \"feature-state\" data expressions are not supported with layout properties.",
200-
"line": 968
199+
"message": "layers[55].paint.line-width.stops[0][1]: expressions are not allowed in function stops.",
200+
"line": 972
201201
},
202202
{
203-
"message": "layers[56].paint.line-width.stops[0][1]: expressions are not allowed in function stops.",
204-
"line": 981
203+
"message": "layers[56]: layer \"invalid expression - color-relief-color must be zoom constant\" requires a raster-dem source",
204+
"line": 983
205205
},
206206
{
207-
"message": "layers[57]: layer \"invalid expression - color-relief-color must be zoom constant\" requires a raster-dem source",
208-
"line": 992
207+
"message": "layers[56].paint.color-relief-color: zoom expressions not supported",
208+
"line": 986
209209
},
210210
{
211-
"message": "layers[57].paint.color-relief-color: zoom expressions not supported",
212-
"line": 995
211+
"message": "layers[57]: layer \"invalid expression - color-relief-color must not be a function\" requires a raster-dem source",
212+
"line": 991
213213
},
214214
{
215-
"message": "layers[58]: layer \"invalid expression - color-relief-color must not be a function\" requires a raster-dem source",
216-
"line": 1000
217-
},
218-
{
219-
"message": "layers[58].paint.color-relief-color: zoom functions not supported",
220-
"line": 1003
215+
"message": "layers[57].paint.color-relief-color: zoom functions not supported",
216+
"line": 994
221217
}
222218
]

0 commit comments

Comments
 (0)