Skip to content
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

[google_maps_flutter] Support for Ground Overlay #8432

Open
wants to merge 18 commits into
base: main
Choose a base branch
from

Conversation

jokerttu
Copy link
Contributor

@jokerttu jokerttu commented Jan 15, 2025

Adds Ground Overlay support for google_maps_flutter plugin.

Fixes flutter/flutter#26479

Android:

iOS:

Web:

Documentation for groundOverlays parameter on app-facing plugin:
documentation

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@jokerttu jokerttu force-pushed the feat/google_maps_flutter_ground_overlay_support branch from c94285d to 19a7808 Compare January 16, 2025 10:34
@@ -22,7 +21,7 @@ void main() {
}

void runTests() {
const double floatTolerance = 1e-8;
const double floatTolerance = 1e-6;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added bigger tolerance as on Android and iOS tests failed as diff was bigger than 1e-8

Color.fromARGB(255, 0, 0, 191),
0.6,
);
await tester.pumpAndSettle(const Duration(seconds: 3));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this line tests timeouted on Web platform, and we were not able to test ground overlay below.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Were they timing out in all tests, or wasm specifically? I know I had to revisit a bunch of plugins and add a few pumps and pumpAndSettle when enabling the wasm tests. See:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ditman
Note that google_maps_flutter tests are currently excluded for web platform because failing tests:
https://github.com/flutter/packages/blob/main/script/configs/exclude_integration_web.yaml

New implemented tests pass with and without wasm enabled, but only if I disable other test sets (that fail because other reasons). The new tests are located in tiles_inspector.dart and I just run this set, which includes tests for tiles, heatmaps, and ground overlays. This file should probably be renamed or split?

image

Fixing other tests is out of scope of this PR, but this must include working integration tests for web for new features and functionality.

So when only tiles_inspector.dart tests are enabled tests pass with following commands:

Without wasm

dart run ./script/tool/bin/flutter_plugin_tools.dart drive-examples --web --run-chromedriver --packages=google_maps_flutter/google_maps_flutter

and with wasm

dart run ./script/tool/bin/flutter_plugin_tools.dart drive-examples --web --wasm --run-chromedriver --packages=google_maps_flutter/google_maps_flutter

expect(wll1.weight, wll2.weight);
expect(wll1.point.latitude, moreOrLessEquals(wll2.point.latitude));
expect(wll1.point.longitude, moreOrLessEquals(wll2.point.longitude));
group('Heatmaps', () {
Copy link
Contributor Author

@jokerttu jokerttu Jan 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added Heatmap tests to own group, like tile overlay tests and ground overlay tests.

@jokerttu jokerttu marked this pull request as ready for review January 16, 2025 11:38
@reidbaker reidbaker requested a review from jesswrd January 17, 2025 16:28
Copy link
Contributor

@stuartmorgan stuartmorgan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks really good! I did a pass over everything from web, and mostly just have minor comments and questions.

}

- (void)didTapGroundOverlayWithIdentifier:(NSString *)identifier {
if (!identifier) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and in the next method: the identifier params were annotated as non-nullable in the interface, so the implementation code shouldn't be handling nil.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Removed the null check.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's still here in this method.

NS_ASSUME_NONNULL_BEGIN

@interface FGMUtils : NSObject
+ (UIImage *)iconFromBitmap:(FGMPlatformBitmap *)platformBitmap
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These new APIs need declaration comments.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be given a more specific name? It's already the case that this plugin has at least one other file of utils (the conversion function file).

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I renamed it FGMImageUtils.

final PlatformBitmap image;
final PlatformLatLng? position;
final PlatformLatLngBounds? bounds;
final PlatformDoublePair? anchor;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this conceptually a point? We already have PlatformPoint, so shouldn't need a new PlatformDoublePair for this unless there's a conceptual difference in meaning here.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed this to PlatformPoint.

illuminati1911 and others added 5 commits January 22, 2025 18:40
* refactor: ios groundoverlay improvements

* refactor: switch anchor to platformpoint on ios

* refactor: refactor global functions

* Format ios code

---------

Co-authored-by: Joonas Kerttula <[email protected]>
- Add missing NonNull annotations for java
- Change zIndex type from double to int for groundOverlays to avoid future issues on iOS platform
- Documentation improvements
@jokerttu jokerttu requested a review from stuartmorgan January 22, 2025 19:40
Copy link
Contributor

@stuartmorgan stuartmorgan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some scattered minor issues remaining. Feel free to split out the first sub-PR at this point!

if (west <= east) {
longitudeOffset = position.longitude - west;
} else {
longitudeOffset = position.longitude - west;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the same in both branches; is that a copy/paste mistake?

If not, it should be factored out of the if/else.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(And if so, that suggests missing test coverage for the behavior in these branches.)

@import GoogleMaps;

#import <OCMock/OCMock.h>
#import <google_maps_flutter_ios/FGMGroundOverlayController_Test.h>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


#import <google_maps_flutter_ios/FGMGroundOverlayController_Test.h>

#import <OCMock/OCMock.h>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be grouped with the other framework imports. Grouping is by type of thing import, not by @ vs #.

/// Returns true if a ground overlay with the given identifier exists on the map.
- (bool)hasGroundOverlaysWithIdentifier:(NSString *)identifier;

/// Returns FGMPlatformGroundOverlay for identifier.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Returns the ground overlay with the given identifier."

registrar:(NSObject<FlutterPluginRegistrar> *)registrar
screenScale:(CGFloat)screenScale {
[self setConsumeTapEvents:groundOverlay.clickable];
[self setVisible:groundOverlay.visible];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on investigation of similar methods in a recent PR (which hasn't landed), this needs to be last to avoid potential flickering (likely due to Google Maps using its own render thread), so should be at the end of the method, and have a comment saying that nothing should be added after it.

}

- (void)didTapGroundOverlayWithIdentifier:(NSString *)identifier {
if (!identifier) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's still here in this method.

static UIImage *scaleImage(UIImage *image, double scale);
static UIImage *scaledImageWithScale(UIImage *image, CGFloat scale);
static UIImage *scaledImageWithSize(UIImage *image, CGSize size);
static UIImage *scaledImage(UIImage *image, NSNumber *width, NSNumber *height, CGFloat screenScale);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The declaration comments for all of these functions should be here, on the declarations, rather than on the definitions below.

#import "FGMImageUtils.h"
#import "Foundation/Foundation.h"

static UIImage *scaleImage(UIImage *image, double scale);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be scaled, not scale, for consistency in naming.

NSNumber *zoomLevel) {
/// Dummy image is used as image is required field of FGMPlatformGroundOverlay and converting
/// image back to bitmap image is not currently supported.
FGMPlatformBitmap *mockImage =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be called placeholderImage rather than mockImage, as "mock" generally refers to a specific test construct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[google_maps_flutter] Support for Ground Overlay
4 participants