-
Notifications
You must be signed in to change notification settings - Fork 3.8k
[google_maps_flutter_web] Fix AdvancedMarker anchors on web #11966
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -367,6 +367,35 @@ void _setIconAnchor({required gmaps.Size size, required Offset anchor, required | |||||||||||||||||||||||||||||||
| icon.anchor = gmapsAnchor; | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| String _advancedMarkerAnchorToCssOffset(double anchor) { | ||||||||||||||||||||||||||||||||
| final double percentage = -anchor * 100; | ||||||||||||||||||||||||||||||||
| if (percentage == percentage.roundToDouble()) { | ||||||||||||||||||||||||||||||||
| return '${percentage.toInt()}%'; | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| return '$percentage%'; | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
Comment on lines
+370
to
+376
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Floating-point multiplication (e.g., Using a small epsilon check when comparing the percentage to its rounded integer value will make the output cleaner and more robust against floating-point precision issues.
Suggested change
|
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| void _setAdvancedMarkerOptionsAnchor(gmaps.AdvancedMarkerElementOptions options, Offset anchor) { | ||||||||||||||||||||||||||||||||
| options | ||||||||||||||||||||||||||||||||
| ..setProperty('anchorLeft'.toJS, _advancedMarkerAnchorToCssOffset(anchor.dx).toJS) | ||||||||||||||||||||||||||||||||
| ..setProperty('anchorTop'.toJS, _advancedMarkerAnchorToCssOffset(anchor.dy).toJS); | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| void _copyAdvancedMarkerOptionsAnchor( | ||||||||||||||||||||||||||||||||
| gmaps.AdvancedMarkerElement marker, | ||||||||||||||||||||||||||||||||
| gmaps.AdvancedMarkerElementOptions options, | ||||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||||
| final JSAny? anchorLeft = options.getProperty('anchorLeft'.toJS); | ||||||||||||||||||||||||||||||||
| if (anchorLeft != null) { | ||||||||||||||||||||||||||||||||
| marker.setProperty('anchorLeft'.toJS, anchorLeft); | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| final JSAny? anchorTop = options.getProperty('anchorTop'.toJS); | ||||||||||||||||||||||||||||||||
| if (anchorTop != null) { | ||||||||||||||||||||||||||||||||
| marker.setProperty('anchorTop'.toJS, anchorTop); | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| // Sets the size of the Google Maps icon. | ||||||||||||||||||||||||||||||||
| void _setIconSize({required gmaps.Size size, required gmaps.Icon icon}) { | ||||||||||||||||||||||||||||||||
| final gmapsSize = gmaps.Size(size.width, size.height); | ||||||||||||||||||||||||||||||||
|
|
@@ -705,6 +734,7 @@ Future<O> _markerOptionsFromMarker<T, O>(Marker marker, T? currentMarker) async | |||||||||||||||||||||||||||||||
| ..title = sanitizeHtml(marker.infoWindow.title ?? '') | ||||||||||||||||||||||||||||||||
| ..zIndex = marker.zIndex | ||||||||||||||||||||||||||||||||
| ..gmpDraggable = marker.draggable; | ||||||||||||||||||||||||||||||||
| _setAdvancedMarkerOptionsAnchor(options, marker.anchor); | ||||||||||||||||||||||||||||||||
| return options as O; | ||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||
| final options = gmaps.MarkerOptions() | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this using unsafe dynamic lookup? If there are properties that aren't reflected in
google_maps, they should be added upstream, rather than bypassing the wrapper.