function focusOnCenterByIndex(index) {
try {
if (!window.markerList || index == null) return;
var marker = window.markerList[index];
if (!marker) return;
// use original data stored on the marker (centerData) to guarantee source coordinates
var latlng = null;
if (marker.centerData && marker.centerData.lat !== undefined && marker.centerData.lng !== undefined) {
latlng = [parseFloat(marker.centerData.lat), parseFloat(marker.centerData.lng)];
} else if (marker.getLatLng) {
latlng = marker.getLatLng();
}
if (!latlng) return;
// fly directly to the source coordinate at a reasonable zoom level
map.flyTo(latlng, 16, { animate: true, duration: 1.0 });
// after move ends, ensure the cluster is expanded to show the actual marker and open popup
map.once('moveend', function() {
try {
if (typeof markers.zoomToShowLayer === 'function') {
markers.zoomToShowLayer(marker, function() {
if (marker && marker.openPopup) marker.openPopup();
});
} else {
if (marker && marker.openPopup) marker.openPopup();
}
} catch (err) { console.warn('zoomToShowLayer error', err); }
});
} catch (err) {
console.warn('focusOnCenterByIndex error', err);
}
}