Skip to content

Commit 215d0db

Browse files
committed
Convert Glyph class to 3 different bitmap descriptor classes
1 parent 3a3cce1 commit 215d0db

File tree

15 files changed

+150
-120
lines changed

15 files changed

+150
-120
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
@@ -1545,7 +1545,7 @@ void googleMapsTests() {
15451545
icon: BitmapDescriptor.pinConfig(
15461546
backgroundColor: Colors.green,
15471547
borderColor: Colors.greenAccent,
1548-
glyph: Glyph.text('A', textColor: Colors.white),
1548+
glyph: const TextGlyph(text: 'A', textColor: Colors.white),
15491549
),
15501550
),
15511551
};

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
@@ -952,15 +952,30 @@ class GoogleMapsFlutterAndroid extends GoogleMapsFlutterPlatform {
952952
width: bytes.width,
953953
height: bytes.height));
954954
case final PinConfig pinConfig:
955-
final BitmapDescriptor? glyphBitmapDescriptor =
956-
pinConfig.glyph?.bitmapDescriptor;
955+
final AdvancedMarkerGlyph? glyph = pinConfig.glyph;
956+
Color? glyphColor;
957+
String? glyphText;
958+
Color? glyphTextColor;
959+
BitmapDescriptor? glyphBitmapDescriptor;
960+
if (glyph != null) {
961+
switch (glyph.runtimeType) {
962+
case final CircleGlyph circleGlyph:
963+
glyphColor = circleGlyph.color;
964+
case final TextGlyph textGlyph:
965+
glyphText = textGlyph.text;
966+
glyphTextColor = textGlyph.textColor;
967+
case final BitmapGlyph bitmapGlyph:
968+
glyphBitmapDescriptor = bitmapGlyph.bitmap;
969+
}
970+
}
971+
957972
return PlatformBitmap(
958973
bitmap: PlatformBitmapPinConfig(
959974
backgroundColor: pinConfig.backgroundColor?.value,
960975
borderColor: pinConfig.borderColor?.value,
961-
glyphColor: pinConfig.glyph?.color?.value,
962-
glyphText: pinConfig.glyph?.text,
963-
glyphTextColor: pinConfig.glyph?.textColor?.value,
976+
glyphColor: glyphColor?.value,
977+
glyphText: glyphText,
978+
glyphTextColor: glyphTextColor?.value,
964979
glyphBitmap: glyphBitmapDescriptor != null
965980
? platformBitmapFromBitmapDescriptor(glyphBitmapDescriptor)
966981
: 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
@@ -1391,7 +1391,7 @@ void main() {
13911391
icon: BitmapDescriptor.pinConfig(
13921392
backgroundColor: Colors.green,
13931393
borderColor: Colors.greenAccent,
1394-
glyph: Glyph.text('A', textColor: Colors.white),
1394+
glyph: const TextGlyph(text: 'A', textColor: Colors.white),
13951395
),
13961396
),
13971397
};

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)