Skip to content

Commit ea564e9

Browse files
committed
Convert Glyph class to 3 different bitmap descriptor classes
1 parent 0473454 commit ea564e9

File tree

14 files changed

+150
-119
lines changed

14 files changed

+150
-119
lines changed

packages/google_maps_flutter/google_maps_flutter/example/lib/advanced_markers_clustering.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class _AdvancedMarkerClusteringBody extends ClusteringBody {
5555
icon: BitmapDescriptor.pinConfig(
5656
backgroundColor: Colors.white,
5757
borderColor: Colors.blue,
58-
glyph: Glyph.color(Colors.blue),
58+
glyph: const CircleGlyph(color: Colors.blue),
5959
),
6060
);
6161
}
@@ -68,12 +68,12 @@ class _AdvancedMarkerClusteringBody extends ClusteringBody {
6868
? BitmapDescriptor.pinConfig(
6969
backgroundColor: Colors.blue,
7070
borderColor: Colors.white,
71-
glyph: Glyph.color(Colors.white),
71+
glyph: const CircleGlyph(color: Colors.white),
7272
)
7373
: BitmapDescriptor.pinConfig(
7474
backgroundColor: Colors.white,
7575
borderColor: Colors.blue,
76-
glyph: Glyph.color(Colors.blue),
76+
glyph: const CircleGlyph(color: Colors.blue),
7777
),
7878
);
7979
}

packages/google_maps_flutter/google_maps_flutter/example/lib/place_advanced_marker.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class _PlaceAdvancedMarkerBodyState extends PlaceMarkerBodyState {
6868
return BitmapDescriptor.pinConfig(
6969
backgroundColor: isSelected ? Colors.blue : Colors.white,
7070
borderColor: isSelected ? Colors.white : Colors.blue,
71-
glyph: Glyph.color(isSelected ? Colors.white : Colors.blue),
71+
glyph: CircleGlyph(color: isSelected ? Colors.white : Colors.blue),
7272
);
7373
}
7474

packages/google_maps_flutter/google_maps_flutter_android/example/integration_test/google_maps_tests.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2048,7 +2048,7 @@ void googleMapsTests() {
20482048
icon: BitmapDescriptor.pinConfig(
20492049
backgroundColor: Colors.green,
20502050
borderColor: Colors.greenAccent,
2051-
glyph: Glyph.text('A', textColor: Colors.white),
2051+
glyph: const TextGlyph(text: 'A', textColor: Colors.white),
20522052
),
20532053
),
20542054
};

packages/google_maps_flutter/google_maps_flutter_android/example/lib/advanced_markers_clustering.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class _AdvancedMarkerClusteringBody extends ClusteringBody {
5050
icon: BitmapDescriptor.pinConfig(
5151
backgroundColor: Colors.white,
5252
borderColor: Colors.blue,
53-
glyph: Glyph.color(Colors.blue),
53+
glyph: const CircleGlyph(color: Colors.blue),
5454
),
5555
);
5656
}
@@ -63,12 +63,12 @@ class _AdvancedMarkerClusteringBody extends ClusteringBody {
6363
? BitmapDescriptor.pinConfig(
6464
backgroundColor: Colors.blue,
6565
borderColor: Colors.white,
66-
glyph: Glyph.color(Colors.white),
66+
glyph: const CircleGlyph(color: Colors.white),
6767
)
6868
: BitmapDescriptor.pinConfig(
6969
backgroundColor: Colors.white,
7070
borderColor: Colors.blue,
71-
glyph: Glyph.color(Colors.blue),
71+
glyph: const CircleGlyph(color: Colors.blue),
7272
),
7373
);
7474
}

packages/google_maps_flutter/google_maps_flutter_android/example/lib/place_advanced_marker.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class _PlaceAdvancedMarkerBodyState extends PlaceMarkerBodyState {
6464
return BitmapDescriptor.pinConfig(
6565
backgroundColor: isSelected ? Colors.blue : Colors.white,
6666
borderColor: isSelected ? Colors.white : Colors.blue,
67-
glyph: Glyph.color(isSelected ? Colors.white : Colors.blue),
67+
glyph: CircleGlyph(color: isSelected ? Colors.white : Colors.blue),
6868
);
6969
}
7070

packages/google_maps_flutter/google_maps_flutter_android/lib/src/google_maps_flutter_android.dart

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,15 +1023,30 @@ class GoogleMapsFlutterAndroid extends GoogleMapsFlutterPlatform {
10231023
width: bytes.width,
10241024
height: bytes.height));
10251025
case final PinConfig pinConfig:
1026-
final BitmapDescriptor? glyphBitmapDescriptor =
1027-
pinConfig.glyph?.bitmapDescriptor;
1026+
final AdvancedMarkerGlyph? glyph = pinConfig.glyph;
1027+
Color? glyphColor;
1028+
String? glyphText;
1029+
Color? glyphTextColor;
1030+
BitmapDescriptor? glyphBitmapDescriptor;
1031+
if (glyph != null) {
1032+
switch (glyph.runtimeType) {
1033+
case final CircleGlyph circleGlyph:
1034+
glyphColor = circleGlyph.color;
1035+
case final TextGlyph textGlyph:
1036+
glyphText = textGlyph.text;
1037+
glyphTextColor = textGlyph.textColor;
1038+
case final BitmapGlyph bitmapGlyph:
1039+
glyphBitmapDescriptor = bitmapGlyph.bitmap;
1040+
}
1041+
}
1042+
10281043
return PlatformBitmap(
10291044
bitmap: PlatformBitmapPinConfig(
10301045
backgroundColor: pinConfig.backgroundColor?.value,
10311046
borderColor: pinConfig.borderColor?.value,
1032-
glyphColor: pinConfig.glyph?.color?.value,
1033-
glyphText: pinConfig.glyph?.text,
1034-
glyphTextColor: pinConfig.glyph?.textColor?.value,
1047+
glyphColor: glyphColor?.value,
1048+
glyphText: glyphText,
1049+
glyphTextColor: glyphTextColor?.value,
10351050
glyphBitmap: glyphBitmapDescriptor != null
10361051
? platformBitmapFromBitmapDescriptor(glyphBitmapDescriptor)
10371052
: null,

packages/google_maps_flutter/google_maps_flutter_ios/example/ios14/integration_test/google_maps_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1890,7 +1890,7 @@ void main() {
18901890
icon: BitmapDescriptor.pinConfig(
18911891
backgroundColor: Colors.green,
18921892
borderColor: Colors.greenAccent,
1893-
glyph: Glyph.text('A', textColor: Colors.white),
1893+
glyph: const TextGlyph(text: 'A', textColor: Colors.white),
18941894
),
18951895
),
18961896
};

packages/google_maps_flutter/google_maps_flutter_ios/example/shared/maps_example_dart/lib/advanced_markers_clustering.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class _AdvancedMarkerClusteringBody extends ClusteringBody {
5555
icon: BitmapDescriptor.pinConfig(
5656
backgroundColor: Colors.white,
5757
borderColor: Colors.blue,
58-
glyph: Glyph.color(Colors.blue),
58+
glyph: const CircleGlyph(color: Colors.blue),
5959
),
6060
);
6161
}
@@ -68,12 +68,12 @@ class _AdvancedMarkerClusteringBody extends ClusteringBody {
6868
? BitmapDescriptor.pinConfig(
6969
backgroundColor: Colors.blue,
7070
borderColor: Colors.white,
71-
glyph: Glyph.color(Colors.white),
71+
glyph: const CircleGlyph(color: Colors.white),
7272
)
7373
: BitmapDescriptor.pinConfig(
7474
backgroundColor: Colors.white,
7575
borderColor: Colors.blue,
76-
glyph: Glyph.color(Colors.blue),
76+
glyph: const CircleGlyph(color: Colors.blue),
7777
),
7878
);
7979
}

packages/google_maps_flutter/google_maps_flutter_ios/example/shared/maps_example_dart/lib/place_advanced_marker.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class _PlaceAdvancedMarkerBodyState extends PlaceMarkerBodyState {
6767
return BitmapDescriptor.pinConfig(
6868
backgroundColor: isSelected ? Colors.blue : Colors.white,
6969
borderColor: isSelected ? Colors.white : Colors.blue,
70-
glyph: Glyph.color(isSelected ? Colors.white : Colors.blue),
70+
glyph: CircleGlyph(color: isSelected ? Colors.white : Colors.blue),
7171
);
7272
}
7373

packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/bitmap.dart

Lines changed: 80 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ import 'package:flutter/material.dart'
1717
createLocalImageConfiguration;
1818
import 'package:flutter/services.dart' show AssetBundle;
1919

20-
import 'glyph.dart';
21-
2220
/// Type of bitmap scaling to use on BitmapDescriptor creation.
2321
enum MapBitmapScaling {
2422
/// Automatically scale image with devices pixel ratio or to given size,
@@ -351,7 +349,7 @@ abstract class BitmapDescriptor {
351349
static BitmapDescriptor pinConfig({
352350
Color? backgroundColor,
353351
Color? borderColor,
354-
Glyph? glyph,
352+
AdvancedMarkerGlyph? glyph,
355353
}) {
356354
return PinConfig(
357355
backgroundColor: backgroundColor,
@@ -1049,14 +1047,14 @@ class PinConfig extends BitmapDescriptor {
10491047
/// The type of the MapBitmap object, used for the JSON serialization.
10501048
static const String type = 'pinConfig';
10511049

1052-
/// The background color of the pin
1050+
/// The background color of the pin.
10531051
final Color? backgroundColor;
10541052

1055-
/// The border color of the pin
1053+
/// The border color of the pin.
10561054
final Color? borderColor;
10571055

1058-
/// The glyph that is displayed on the pin marker
1059-
final Glyph? glyph;
1056+
/// The glyph that is displayed on the pin marker.
1057+
final AdvancedMarkerGlyph? glyph;
10601058

10611059
@override
10621060
Object toJson() => <Object>[
@@ -1065,12 +1063,81 @@ class PinConfig extends BitmapDescriptor {
10651063
if (backgroundColor != null)
10661064
'backgroundColor': backgroundColor?.value,
10671065
if (borderColor != null) 'borderColor': borderColor?.value,
1068-
if (glyph?.text != null) 'glyphText': glyph?.text,
1069-
if (glyph?.textColor != null)
1070-
'glyphTextColor': glyph?.textColor?.value,
1071-
if (glyph?.color != null) 'glyphColor': glyph?.color?.value,
1072-
if (glyph?.bitmapDescriptor != null)
1073-
'glyphBitmapDescriptor': glyph?.bitmapDescriptor?.toJson(),
1066+
if (glyph != null) 'glyph': glyph?.toJson(),
1067+
}
1068+
];
1069+
}
1070+
1071+
/// Defines a glyph (the element at the center of an [AdvancedMarker] icon).
1072+
abstract class AdvancedMarkerGlyph extends BitmapDescriptor {
1073+
const AdvancedMarkerGlyph._() : super._();
1074+
}
1075+
1076+
/// Defines a glyph using the default circle, but with a custom color.
1077+
class CircleGlyph extends AdvancedMarkerGlyph {
1078+
/// Constructs a glyph instance, using the default circle, but with
1079+
/// a custom color.
1080+
const CircleGlyph({
1081+
required this.color,
1082+
}) : super._();
1083+
1084+
/// Color of the circular icon.
1085+
final Color color;
1086+
1087+
@override
1088+
Object toJson() => <Object>[
1089+
'circleGlyph',
1090+
<String, Object>{
1091+
'color': color.value,
10741092
}
10751093
];
10761094
}
1095+
1096+
/// Defines a glyph instance with a specified bitmap.
1097+
class BitmapGlyph extends AdvancedMarkerGlyph {
1098+
/// Constructs a glyph with the specified [bitmap].
1099+
const BitmapGlyph({
1100+
required this.bitmap,
1101+
}) : assert(
1102+
bitmap is! AdvancedMarkerGlyph,
1103+
'BitmapDescriptor cannot be an AdvancedMarkerGlyph.',
1104+
),
1105+
super._();
1106+
1107+
/// Bitmap image to be displayed in the center of the glyph.
1108+
final BitmapDescriptor bitmap;
1109+
1110+
@override
1111+
Object toJson() => <Object>[
1112+
'bitmapGlyph',
1113+
<String, Object>{
1114+
'bitmap': bitmap.toJson(),
1115+
}
1116+
];
1117+
}
1118+
1119+
/// Defines a glyph instance with a specified text and color.
1120+
class TextGlyph extends AdvancedMarkerGlyph {
1121+
/// Constructs a glyph with the specified [text] and [textColor].
1122+
const TextGlyph({
1123+
required this.text,
1124+
required this.textColor,
1125+
}) : super._();
1126+
1127+
/// Text to be displayed in the glyph.
1128+
final String text;
1129+
1130+
/// Color of the text.
1131+
final Color? textColor;
1132+
1133+
@override
1134+
Object toJson() {
1135+
return <Object>[
1136+
'textGlyph',
1137+
<String, Object>{
1138+
'text': text,
1139+
if (textColor != null) 'textColor': textColor!.value,
1140+
}
1141+
];
1142+
}
1143+
}

0 commit comments

Comments
 (0)