SpatialIndex<T> class
A generic spatial index for fast 2D range queries on geographical coordinates.
Uses a spatial hashing technique to bin items into cells based on their LatLngBounds.
This allows O(1) average time complexity for querying items in a specific area,
drastically optimizing hit testing and visibility checks for large datasets.
It works in "World Space" (LatLng), making it independent of zoom level and screen size.
Constructors
- SpatialIndex({double cellSize = 0.1})
Properties
- cellSize → double
-
Cell size in degrees (latitude/longitude).
A value of 0.1 corresponds roughly to 11km at the equator.
Adjust based on the expected density and size of items.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- length → int
-
Returns the number of items in the index.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
add(
Key key, T item, LatLngBounds bounds) → void - Adds or updates an item in the index.
-
clear(
) → void - Clears the entire index.
-
contains(
Key key) → bool - Returns true if the index contains the given key.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
query(
LatLngBounds queryBounds) → Iterable< T> -
Returns all items whose bounds overlap with the given
queryBounds. -
remove(
Key key) → void - Removes an item from the index.
-
toString(
) → String -
A string representation of this object.
inherited
-
update(
Key key, T item, LatLngBounds oldBounds, LatLngBounds newBounds) → void - Optimised update when old bounds are known (avoids internal lookup).
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited