pukaad-ui-lib 1.281.0 → 1.282.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/module.json
CHANGED
|
@@ -118,6 +118,29 @@ watch(
|
|
|
118
118
|
drawDebounceTimer = setTimeout(() => drawPolygon(), 80);
|
|
119
119
|
}
|
|
120
120
|
);
|
|
121
|
+
const getPolygonCentroid = (feature) => {
|
|
122
|
+
if (!feature?.geometry) return null;
|
|
123
|
+
const type = feature.geometry.type;
|
|
124
|
+
let coords = null;
|
|
125
|
+
if (type === "Polygon") {
|
|
126
|
+
coords = feature.geometry.coordinates[0];
|
|
127
|
+
} else if (type === "MultiPolygon") {
|
|
128
|
+
let maxLen = 0;
|
|
129
|
+
for (const poly of feature.geometry.coordinates) {
|
|
130
|
+
if (poly[0].length > maxLen) {
|
|
131
|
+
maxLen = poly[0].length;
|
|
132
|
+
coords = poly[0];
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
if (!coords || coords.length === 0) return null;
|
|
137
|
+
let sumLat = 0, sumLng = 0;
|
|
138
|
+
for (const [lng, lat] of coords) {
|
|
139
|
+
sumLat += lat;
|
|
140
|
+
sumLng += lng;
|
|
141
|
+
}
|
|
142
|
+
return { lat: sumLat / coords.length, lng: sumLng / coords.length };
|
|
143
|
+
};
|
|
121
144
|
const drawPolygon = async () => {
|
|
122
145
|
if (!map || !L) return;
|
|
123
146
|
if (polygonLayer) {
|
|
@@ -154,13 +177,14 @@ const drawPolygon = async () => {
|
|
|
154
177
|
}
|
|
155
178
|
}).addTo(map);
|
|
156
179
|
map.flyToBounds(polygonLayer.getBounds(), { padding: [20, 20], duration: 0.5 });
|
|
157
|
-
const center = polygonLayer.getBounds().getCenter();
|
|
180
|
+
const center = getPolygonCentroid(feature) ?? polygonLayer.getBounds().getCenter();
|
|
158
181
|
const divIcon = L.divIcon({
|
|
159
182
|
html: mapPinSvg,
|
|
160
183
|
className: "",
|
|
161
184
|
// Remove default leaflet background
|
|
162
185
|
iconSize: [32, 32],
|
|
163
|
-
iconAnchor: [16,
|
|
186
|
+
iconAnchor: [16, 16]
|
|
187
|
+
// center of icon aligns with coordinate
|
|
164
188
|
});
|
|
165
189
|
marker = L.marker(center, {
|
|
166
190
|
icon: divIcon
|
package/package.json
CHANGED
|
File without changes
|