> For the complete documentation index, see [llms.txt](https://docs.fleaflet.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.fleaflet.dev/v7/layers/layer-interactivity/hit-testing-behaviour.md).

# Hit Testing Behaviour

The behaviour of hit testing can be confusing at first. These rules define how hit testing usually behaves:

1. Gesture callbacks in `MapOptions` are always invoked, no matter what is within the layers or the result of `hitTest`s in those layers, with the exception of custom defined hit test behaviours (not those layers that support interactivity, see [Layer Interactivity](/v7/layers/layer-interactivity.md)), such as applying `GestureDetector`s around `Marker.child`ren

{% hint style="warning" %}
`GestureDetector`s absorb hit tests, and so corresponding callbacks in `MapOptions` will not be invoked if they are defined/invoked in the `GestureDetector`.

Workarounds to resolve this are discussed below.
{% endhint %}

2. Hit testing is always\* performed on the interactable layers (see [Layer Interactivity](/v7/layers/layer-interactivity.md)) even if they have not been set-up for interactivity: hit testing != interactivity
3. Non-interactable layers (such as [Overlay Image Layer](/v7/layers/overlay-image-layer.md)) have no defined `hitTest`, and behaviour is situation dependent
4. A successful hit test (`true`) from an interactable layer will prevent hit testing on layers below it in the `children` stack

To change this behviour, make use of these three widgets, wrapping them around layers when and as necessary:

* [`IgnorePointer`](https://api.flutter.dev/flutter/widgets/IgnorePointer-class.html)
* [`AbsorbPointer`](https://api.flutter.dev/flutter/widgets/AbsorbPointer-class.html)
* `TranslucentPointer`: a general purpose 'widget' included with flutter\_map that allows the child to hit test as normal, but also allows widgets beneath it to hit test as normal, both seperately

***

For example, a marker with a `GestureDetector` child that detects taps beneath a `Polyline` will not detect a tap, no matter if the `PolylineLayer` has a defined `hitNotifier` or the `Polyline` has a defined `hitValue`. A defined `onTap` callback in `MapOptions` would be called however. If the `Marker` were no longer obscured by the `Polyline`, it's `onTap` callback would be fired instead of the one defined in `MapOptions`.

However, this behaviour could be changed by wrapping the `PolylineLayer` with a `TranslucentPointer`. This would allow interacitivity to function as normal, but also allow the `Marker` beneath to have it's `onTap` callback fired. Further wrapping another `TransclucentPointer` around the `MarkerLayer` would allow all 3 detections to function.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.fleaflet.dev/v7/layers/layer-interactivity/hit-testing-behaviour.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
