REPOSITORY CODING · MEDIUM
Make map label priority independent of import order
Greedy placement currently depends on the input array, allowing a low-priority label to hide a more important landmark. Implement descending-priority processing with lexical ID tie breaks. Return hidden IDs in that processing order and preserve the original request arrays.
Repository ImplementationCartographic label placement workbench
Work through a real codebase.
Choose an environment, investigate the existing implementation and use the tests to check your change. Sign in to open a workspace; execution and Ono usage follow your plan’s allowances.
Task requirements and environments
Vue · 50 minute session
- Place map labels deterministically inside a viewport. Map anchors use world coordinates; viewport x/y is the world origin at its top-left, scale converts world units to screen pixels. Label widths/heights and candidate offsets are already screen pixels and must not be scaled.
- Project each anchor as (world - origin) * scale, then add its candidate offset. Candidates are top-left label positions. Try offsets in the supplied order and choose the first rectangle entirely inside [0,width] x [0,height] with no positive-area overlap.
- Obstacle rectangles are in screen pixels. Touching edges or corners is allowed; positive-area overlap is not. Previously placed labels also become obstacles. Report a label as hidden only if every candidate is clipped or collides.
- Process labels by descending priority, then id using lexical comparison. Placement is greedy and does not move earlier labels. Return placed items with id, chosen zero-based offset, x/y/width/height, and hidden ids in processing order. Never mutate the input.
- The real Vue application runs the same layout service in the browser, displays placed labels and obstacles in SVG, and lets users inspect each label. The Node HTTP rehearsal endpoint supports automated fixtures. This is a planar screen-layout model, not a geographic projection library.