What is polylabel?
The polylabel npm package is used to find the pole of inaccessibility of a polygon, which is the most distant internal point from the polygon's edges. This is useful for placing labels on polygons in a way that maximizes readability and avoids overlap with the edges.
Finding the pole of inaccessibility
This feature allows you to find the pole of inaccessibility for a given polygon. The code sample demonstrates how to use the polylabel function to find the optimal label position within a square polygon.
const polylabel = require('polylabel');
const polygon = [[[0, 0], [10, 0], [10, 10], [0, 10], [0, 0]]];
const precision = 1.0;
const labelPosition = polylabel(polygon, precision);
console.log(labelPosition); // Outputs: [5, 5]