For the complete documentation index, see llms.txt. This page is also available as Markdown.

Marker Layer

You can add single point features - including arbitrary widgets - to maps using MarkerLayer and Markers.

A variety of Markers on a rotated map

Size

The height and width parameters are required to enable the positioning and culling of the markers to work correctly.

The marker child will be sized to these parameters, which default to 30 logical pixels. If the child will change size, set the size to the largest size and control the size of the child within a widget which allows it to be smaller than the constraints set.

Alignment & Counter-Rotation

By default, the marker's child is centered over the point, and will always remain upright relative to the North when the map is rotated.

This can be changed using alignment and rotate.

To keep the child upright relative to the screen (counter-rotate it compared to any map rotation), set rotate to true.

To change the pivot point for the counter-rotation and the alignment of the child to the point, set the alignment accordingly.

For example:

These parameters can also be set directly on the MarkerLayer to change the default for all of its markers.

There is no built-in support to rotate markers to a specific degree. However, this is easy to implement through a rotating widget, such as Transform.rotate.

Handling State

Often, marker children do not have their own internal state (they are StatelessWidgets). However, some use-cases may require them to be stateful.

Marker children should not be StatefulWidgets, and keys should not be used in the child's tree. Instead, the state should be detached and moved up in the tree, using an inherited approach. For example, a state management package, or Flutter's built-in options like InheritedWidget or ValueNotifier - remember that FlutterMap.children can contain widgets wrapped around layers like this.

Then, some map should be kept linking a unique property of the marker (its point could be suitable and easily accessed in most dynamic marker layer systems) to its state. The marker child can then lookup this state.

For example:

The maintainer team is looking into improving the MarkerLayer to improve this situation:

  • Providing a keepAlive option directly on Markers - although this means culled markers still need to be built (although not necessarily painted), which could be expensive compared to the solution above (which requires more boilerplate but should scale better)

  • Painting a marker multiple times across worlds while only building it once - although this is fairly complicated, but in combination with the option above could eventually allow the Marker size parameters to become unnecessary/optional

Any contributors would be appreciated, although the second point is quite complicated to implement!

Handling Gestures

If you need to, for example, handle taps and presses on your marker's child, it's easy! Just wrap the child in something like a GestureDetector, or a button.

If you need to be able to drag the marker, check out the community maintained plugin 'flutter_map_dragmarker'. Alternatively if you need more control, build it yourself. Because of the way flutter_map handles gestures, the following workaround may be required to allow the marker to capture the necessary gesture events:

Use a RawGestureDetector and custom PanGestureRecognizer than declares victory in the gesture arena. For example:

Last updated

Was this helpful?