-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[google_maps_flutter] Custom marker size improvements #6805
[google_maps_flutter] Custom marker size improvements #6805
Conversation
final ui.Codec codec = | ||
await ui.webOnlyInstantiateImageCodecFromUrl(Uri.parse(assetUrl)); |
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.
I like this new approach, but I don't think this works in the html
renderer?
(Compare to canvaskit.)
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.
True, and this also decodes the entire image frame for each marker, as there is no caching either, which is not a really efficient solution, but not too slow either. I like this solution as this allows automatically use exact same logical marker size for each platform, including web. But this is indeed a bit slow compared to using size parameter (which is fastest approach for web), and also not working for html
renderer
I would like to keep this support for scaling with imagePixelRatio, but change the logic so that image width and height are parsed from the image header, so that only first bytes of data need to be parsed... and check if this approach is fast enough and valid for html
renderer as well. Here's an example for this approach by @dnfield. Writing something similar, as this gist has no proper license to be used directly.
And also API need to be changed a bit, as developers are not able to disable scaling for web at the moment as for web images need to be counter-scaled even if imagePixelFactor is 1.
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.
@jokerttu, have you see package:image
? The only concern I have with this approach is that you'll need to download with a XHR request the image to get access to its bytes, and that's going to make this slower. Is there any way of combining the two solutions, so users can pass a size and dpr for a given marker, and if not, fall back to the slower code path?
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.
@ditman yes, image packages startDecode does exactly this. If it is ok to add new dependency this would be better option than writing own parsers for image headers.
webOnlyInstantiateImageCodecFromUrl
fetches image as well, for each marker, but of course image request is cached by browser, but it still fills up network panel with requests each time marker updates. This is not really good thing either.
I might still implement this feature, and keep the feature for web as well, and instruct users to use size instead, as more performant option.
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.
@ditman feature implemented using package:image
. Also fixed case where image was scaled even when imageScaling was set to noScaling.
On web, using scaling without "size" is slow, as the image need to be loaded before size can be calculated, but users have way to improve performance by using size or disabling scaling totally.
26fd693
to
a705bd5
Compare
a705bd5
to
472b675
Compare
packages/google_maps_flutter/google_maps_flutter_ios/ios/Classes/GoogleMapMarkerController.m
Show resolved
Hide resolved
packages/google_maps_flutter/google_maps_flutter_ios/ios/Classes/GoogleMapMarkerController.m
Show resolved
Hide resolved
packages/google_maps_flutter/google_maps_flutter_ios/ios/Classes/GoogleMapMarkerController.m
Show resolved
Hide resolved
packages/google_maps_flutter/google_maps_flutter_ios/ios/Classes/GoogleMapMarkerController.m
Show resolved
Hide resolved
packages/google_maps_flutter/google_maps_flutter_ios/ios/Classes/GoogleMapMarkerController.m
Show resolved
Hide resolved
We've just completed the migration of the plugin code to the flutter/packages repository, as described in https://flutter.dev/go/flutter-plugins-repo-migration, and this repository is now being archived. Unfortunately that means that all in-progress PRs here must be moved to flutter/packages. Please see our instructions for an explanation of how to move your PR, and if you have any issues moving your PR please don't hesitate to reach out in the #hackers-ecosystem channel in Discord. Our apologies that your PR was caught in this one-time transition. We're aware that it's disruptive in the short term, and appreciate your help in getting us to a better long-term state! |
This PR adds and improves marker scaling support for Android, iOS and Web.
With this change, custom marker icons are drawn with same logical size on all platforms, keeping the visual style as close as possible.
To avoid breaking change, this PR makes the following changes while keeping the old behavior intact:
BitmapDescriptor.fromAssetImage
in favor ofBitmapDescriptor.createFromAsset
BitmapDescriptor.fromBytes
in favor ofBitmapDescriptor.createFromBytes
Android:

Web:

Resolves flutter/flutter#34657
Pre-launch Checklist
dart format
.)[shared_preferences]
pubspec.yaml
with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.CHANGELOG.md
to add a description of the change, following repository CHANGELOG style.///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.