$ cnpm install polylabel
A fast algorithm for finding polygon pole of inaccessibility, the most distant internal point from the polygon outline (not to be confused with centroid), implemented as a JavaScript library. Useful for optimal placement of a text label on a polygon.
It's an iterative grid algorithm, inspired by paper by Garcia-Castellanos & Lombardo, 2007. Unlike the one in the paper, this algorithm:
Given polygon coordinates in
GeoJSON-like format
and precision (1.0
by default),
Polylabel returns the pole of inaccessibility coordinate in [x, y]
format.
var p = polylabel(polygon, 1.0);
This is an iterative grid-based algorithm, which starts by covering the polygon with big square cells and then iteratively splitting them in the order of the most promising ones, while aggressively pruning uninteresting cells.
cell_size * sqrt(2) / 2
).cell_max - best_dist > precision
),
split it into 4 children cells and put them in the queue.TypeScript type definitions
are available via npm install --save @types/polylabel
.
Copyright 2013 - present © cnpmjs.org