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

Full TypeScript signature sourced from the util file.

typescript

API

Parameters

Input parameters accepted by this util.

multi
required
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

Return value

The value returned by this util.

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

Usage

Examples

Ready-to-paste usage snippets.

Place a label at the centre of a country

typescript