MCPcopy Create free account
hub / github.com/plotly/plotly.js / getCentroid

Function getCentroid

topojson/bin/process_geodata.mjs:120–139  ·  view source on GitHub ↗
(feature)

Source from the content-addressed store, hash-verified

118}
119
120function getCentroid(feature) {
121 const { type } = feature.geometry;
122 const projection = geoIdentity();
123 const geoPathGenerator = geoPath(projection);
124
125 if (type === 'MultiPolygon') {
126 let maxArea = -Infinity;
127
128 for (const coordinates of feature.geometry.coordinates) {
129 const polygon = { type: 'Polygon', coordinates };
130 const area = geoPathGenerator.area(polygon);
131 if (area > maxArea) {
132 maxArea = area;
133 feature = polygon;
134 }
135 }
136 }
137
138 return geoPathGenerator.centroid(feature).map((coord) => +coord.toFixed(2));
139}
140
141async function createCountriesLayer({ bounds, filter, name, resolution, source }) {
142 const inputFilePath = `${outputDirGeojson}/${unFilename}_${resolution}m/${source}.geojson`;

Callers 1

addCentroidsToGeojsonFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…