Skip to content

Commit e8df84f

Browse files
committed
[google_maps_flutter_web] Calculate marker anchor from image size if available
Uses the size info from the image configuration if available to convert the anchor from Flutter API unit coordinates to JS API pixels. flutter/flutter#80578
1 parent 44358bd commit e8df84f

File tree

1 file changed

+8
-4
lines changed
  • packages/google_maps_flutter/google_maps_flutter_web/lib/src

1 file changed

+8
-4
lines changed

packages/google_maps_flutter/google_maps_flutter_web/lib/src/convert.dart

+8-4
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,8 @@ gmaps.Size? _gmSizeFromIconConfig(List<Object?> iconConfig, int sizeIndex) {
244244
}
245245

246246
// Converts a [BitmapDescriptor] into a [gmaps.Icon] that can be used in Markers.
247-
gmaps.Icon? _gmIconFromBitmapDescriptor(BitmapDescriptor bitmapDescriptor) {
247+
gmaps.Icon? _gmIconFromBitmapDescriptor(
248+
BitmapDescriptor bitmapDescriptor, Offset anchor) {
248249
final List<Object?> iconConfig = bitmapDescriptor.toJson() as List<Object?>;
249250

250251
gmaps.Icon? icon;
@@ -279,7 +280,11 @@ gmaps.Icon? _gmIconFromBitmapDescriptor(BitmapDescriptor bitmapDescriptor) {
279280
}
280281
}
281282

282-
return icon;
283+
return icon
284+
?..anchor = icon.size == null
285+
? null
286+
: gmaps.Point(
287+
anchor.dx * icon.size!.width!, anchor.dy * icon.size!.height!);
283288
}
284289

285290
// Computes the options for a new [gmaps.Marker] from an incoming set of options
@@ -298,8 +303,7 @@ gmaps.MarkerOptions _markerOptionsFromMarker(
298303
..visible = marker.visible
299304
..opacity = marker.alpha
300305
..draggable = marker.draggable
301-
..icon = _gmIconFromBitmapDescriptor(marker.icon);
302-
// TODO(ditman): Compute anchor properly, otherwise infowindows attach to the wrong spot.
306+
..icon = _gmIconFromBitmapDescriptor(marker.icon, marker.anchor);
303307
// Flat and Rotation are not supported directly on the web.
304308
}
305309

0 commit comments

Comments
 (0)