addMarkerPoint method
Adds a marker marker to the map and animates it between points.
markerId: A unique identifier for the marker.markerImage: The path to the image file to be used as the marker icon.data: A list of position and rotation data for the marker animation {position:double, double, rotation: double}[].properties: (Optional) Custom properties for marker style.scale: (optional) A scale factor for the image.
Implementation
Future<void> addMarkerPoint(
String markerId,
String markerImage,
List<Map<String, dynamic>> data, {
double scale = 15,
Map<String, dynamic> properties = const {
"icon-opacity": 1.0,
"icon-size": 1.0,
"icon-anchor": "center",
"icon-offset": [0.5, 0.5],
'icon-allow-overlap': true,
'icon-ignore-placement': true,
},
}) async {
try {
// Store marker points (positions and rotations).
markerPoints.putIfAbsent(markerId, () => []);
for (var data in data) {
Point newPoint = Point(coordinates: Position(data['position'][0], data['position'][1]));
num rotation = data['rotation'];
markerPoints[markerId]?.add({'point': newPoint, 'rotation': rotation});
}
// Initialize the marker stream if it doesn't exist.
if (!_locationStreamControllers.containsKey(markerId) && markerPoints[markerId]!.length > 2) {
await _initializeMarkerStreams(
markerId: markerId,
markerImage: markerImage,
properties: properties,
scale: scale,
);
}
// Trigger the stream to start the animation.
_locationStreamControllers[markerId]?.add("animate");
} on Exception catch (_) {
rethrow;
}
}