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

more typing improvements [#112] #128

Merged
merged 3 commits into from
Jan 24, 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
6 changes: 3 additions & 3 deletions src/attribute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export class TextAttr {
break;
}
}
let transform;
let transform: string | ((z: number, f: Feature) => string) | undefined;
if (typeof this.textTransform === "function") {
transform = this.textTransform(z, f);
} else {
Expand Down Expand Up @@ -139,14 +139,14 @@ export class FontAttr {
}
}

let size;
let size: number | ((z: number, f: Feature) => number) | undefined;
if (typeof this.size === "function") {
size = this.size(z, f);
} else {
size = this.size;
}

let family;
let family: string | ((z: number, f: Feature) => string) | undefined;
if (typeof this.family === "function") {
family = this.family(z, f);
} else {
Expand Down
6 changes: 5 additions & 1 deletion src/frontends/static.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,11 @@ export class Static {
canvas.height = height * dpr;
}
if (options.lang) canvas.lang = options.lang;
const ctx = canvas.getContext("2d")!;
const ctx = canvas.getContext("2d");
if (!ctx) {
console.error("Failed to initialize canvas2d context.");
return;
}
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
return this.drawContext(ctx, width, height, latlng, display_zoom);
}
Expand Down
10 changes: 3 additions & 7 deletions src/symbolizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,6 @@ export function cubicBezier(
};
}

function isFunction(obj: any) {
return !!(obj && obj.constructor && obj.call && obj.apply);
}

export class LineSymbolizer implements PaintSymbolizer {
color: StringAttr;
width: NumberAttr;
Expand Down Expand Up @@ -525,7 +521,7 @@ export class ShieldSymbolizer implements LabelSymbolizer {
);
ctx.fillStyle = this.fill.get(layout.zoom, f);
ctx.font = font;
ctx.fillText(property!, -width / 2, 0);
ctx.fillText(property, -width / 2, 0);
};
return [{ anchor: a, bboxes: [bbox], draw: draw }];
}
Expand Down Expand Up @@ -1104,10 +1100,10 @@ export class LineLabelSymbolizer implements LabelSymbolizer {
if (lineWidth) {
ctx.lineWidth = lineWidth;
ctx.strokeStyle = this.stroke.get(layout.zoom, feature);
ctx.strokeText(name!, 0, 0);
ctx.strokeText(name, 0, 0);
}
ctx.fillStyle = this.fill.get(layout.zoom, feature);
ctx.fillText(name!, 0, 0);
ctx.fillText(name, 0, 0);
};
labels.push({
anchor: candidate.start,
Expand Down
2 changes: 1 addition & 1 deletion src/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export class View {

public dataTilesForBounds(
display_zoom: number,
bounds: any,
bounds: Bbox,
): Array<TileTransform> {
const fractional = 2 ** display_zoom / 2 ** Math.ceil(display_zoom);
const needed = [];
Expand Down
Loading