hit method
Implementation
Marker? hit(
List<Marker> markers,
Offset offset, {
Key? preferKey,
bool Function(Key?)? isActiveKey,
}) {
if (markers.isEmpty) return null;
// 1. Check preferred key
if (preferKey != null) {
final prefer = markers.findByKeyOrNull(preferKey);
if (prefer != null &&
prefer.inPixelsBounds(cam, offset,
options: options, active: isActiveKey?.call(prefer.key))) {
return prefer;
}
}
// 2. Prepare candidates
Set<Key>? candidateKeys;
if (index != null) {
const double margin = 120.0;
final bounds = _createHitBounds(offset, margin);
candidateKeys =
index!.query(bounds).map((m) => m.key).whereType<Key>().toSet();
if (candidateKeys.isEmpty) return null;
}
// 3. Iterate in Z-order (reversed)
for (final m in markers.reversed) {
if (candidateKeys != null && !candidateKeys.contains(m.key)) continue;
if (m.inPixelsBounds(cam, offset,
options: options, active: isActiveKey?.call(m.key))) {
return m;
}
}
return null;
}