diff --git a/map.html b/map.html
index f811224..8baeb07 100644
--- a/map.html
+++ b/map.html
@@ -261,7 +261,11 @@
if (!feature || !feature.geometry) {
return;
}
- const labelPoint = turf.pointOnFeature(feature);
+ // use center of mass when possible so labels stay visually centered
+ let labelPoint = turf.centerOfMass(feature);
+ if (!turf.booleanPointInPolygon(labelPoint, feature)) {
+ labelPoint = turf.pointOnFeature(feature);
+ }
const [lng, lat] = labelPoint.geometry.coordinates;
L.marker([lat, lng], {
icon: L.divIcon({