Skip to content
This repository has been archived by the owner on Jul 6, 2023. It is now read-only.

Commit

Permalink
fix(ts): Exports TextPlacements and LineLabelPlacement
Browse files Browse the repository at this point in the history
  • Loading branch information
ibesora committed Mar 30, 2022
1 parent 2f81707 commit 04e89af
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 22 deletions.
2 changes: 1 addition & 1 deletion dist/dd-symbolizers.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Point from "@mapbox/point-geometry";
import { Feature } from "./tilecache";
import { Justify, LabelSymbolizer, TextSymbolizer } from "./symbolizer";
import { Label, Layout } from "./labeler";
export declare const enum TextPlacements {
export declare enum TextPlacements {
N = 1,
NE = 2,
E = 3,
Expand Down
41 changes: 26 additions & 15 deletions dist/dd-symbolizers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@ import Point from "@mapbox/point-geometry";
import { GeomType } from "./tilecache";
// @ts-ignore
import { TextSymbolizer } from "./symbolizer";
export var TextPlacements;
(function (TextPlacements) {
TextPlacements[TextPlacements["N"] = 1] = "N";
TextPlacements[TextPlacements["NE"] = 2] = "NE";
TextPlacements[TextPlacements["E"] = 3] = "E";
TextPlacements[TextPlacements["SE"] = 4] = "SE";
TextPlacements[TextPlacements["S"] = 5] = "S";
TextPlacements[TextPlacements["SW"] = 6] = "SW";
TextPlacements[TextPlacements["W"] = 7] = "W";
TextPlacements[TextPlacements["NW"] = 8] = "NW";
})(TextPlacements || (TextPlacements = {}));
export class DataDrivenOffsetSymbolizer {
constructor(symbolizer, options) {
this.getBbox = (anchor, bbOrigin, firstLabelBbox) => {
Expand All @@ -17,14 +28,14 @@ export class DataDrivenOffsetSymbolizer {
this.offsetX = options.offsetX || 0;
this.offsetY = options.offsetY || 0;
this.placements = options.placements || [
2 /* NE */,
6 /* SW */,
8 /* NW */,
4 /* SE */,
1 /* N */,
5 /* S */,
3 /* E */,
7 /* W */,
TextPlacements.NE,
TextPlacements.SW,
TextPlacements.NW,
TextPlacements.SE,
TextPlacements.N,
TextPlacements.S,
TextPlacements.E,
TextPlacements.W,
];
this.attrs =
options.attrs ||
Expand Down Expand Up @@ -86,30 +97,30 @@ export class DataDrivenOffsetSymbolizer {
computeXAxisOffset(offsetX, fb, placement) {
const labelWidth = fb.maxX;
const labelHalfWidth = labelWidth / 2;
if ([1 /* N */, 5 /* S */].includes(placement))
if ([TextPlacements.N, TextPlacements.S].includes(placement))
return offsetX - labelHalfWidth;
if ([8 /* NW */, 7 /* W */, 6 /* SW */].includes(placement))
if ([TextPlacements.NW, TextPlacements.W, TextPlacements.SW].includes(placement))
return -offsetX - labelWidth;
return offsetX;
}
computeYAxisOffset(offsetY, fb, placement) {
const labelHalfHeight = Math.abs(fb.minY);
const labelBottom = fb.maxY;
const labelCenterHeight = (fb.minY + fb.maxY) / 2;
if ([3 /* E */, 7 /* W */].includes(placement))
if ([TextPlacements.E, TextPlacements.W].includes(placement))
return offsetY - labelCenterHeight;
if ([8 /* NW */, 2 /* NE */, 1 /* N */].includes(placement))
if ([TextPlacements.NW, TextPlacements.NE, TextPlacements.N].includes(placement))
return -offsetY - labelBottom;
if ([6 /* SW */, 4 /* SE */, 5 /* S */].includes(placement))
if ([TextPlacements.SW, TextPlacements.SE, TextPlacements.S].includes(placement))
return offsetY + labelHalfHeight;
return offsetY;
}
computeJustify(fixedJustify, placement) {
if (fixedJustify)
return fixedJustify;
if ([1 /* N */, 5 /* S */].includes(placement))
if ([TextPlacements.N, TextPlacements.S].includes(placement))
return 2 /* Center */;
if ([2 /* NE */, 3 /* E */, 4 /* SE */].includes(placement))
if ([TextPlacements.NE, TextPlacements.E, TextPlacements.SE].includes(placement))
return 1 /* Left */;
return 3 /* Right */;
}
Expand Down
2 changes: 1 addition & 1 deletion dist/symbolizer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ export declare class OffsetTextSymbolizer implements LabelSymbolizer {
constructor(options: any);
place(layout: Layout, geom: Point[][], feature: Feature): Label[] | undefined;
}
export declare const enum LineLabelPlacement {
export declare enum LineLabelPlacement {
Above = 1,
Center = 2,
Below = 3
Expand Down
12 changes: 9 additions & 3 deletions dist/symbolizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,12 @@ export class OffsetTextSymbolizer {
return this.symbolizer.place(layout, geom, feature);
}
}
export var LineLabelPlacement;
(function (LineLabelPlacement) {
LineLabelPlacement[LineLabelPlacement["Above"] = 1] = "Above";
LineLabelPlacement[LineLabelPlacement["Center"] = 2] = "Center";
LineLabelPlacement[LineLabelPlacement["Below"] = 3] = "Below";
})(LineLabelPlacement || (LineLabelPlacement = {}));
export class LineLabelSymbolizer {
constructor(options) {
this.font = new FontAttr(options);
Expand All @@ -725,7 +731,7 @@ export class LineLabelSymbolizer {
this.stroke = new StringAttr(options.stroke, "black");
this.width = new NumberAttr(options.width, 0);
this.offset = new NumberAttr(options.offset, 0);
this.position = options.position || 1 /* Above */;
this.position = options.position || LineLabelPlacement.Above;
this.maxLabelCodeUnits = new NumberAttr(options.maxLabelChars, 40);
this.repeatDistance = new NumberAttr(options.repeatDistance, 250);
}
Expand Down Expand Up @@ -773,9 +779,9 @@ export class LineLabelSymbolizer {
// ctx.strokeStyle = "red";
// ctx.stroke();
let heightPlacement = 0;
if (this.position === 3 /* Below */)
if (this.position === LineLabelPlacement.Below)
heightPlacement = height;
else if (this.position === 2 /* Center */)
else if (this.position === LineLabelPlacement.Center)
heightPlacement = height / 2;
// Compute the angle between the positive X axis and
// the point (dx, -dy). Notice that we need to change
Expand Down
2 changes: 1 addition & 1 deletion src/dd-symbolizers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Justify, LabelSymbolizer, TextSymbolizer } from "./symbolizer";
import { NumberAttr } from "./attribute";
import { Label, Layout } from "./labeler";

export const enum TextPlacements {
export enum TextPlacements {
N = 1,
NE = 2,
E = 3,
Expand Down
2 changes: 1 addition & 1 deletion src/symbolizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -942,7 +942,7 @@ export class OffsetTextSymbolizer implements LabelSymbolizer {
}
}

export const enum LineLabelPlacement {
export enum LineLabelPlacement {
Above = 1,
Center = 2,
Below = 3,
Expand Down

0 comments on commit 04e89af

Please sign in to comment.