MarkerDatastore<T> class
abstract
Abstract base class for managing collections of map markers with dynamic loading capabilities.
A MarkerDatastore provides an interface for storing, retrieving, and managing markers that can be dynamically loaded based on the current map view. This enables efficient handling of large marker datasets by only loading markers relevant to the visible area.
Key Concepts
- Dynamic Loading: Markers are loaded based on zoom level and visible bounding box
- Change Notification: Extends ChangeNotifier to trigger UI updates when markers change
- Zoom-Aware: Different markers can be shown at different zoom levels
- Boundary-Based: Markers are queried based on geographic boundaries
- Generic Type Support: Supports typed markers via generic parameter
T
Lifecycle Methods
The overlay system calls these methods to manage marker loading:
- askChangeZoomlevel: Called when zoom level changes - opportunity to load/filter markers
- askChangeBoundingBox: Called when map moves - opportunity to load markers for new area
- askRetrieveMarkersToPaint: Called during rendering - returns markers to display
Implementation Strategy
Implementing classes should consider:
- Caching: Cache markers to avoid repeated loading
- Filtering: Filter markers by zoom level and bounding box for performance
- Clustering: Group nearby markers at lower zoom levels
- Lazy Loading: Load markers on-demand from databases or network sources
- Memory Management: Remove off-screen markers to control memory usage
Usage Example
class MyMarkerDatastore extends MarkerDatastore<String> {
final List<Marker<String>> _markers = [];
BoundingBox? _currentBounds;
int _currentZoom = -1;
@override
void askChangeZoomlevel(int zoomlevel, BoundingBox boundingBox, PixelProjection projection) {
_currentZoom = zoomlevel;
_currentBounds = boundingBox;
_loadMarkersForView();
}
@override
void askChangeBoundingBox(int zoomlevel, BoundingBox boundingBox) {
_currentBounds = boundingBox;
_loadMarkersForView();
}
@override
Iterable<Marker<String>> askRetrieveMarkersToPaint() {
return _markers.where((marker) => _isMarkerVisible(marker));
}
void _loadMarkersForView() {
// Load markers from database/API based on _currentBounds and _currentZoom
// Update _markers list
requestRepaint(); // Notify UI of changes
}
}
Performance Tips
- Implement efficient spatial indexing for marker queries
- Use marker clustering for high-density areas
- Cache marker data to minimize database/network requests
- Filter markers by zoom level to reduce rendering overhead
- Call requestRepaint only when markers actually change
See also:
- MarkerDatastoreOverlay for displaying markers from a datastore
- DefaultMarkerDatastore for a ready-to-use implementation
- SingleMarkerOverlay for displaying individual markers
- Mixed-in types
- Implementers
Constructors
- MarkerDatastore()
- Creates a new marker datastore.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- hasListeners → bool
-
Whether any listeners are currently registered.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
addListener(
VoidCallback listener) → void -
Register a closure to be called when the object changes.
inherited
-
addMarker(
Marker< T> marker) → void - Adds a single marker to the datastore.
-
addMarkers(
Iterable< Marker< markers) → voidT> > - Adds multiple markers to the datastore in a batch operation.
-
askChangeBoundingBox(
int zoomlevel, BoundingBox boundingBox) → void - Called when the map view moves to a new area at the same zoom level.
-
askChangeZoomlevel(
int zoomlevel, BoundingBox boundingBox, PixelProjection projection) → void - Called when the map zoom level changes.
-
askRetrieveMarkersToPaint(
) → Iterable< Marker< T> > - Returns the markers that should be rendered on the current screen.
-
clearMarkers(
) → void - Removes all markers from the datastore.
-
dispose(
) → void -
Disposes of the datastore and releases any held resources.
override
-
getTappedMarkers(
TapEvent event) → List< Marker< T> > - Returns markers that intersect with the given tap event area.
-
markerChanged(
Marker< T> marker) → void - Notifies the datastore that a marker's properties have changed.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
notifyListeners(
) → void -
Call all the registered listeners.
inherited
-
removeListener(
VoidCallback listener) → void -
Remove a previously registered closure from the list of closures that are
notified when the object changes.
inherited
-
removeMarker(
Marker< T> marker) → void - Removes a specific marker from the datastore.
-
requestRepaint(
) → void - Requests a repaint of the marker overlay.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited