Skip to content

Commit

Permalink
dynamic justification based on OffsetSymbolizer position [#50]
Browse files Browse the repository at this point in the history
  • Loading branch information
bdon committed Sep 24, 2021
1 parent d765dd3 commit 21fe2fe
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/symbolizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -609,28 +609,33 @@ export class OffsetSymbolizer implements LabelSymbolizer {
}

var origin = new Point(offset,-offset)
var justify:Justify
let draw = (ctx:any) => {
ctx.translate(origin.x,origin.y)
first_label.draw(ctx)
first_label.draw(ctx,{justify:justify})
}

// NE
var bbox = getBbox(anchor,origin)
justify = Justify.Left
if (!layout.index.bboxCollides(bbox,layout.order)) return [{anchor:anchor,bboxes:[bbox],draw:draw}]

// SW
origin = new Point(-offset-fb.maxX,offset-fb.minY)
bbox = getBbox(anchor,origin)
justify = Justify.Right
if (!layout.index.bboxCollides(bbox,layout.order)) return [{anchor:anchor,bboxes:[bbox],draw:draw}]

// NW
origin = new Point(-offset-fb.maxX,-offset)
bbox = getBbox(anchor,origin)
justify = Justify.Right
if (!layout.index.bboxCollides(bbox,layout.order)) return [{anchor:anchor,bboxes:[bbox],draw:draw}]

// SE
origin = new Point(-offset-fb.maxX,offset-fb.minY)
bbox = getBbox(anchor,origin)
justify = Justify.Left
if (!layout.index.bboxCollides(bbox,layout.order)) return [{anchor:anchor,bboxes:[bbox],draw:draw}]

return undefined
Expand Down

0 comments on commit 21fe2fe

Please sign in to comment.