sendAnnotationBackward method
void
sendAnnotationBackward(
- String annotationId
)
Implementation
void sendAnnotationBackward(String annotationId) {
final annotation = _annotations[annotationId];
if (annotation == null) return;
// Sort all annotations by z-index AND id to ensure consistent ordering
final sortedAnnotations = _annotations.values.toList()
..sort((a, b) {
final zComparison = a.zIndex.value.compareTo(b.zIndex.value);
return zComparison != 0 ? zComparison : a.id.compareTo(b.id);
});
// Always normalize z-indexes to sequential values first
for (int i = 0; i < sortedAnnotations.length; i++) {
sortedAnnotations[i].setZIndex(i);
}
// Find current annotation's position after normalization
final currentIndex = sortedAnnotations.indexOf(annotation);
// If not at the bottom, swap with next lower annotation
if (currentIndex > 0) {
final prevAnnotation = sortedAnnotations[currentIndex - 1];
// Simple swap of adjacent positions
annotation.setZIndex(currentIndex - 1);
prevAnnotation.setZIndex(currentIndex);
}
}