Skip to content

Commit b3c310e

Browse files
committed
fix chart component: no crash when o marker
1 parent 541053f commit b3c310e

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

sqlpage/sqlpage.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,13 @@ function sqlpage_map() {
181181
if (first_map && is_leaflet_loaded) {
182182
onLeafletLoad();
183183
}
184+
/**
185+
*
186+
* @param {string|undefined} coords
187+
* @returns {[number, number] | undefined}
188+
*/
184189
function parseCoords(coords) {
185-
return coords?.split(",").map((c) => Number.parseFloat(c));
190+
return coords?.split(",", 2).map((c) => Number.parseFloat(c));
186191
}
187192
function onLeafletLoad() {
188193
is_leaflet_loaded = true;
@@ -201,14 +206,15 @@ function sqlpage_map() {
201206
setTimeout(addMarker, 0, marker_elem, map);
202207
}
203208
setTimeout(() => {
204-
if (center == null && map._sqlpage_markers.length) {
205-
map.fitBounds(
206-
map._sqlpage_markers.map((m) =>
207-
m.getLatLng ? m.getLatLng() : m.getBounds(),
208-
),
209-
);
209+
if (center) map.setView(center, +zoom);
210+
else {
211+
const markerBounds = (m) =>
212+
m.getLatLng ? m.getLatLng() : m.getBounds();
213+
const bounds = map._sqlpage_markers.map(markerBounds);
214+
if (bounds.length > 0) map.fitBounds(bounds);
215+
else map.setView([51.505, 10], +zoom);
210216
if (zoom != null) map.setZoom(+zoom);
211-
} else map.setView(center, +zoom);
217+
}
212218
}, 100);
213219
m.removeAttribute("data-pre-init");
214220
m.getElementsByClassName("spinner-border")[0]?.remove();

0 commit comments

Comments
 (0)