MarkerDatastoreOverlay class

A Flutter widget overlay that renders markers from a MarkerDatastore on a map.

This overlay provides an efficient way to display large numbers of markers by:

  • Automatically managing marker visibility based on zoom level and viewport
  • Caching marker queries to minimize datastore requests
  • Using intelligent bounding box extension to reduce query frequency
  • Integrating with the map's transformation system for smooth rendering

The overlay works by:

  1. Listening to map position changes via MapModel.positionStream
  2. Calculating the visible screen area as a BoundingBox
  3. Extending the bounding box by extendMargin to create a buffer zone
  4. Requesting markers from the datastore only when needed
  5. Rendering markers using MarkerDatastorePainter with proper transformations

Performance Optimizations

  • Zoom Level Caching: Avoids redundant datastore queries at the same zoom level
  • Bounding Box Extension: Uses extendMargin to create a buffer, reducing queries during small map movements
  • Conditional Updates: Only updates markers when the view moves outside the cached bounding box
  • Transform Integration: Leverages TransformWidget for efficient coordinate transformations

Usage Example

// Create a marker datastore
final markerDatastore = DefaultMarkerDatastore();
markerDatastore.addMarker(PoiMarker(
  position: LatLong(52.5200, 13.4050), // Berlin
  displayName: 'Berlin',
));

// Add overlay to map
Stack(
  children: [
    MapsforgeView(mapModel: mapModel),
    MarkerDatastoreOverlay(
      mapModel: mapModel,
      datastore: markerDatastore,
      zoomlevelRange: ZoomlevelRange(5, 18),
      extendMargin: 1.5, // 50% buffer around visible area
    ),
  ],
)

Best Practices

  • Use extendMargin values between 1.2-2.0 for optimal performance
  • Implement efficient marker filtering in your datastore based on zoom level
  • Consider marker clustering for high-density datasets
  • Use appropriate ZoomlevelRange to control marker visibility

See also:

Inheritance

Constructors

MarkerDatastoreOverlay({Key? key, required MapModel mapModel, required MarkerDatastore datastore, required ZoomlevelRange zoomlevelRange, double extendMargin = 1.5})
Creates a marker datastore overlay.
const

Properties

datastore MarkerDatastore
The marker datastore containing the markers to be displayed.
final
extendMargin double
Margin factor to extend the visible bounding box for marker queries.
final
hashCode int
The hash code for this object.
no setterinherited
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
mapModel MapModel
The map model providing position updates and coordinate transformations.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
zoomlevelRange → ZoomlevelRange
The zoom level range in which markers should be visible.
final

Methods

createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() State<MarkerDatastoreOverlay>
Creates the mutable state for this widget at a given location in the tree.
override
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) String
A string representation of this object.
inherited
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) String
Returns a string representation of this node and its descendants.
inherited
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a one-line detailed description of the object.
inherited
toStringShort() String
A short, textual description of this widget.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited