addImageMarkers method
Add a Marker Group to the Map
imagePath
is the path to the image asset, allow only image in png
, jpeg
, jpg
format
Implementation
Future<List<NavigationMarker>> addImageMarkers(
List<NavigationMarker> markers) async {
List<Map<String, dynamic>> markerList = [];
await Future.forEach(markers, (NavigationMarker marker) async {
try {
ByteData data = await rootBundle.load(marker.imagePath);
var jsonData = marker.toJson();
if (Platform.isAndroid) {
var bytes =
data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes);
jsonData['imageBytes'] = bytes;
} else if (Platform.isIOS) {
var base64String = base64Encode(
data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes));
jsonData['imageBase64'] = base64String;
}
markerList.add(jsonData);
} catch (e) {
debugPrint(e.toString());
}
});
var i = 0;
var markerMap = {for (var e in markerList) i++: e};
List<Object?> listMarkerId = await _methodChannel.invokeMethod(
MethodChannelEvent.addMarkers, markerMap);
if (listMarkerId.isNotEmpty) {
for (var element in markers) {
element.markerId = listMarkerId[markers.indexOf(element)] as int?;
}
return markers;
} else {
return [];
}
}