multiPolygonCentroid

Chart
stable

Computes the geographic centroid of a multi-polygon (arithmetic mean of all [lng, lat] vertices) and returns it projected to SVG pixel space via mercatorProject.

API

Signature

Signature TypeScript complète, extraite du fichier util.

typescript

API

Paramètres

Paramètres d'entrée acceptés par cet util.

multi
requis
Array<Array<[number, number]>>
Multi-polygon data: outer array is a list of polygons, inner array is a list of [lng, lat] geographic pairs.
width
number
1000
SVG canvas width in pixels.
height
number
500
SVG canvas height in pixels.

API

Valeur de retour

La valeur retournée par cet util.

[x, y] centroid in SVG pixel space. Returns [width/2, height/2] when the polygon set is empty.

Usage

Exemples

Extraits de code prêts à coller.

Place a label at the centre of a country

typescript