Fix a filter-syntax warning found while investigating missing labels
Mixing the legacy "$type" filter with an expression (["get", "role"]) in the same filter logs as unsupported in newer MapLibre. Modernized all three measure layer filters to expression syntax; the vertex circle layer's filter simplifies to just checking "role" (it's only ever set on Point features to begin with, so the geometry-type check was redundant once "role" was added). Found while trying to reproduce a report that per-segment distance labels don't show on a longer, several-point measurement -- couldn't reproduce it locally or against production itself (both showed labels correctly on a fresh page load), so this may be unrelated; still worth fixing on its own.
This commit is contained in:
1 parent
3e81ee8015
commit
64a85afe6a
1 file changed
+10
-3
+10
-3
@@ -105,21 +105,28 @@ export class MeasureControl {
|
||||
id: FILL_LAYER_ID,
|
||||
type: "fill",
|
||||
source: SOURCE_ID,
|
||||
filter: ["==", "$type", "Polygon"],
|
||||
filter: ["==", ["geometry-type"], "Polygon"],
|
||||
paint: { "fill-color": "#1e5fbf", "fill-opacity": 0.15 },
|
||||
});
|
||||
this._map.addLayer({
|
||||
id: LINE_LAYER_ID,
|
||||
type: "line",
|
||||
source: SOURCE_ID,
|
||||
filter: ["!=", "$type", "Point"],
|
||||
filter: ["!=", ["geometry-type"], "Point"],
|
||||
paint: { "line-color": "#1e5fbf", "line-width": 2 },
|
||||
});
|
||||
// "role" alone (not also a geometry-type check) — it's only ever set on
|
||||
// Point features to begin with (the line/polygon shape feature has no
|
||||
// "role" property at all), so it already implies the geometry type.
|
||||
// Mixing the legacy "$type" filter syntax with an expression like
|
||||
// ["get", "role"] in the same filter logs as unsupported in newer
|
||||
// MapLibre — this sidesteps that rather than fixing it by switching
|
||||
// "$type" to ["geometry-type"] and keeping both checks.
|
||||
this._map.addLayer({
|
||||
id: POINT_LAYER_ID,
|
||||
type: "circle",
|
||||
source: SOURCE_ID,
|
||||
filter: ["all", ["==", "$type", "Point"], ["==", ["get", "role"], "vertex"]],
|
||||
filter: ["==", ["get", "role"], "vertex"],
|
||||
paint: { "circle-radius": 4, "circle-color": "#fff", "circle-stroke-color": "#1e5fbf", "circle-stroke-width": 2 },
|
||||
});
|
||||
// Distance mode only (see _render) — each segment's own length, not
|
||||
|
||||
Reference in new issue
Block a user