bringAnnotationForward method
void
bringAnnotationForward(
- String annotationId
)
Implementation
void bringAnnotationForward(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.compareTo(b.zIndex);
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].zIndex = i;
}
// Find current annotation's position after normalization
final currentIndex = sortedAnnotations.indexOf(annotation);
// If not at the top, swap with next higher annotation
if (currentIndex < sortedAnnotations.length - 1) {
final nextAnnotation = sortedAnnotations[currentIndex + 1];
// Simple swap of adjacent positions
annotation.zIndex = currentIndex + 1;
nextAnnotation.zIndex = currentIndex;
}
}