Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

continue linting fixes [#112] #125

Merged
merged 4 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 31 additions & 36 deletions src/attribute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ export class StringAttr<T extends string = string> {
public get(z: number, f?: Feature): T {
if (typeof this.str === "function") {
return this.str(z, f);
} else {
return this.str;
}
return this.str;
}
}

Expand All @@ -33,9 +32,8 @@ export class NumberAttr {
public get(z: number, f?: Feature): number {
if (typeof this.value === "function") {
return this.value(z, f);
} else {
return this.value;
}
return this.value;
}
}

Expand Down Expand Up @@ -120,44 +118,42 @@ export class FontAttr {
if (this.font) {
if (typeof this.font === "function") {
return this.font(z, f);
} else {
return this.font;
}
} else {
let style = "";
if (this.style) {
if (typeof this.style === "function") {
style = this.style(z, f) + " ";
} else {
style = this.style + " ";
}
}

let weight = "";
if (this.weight) {
if (typeof this.weight === "function") {
weight = this.weight(z, f) + " ";
} else {
weight = this.weight + " ";
}
}

let size;
if (typeof this.size === "function") {
size = this.size(z, f);
return this.font;
}
let style = "";
if (this.style) {
if (typeof this.style === "function") {
style = `${this.style(z, f)} `;
} else {
size = this.size;
style = `${this.style} `;
}
}

let family;
if (typeof this.family === "function") {
family = this.family(z, f);
let weight = "";
if (this.weight) {
if (typeof this.weight === "function") {
weight = `${this.weight(z, f)} `;
} else {
family = this.family;
weight = `${this.weight} `;
}
}

let size;
if (typeof this.size === "function") {
size = this.size(z, f);
} else {
size = this.size;
}

return `${style}${weight}${size}px ${family}`;
let family;
if (typeof this.family === "function") {
family = this.family(z, f);
} else {
family = this.family;
}

return `${style}${weight}${size}px ${family}`;
}
}

Expand All @@ -174,8 +170,7 @@ export class ArrayAttr<T = number> {
public get(z: number, f?: Feature): T[] {
if (typeof this.value === "function") {
return this.value(z, f);
} else {
return this.value;
}
return this.value;
}
}
72 changes: 43 additions & 29 deletions src/compat/json_style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,53 +17,66 @@ export function filterFn(arr: any[]): Filter {
// hack around "$type"
if (arr.includes("$type")) {
return (z) => true;
} else if (arr[0] === "==") {
}
if (arr[0] === "==") {
return (z, f) => f.props[arr[1]] === arr[2];
} else if (arr[0] === "!=") {
}
if (arr[0] === "!=") {
return (z, f) => f.props[arr[1]] !== arr[2];
} else if (arr[0] === "!") {
}
if (arr[0] === "!") {
const sub = filterFn(arr[1]);
return (z, f) => !sub(z, f);
} else if (arr[0] === "<") {
}
if (arr[0] === "<") {
return (z, f) => number(f.props[arr[1]], Infinity) < arr[2];
} else if (arr[0] === "<=") {
}
if (arr[0] === "<=") {
return (z, f) => number(f.props[arr[1]], Infinity) <= arr[2];
} else if (arr[0] === ">") {
}
if (arr[0] === ">") {
return (z, f) => number(f.props[arr[1]], -Infinity) > arr[2];
} else if (arr[0] === ">=") {
}
if (arr[0] === ">=") {
return (z, f) => number(f.props[arr[1]], -Infinity) >= arr[2];
} else if (arr[0] === "in") {
}
if (arr[0] === "in") {
return (z, f) => arr.slice(2, arr.length).includes(f.props[arr[1]]);
} else if (arr[0] === "!in") {
}
if (arr[0] === "!in") {
return (z, f) => !arr.slice(2, arr.length).includes(f.props[arr[1]]);
} else if (arr[0] === "has") {
}
if (arr[0] === "has") {
return (z, f) => f.props.hasOwnProperty(arr[1]);
} else if (arr[0] === "!has") {
}
if (arr[0] === "!has") {
return (z, f) => !f.props.hasOwnProperty(arr[1]);
} else if (arr[0] === "all") {
}
if (arr[0] === "all") {
const parts = arr.slice(1, arr.length).map((e) => filterFn(e));
return (z, f) =>
parts.every((p) => {
return p(z, f);
});
} else if (arr[0] === "any") {
}
if (arr[0] === "any") {
const parts = arr.slice(1, arr.length).map((e) => filterFn(e));
return (z, f) =>
parts.some((p) => {
return p(z, f);
});
} else {
console.log("Unimplemented filter: ", arr[0]);
return (f) => false;
}
console.log("Unimplemented filter: ", arr[0]);
return (f) => false;
}

export function numberFn(obj: any): (z: number, f?: Feature) => number {
if (obj.base && obj.stops) {
return (z: number) => {
return exp(obj.base, obj.stops)(z - 1);
};
} else if (
}
if (
obj[0] === "interpolate" &&
obj[1][0] === "exponential" &&
obj[2][0] === "zoom"
Expand All @@ -76,7 +89,8 @@ export function numberFn(obj: any): (z: number, f?: Feature) => number {
return (z: number) => {
return exp(obj[1][1], stops)(z - 1);
};
} else if (obj[0] === "step" && obj[1][0] === "get") {
}
if (obj[0] === "step" && obj[1][0] === "get") {
const slice = obj.slice(2);
const prop = obj[1][1];
return (z: number, f?: Feature) => {
Expand All @@ -89,10 +103,9 @@ export function numberFn(obj: any): (z: number, f?: Feature) => number {
}
return slice[slice.length - 1];
};
} else {
console.log("Unimplemented numeric fn: ", obj);
return (z) => 1;
}
console.log("Unimplemented numeric fn: ", obj);
return (z) => 1;
}

export function numberOrFn(
Expand Down Expand Up @@ -138,16 +151,17 @@ export function getFont(obj: any, fontsubmap: any) {
// for fallbacks, use the weight and style of the first font
let weight = "";
if (fontfaces.length && fontfaces[0].weight)
weight = fontfaces[0].weight + " ";
weight = `${fontfaces[0].weight} `;
let style = "";
if (fontfaces.length && fontfaces[0].style) style = fontfaces[0].style + " ";
if (fontfaces.length && fontfaces[0].style) style = `${fontfaces[0].style} `;

if (typeof text_size === "number") {
return (z: number) =>
`${style}${weight}${text_size}px ${fontfaces
.map((f) => f.face)
.join(", ")}`;
} else if (text_size.stops) {
}
if (text_size.stops) {
let base = 1.4;
if (text_size.base) base = text_size.base;
else text_size.base = base;
Expand All @@ -157,17 +171,17 @@ export function getFont(obj: any, fontsubmap: any) {
.map((f) => f.face)
.join(", ")}`;
};
} else if (text_size[0] === "step") {
}
if (text_size[0] === "step") {
const t = numberFn(text_size);
return (z: number, f?: Feature) => {
return `${style}${weight}${t(z, f)}px ${fontfaces
.map((f) => f.face)
.join(", ")}`;
};
} else {
console.log("Can't parse font: ", obj);
return (z: number) => "12px sans-serif";
}
console.log("Can't parse font: ", obj);
return (z: number) => "12px sans-serif";
}

export function json_style(obj: any, fontsubmap: Map<string, FontSub>) {
Expand All @@ -186,7 +200,7 @@ export function json_style(obj: any, fontsubmap: Map<string, FontSub>) {
const referenced = refs.get(layer.ref);
layer.type = referenced.type;
layer.filter = referenced.filter;
layer.source = referenced["source"];
layer.source = referenced.source;
layer["source-layer"] = referenced["source-layer"];
}

Expand Down
37 changes: 17 additions & 20 deletions src/default_style/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,15 +336,14 @@ export const labelRules = (
label_props: language2,
}),
]);
} else {
return new FlexSymbolizer([
symbolizer,
new CenteredTextSymbolizer({
fill: fill,
label_props: language2,
}),
]);
}
return new FlexSymbolizer([
symbolizer,
new CenteredTextSymbolizer({
fill: fill,
label_props: language2,
}),
]);
};

return [
Expand All @@ -364,7 +363,7 @@ export const labelRules = (
params.countryLabel,
),
filter: (z, f) => {
return f.props["pmap:kind"] == "country";
return f.props["pmap:kind"] === "country";
},
},
{
Expand All @@ -378,14 +377,14 @@ export const labelRules = (
params.stateLabel,
),
filter: (z, f) => {
return f.props["pmap:kind"] == "state";
return f.props["pmap:kind"] === "state";
},
},
{
id: "cities_high",
dataLayer: "places",
filter: (z, f) => {
return f.props["pmap:kind"] == "city";
return f.props["pmap:kind"] === "city";
},
minzoom: 7,
symbolizer: languageStack(
Expand All @@ -396,10 +395,9 @@ export const labelRules = (
if (f?.props["pmap:rank"] === 1) {
if (z > 8) return "600 20px sans-serif";
return "600 12px sans-serif";
} else {
if (z > 8) return "600 16px sans-serif";
return "600 10px sans-serif";
}
if (z > 8) return "600 16px sans-serif";
return "600 10px sans-serif";
},
}),
params.cityLabel,
Expand All @@ -412,7 +410,7 @@ export const labelRules = (
id: "cities_low",
dataLayer: "places",
filter: (z, f) => {
return f.props["pmap:kind"] == "city";
return f.props["pmap:kind"] === "city";
},
maxzoom: 6,
symbolizer: new GroupSymbolizer([
Expand All @@ -430,10 +428,9 @@ export const labelRules = (
if (f?.props["pmap:rank"] === 1) {
if (z > 8) return "600 20px sans-serif";
return "600 12px sans-serif";
} else {
if (z > 8) return "600 16px sans-serif";
return "600 10px sans-serif";
}
if (z > 8) return "600 16px sans-serif";
return "600 10px sans-serif";
},
}),
params.cityLabel,
Expand All @@ -456,7 +453,7 @@ export const labelRules = (
params.neighbourhoodLabel,
),
filter: (z, f) => {
return f.props["pmap:kind"] == "neighbourhood";
return f.props["pmap:kind"] === "neighbourhood";
},
},
{
Expand Down Expand Up @@ -514,7 +511,7 @@ export const labelRules = (
fill: params.neighbourhoodLabel,
}),
filter: (z, f) => {
return f.props["pmap:kind"] == "highway";
return f.props["pmap:kind"] === "highway";
},
},
{
Expand Down
Loading
Loading