Skip to content

Commit

Permalink
fix: Mapbox style conversion function - geometry type filtering (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
claustres committed Jul 15, 2024
1 parent c60e2b8 commit d241612
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/mapbox-style.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,17 @@ function number(val, defaultValue) {
return typeof val === "number" ? val : defaultValue
}

function getGeomType(f) {
if (f.geomType === 1) return 'Point'
else if (f.geomType === 2) return 'LineString'
else return 'Polygon'
}

export function filterFn(arr) {
// hack around "$type"
if (arr.includes("$type")) {
return (z) => true
if (arr[0] === "==") {
return (z, f) => getGeomType(f) === arr[2]
}
}
if (arr[0] === "==") {
return (z, f) => f.props[arr[1]] === arr[2]
Expand Down Expand Up @@ -196,6 +203,10 @@ export function mapbox_style(obj, fontsubmap) {
if (layer.layout && layer.layout.visibility === "none") {
continue
}
// ignore background layer as this should be managed by backgroundColor
if (layer.type === "background") {
continue
}

if (layer.ref) {
const referenced = refs.get(layer.ref)
Expand All @@ -213,7 +224,6 @@ export function mapbox_style(obj, fontsubmap) {
filter = filterFn(layer.filter)
}

// ignore background-color?
if (layer.type === "fill") {
paint_rules.push({
dataLayer: layer["source-layer"],
Expand Down

0 comments on commit d241612

Please sign in to comment.