-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathbitmap.dart
61 lines (55 loc) · 2.09 KB
/
bitmap.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
part of '../platform_maps_flutter.dart';
/// Defines a bitmap image. For a marker, this class can be used to set the
/// image of the marker icon. For a ground overlay, it can be used to set the
/// image to place on the surface of the earth.
class BitmapDescriptor {
final dynamic bitmapDescriptor;
BitmapDescriptor._(this.bitmapDescriptor);
/// Creates a BitmapDescriptor that refers to the default marker image.
static BitmapDescriptor? get defaultMarker {
if (Platform.isIOS) {
return BitmapDescriptor._(apple_maps.BitmapDescriptor.defaultAnnotation);
} else if (Platform.isAndroid) {
return BitmapDescriptor._(google_maps.BitmapDescriptor.defaultMarker);
}
return null;
}
/// Creates a [BitmapDescriptor] from an asset image.
/// Asset images in flutter are stored per: https://flutter.dev/docs/development/ui/assets-and-images#declaring-resolution-aware-image-assets
///
/// This method takes into consideration various asset resolutions and scales the images to the right resolution depending on the dpi.
///
/// Don't forget to rebuild the map with the new Icons if it was already build.
static Future<BitmapDescriptor> fromAssetImage(
ImageConfiguration configuration,
String assetName, {
AssetBundle? bundle,
String? package,
}) async {
dynamic bitmap;
if (Platform.isIOS) {
bitmap = await apple_maps.BitmapDescriptor.fromAssetImage(
configuration,
assetName,
bundle: bundle,
package: package,
);
} else if (Platform.isAndroid) {
bitmap = await google_maps.BitmapDescriptor.fromAssetImage(
configuration,
assetName,
bundle: bundle,
package: package,
);
}
return BitmapDescriptor._(bitmap);
}
/// Creates a BitmapDescriptor using an array of bytes that must be encoded
/// as PNG.
static BitmapDescriptor fromBytes(Uint8List byteData) {
var bitmap = Platform.isAndroid
? google_maps.BitmapDescriptor.fromBytes(byteData)
: apple_maps.BitmapDescriptor.fromBytes(byteData);
return BitmapDescriptor._(bitmap);
}
}