elementHitTest method
bool
elementHitTest(
- CircleMarker<
R> element, { - required Offset point,
- required LatLng coordinate,
Method invoked by hitTest for every element (each of elements in reverse order) that requires testing
Not all elements will require testing. For example, testing is skipped if
a hit has already been found on another element, and the
HitDetectableElement.hitValue
is null
on this element.
Offset and coordinate
(MapCamera.screenOffsetToLatLng) are provided for simplicity.
Avoid performing calculations that are not dependent on element
. Instead,
override hitTest, store the necessary calculation results in
(late
non-null
able) members, and call super.hitTest(position)
at the
end. To calculate the camera origin in this way, instead mix in and use
FeatureLayerUtils.origin
.
Should return whether an element has been hit.
Implementation
@override
bool elementHitTest(
CircleMarker<R> element, {
required Offset point,
required LatLng coordinate,
}) {
final radius = _getRadiusInPixel(element, withBorder: true);
final initialCenter = _getOffset(element.point);
WorldWorkControl checkIfHit(double shift) {
final center = initialCenter + Offset(shift, 0);
if (!_isVisible(center: center, radiusInPixel: radius)) {
return WorldWorkControl.invisible;
}
return pow(point.dx - center.dx, 2) + pow(point.dy - center.dy, 2) <=
radius * radius
? WorldWorkControl.hit
: WorldWorkControl.visible;
}
return workAcrossWorlds(checkIfHit);
}