Skip to content

A better “label centroid” initializer? (polylabel) #1587

Open
@Fil

Description

@Fil

The centroid of a geometry is sometimes outside of it, for example (but not exclusively) with a MultiPolygon such as France+Guyane. This can result in labels or interactive tips that are quite far off from the shape they identify.

A great solution is to use @mapbox/polylabel, which guarantees that the center is inside —and furthermore at an optimal position for a centered label. The dependency is less that 1kB over the wire, including tinyqueue. An alternative approach could be to add an option to Plot.centroid, to make it choose the centroid of the largest polygon when given a multipolygon. Subpar solution, but cheaper.

Prototype https://observablehq.com/@observablehq/plot-pole-of-inaccessibility-1587

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestquestionFurther information is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions