bringAnnotationForward method

void bringAnnotationForward(
  1. 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.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 top, swap with next higher annotation
  if (currentIndex < sortedAnnotations.length - 1) {
    final nextAnnotation = sortedAnnotations[currentIndex + 1];
    // Simple swap of adjacent positions
    annotation.setZIndex(currentIndex + 1);
    nextAnnotation.setZIndex(currentIndex);
  }
}