Skip to content

Commit

Permalink
add right justification and justify attr to TextSymbolizer [#50]
Browse files Browse the repository at this point in the history
  • Loading branch information
bdon committed Sep 24, 2021
1 parent b1b0702 commit d765dd3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/default_style/style.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createPattern, PolygonSymbolizer, IconSymbolizer, ShieldSymbolizer, LineSymbolizer, CenteredTextSymbolizer, OffsetTextSymbolizer, GroupSymbolizer, FlexSymbolizer, CircleSymbolizer, PolygonLabelSymbolizer, LineLabelSymbolizer, exp, LabelSymbolizer, Padding } from '../symbolizer'
import { createPattern, PolygonSymbolizer, IconSymbolizer, ShieldSymbolizer, LineSymbolizer, CenteredTextSymbolizer, OffsetTextSymbolizer, GroupSymbolizer, FlexSymbolizer, CircleSymbolizer, PolygonLabelSymbolizer, LineLabelSymbolizer, exp, LabelSymbolizer, Padding, Justify } from '../symbolizer'
import { Rule } from '../painter'
import { LabelRule } from '../labeler'
import { Feature } from '../tilecache'
Expand Down
6 changes: 5 additions & 1 deletion src/symbolizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,7 @@ export class TextSymbolizer implements LabelSymbolizer {
lineHeight: NumberAttr // in ems
letterSpacing: NumberAttr // in px
maxLineCodeUnits: number
justify: Justify

constructor(options:any) {
this.font = new FontAttr(options)
Expand All @@ -485,6 +486,7 @@ export class TextSymbolizer implements LabelSymbolizer {
this.lineHeight = new NumberAttr(options.lineHeight,1)
this.letterSpacing = new NumberAttr(options.letterSpacing,0)
this.maxLineCodeUnits = options.maxLineChars || 15
this.justify = options.justify
}

public place(layout:Layout,geom:Point[][],feature:Feature) {
Expand Down Expand Up @@ -532,8 +534,10 @@ export class TextSymbolizer implements LabelSymbolizer {
var y = 0
for (let line of lines) {
var startX = 0
if (extra && extra.justify == Justify.Center) {
if (this.justify == Justify.Center || (extra && extra.justify == Justify.Center)) {
startX = (width - ctx.measureText(line).width) / 2
} else if (this.justify == Justify.Right || (extra && extra.justify == Justify.Right)) {
startX = (width - ctx.measureText(line).width)
}
if (textStrokeWidth) {
ctx.lineWidth = textStrokeWidth * 2 // centered stroke
Expand Down

0 comments on commit d765dd3

Please sign in to comment.