Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.6.4

* Adds support for tapping points of interest on the map.

## 0.6.3+1

* Fixes flickering of byte-backed advanced markers when updating their position on web.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ environment:
dependencies:
flutter:
sdk: flutter
google_maps_flutter_platform_interface: ^2.16.0
google_maps_flutter_platform_interface: ^2.17.0
google_maps_flutter_web:
path: ../..
web: ^1.0.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,36 @@ void main() {
expect(events[4], isA<CameraIdleEvent>());
});

testWidgets('emits point of interest tap when click has placeId', (
WidgetTester tester,
) async {
controller = createController()
..debugSetOverrides(
createMap: (_, _) => map,
circles: circles,
heatmaps: heatmaps,
markers: markers,
polygons: polygons,
polylines: polylines,
groundOverlays: groundOverlays,
)
..init();

final Stream<MapEvent<Object?>> capturedEvents = stream.stream.take(1);

gmaps.event.trigger(
map,
'click',
gmaps.IconMouseEvent(placeId: 'place-123')..latLng = gmaps.LatLng(0, 0),
);

final List<MapEvent<Object?>> events = await capturedEvents.toList();

expect(events, hasLength(1));
expect(events[0], isA<PointOfInterestTapEvent>());
expect((events[0] as PointOfInterestTapEvent).value, const PointOfInterestId('place-123'));
});

testWidgets('stops listening to map events once disposed', (WidgetTester tester) async {
controller = createController()
..debugSetOverrides(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,13 @@ void main() {

await testStreamFiltering(stream, event);
});
testWidgets('onPointOfInterestTap', (WidgetTester tester) async {
final event = PointOfInterestTapEvent(mapId, const PointOfInterestId('place-123'));

final Stream<PointOfInterestTapEvent> stream = plugin.onPointOfInterestTap(mapId: mapId);

await testStreamFiltering(stream, event);
});
// Map taps
testWidgets('onTap', (WidgetTester tester) async {
final event = MapTapEvent(mapId, const LatLng(43.3597, -5.8458));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ environment:
dependencies:
flutter:
sdk: flutter
google_maps_flutter_platform_interface: ^2.16.0
google_maps_flutter_platform_interface: ^2.17.0
google_maps_flutter_web:
path: ../..
web: ^1.0.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import 'package:web/web.dart' as web;

import 'src/dom_window_extension.dart';
import 'src/google_maps_inspector_web.dart';
import 'src/map_mouse_event_extension.dart';
import 'src/map_styler.dart';
import 'src/marker_clustering.dart';
import 'src/third_party/to_screen_location/to_screen_location.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,11 @@ class GoogleMapController {
_onClickSubscription = map.onClick.listen((gmaps.MapMouseEventOrIconMouseEvent event) {
assert(event.latLng != null);
if (!_streamController.isClosed) {
final String? placeId = event.placeId;
if (placeId != null) {
_streamController.add(PointOfInterestTapEvent(_mapId, PointOfInterestId(placeId)));
return;
}
_streamController.add(MapTapEvent(_mapId, gmLatLngToLatLng(event.latLng!)));
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,11 @@ class GoogleMapsPlugin extends GoogleMapsFlutterPlatform {
return _events(mapId).whereType<CircleTapEvent>();
}

@override
Stream<PointOfInterestTapEvent> onPointOfInterestTap({required int mapId}) {
return _events(mapId).whereType<PointOfInterestTapEvent>();
}

@override
Stream<MapTapEvent> onTap({required int mapId}) {
return _events(mapId).whereType<MapTapEvent>();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2013 The Flutter Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

@JS()
library;

import 'dart:js_interop';

import 'package:google_maps/google_maps.dart' as gmaps;

/// Exposes the `placeId` property on map click events.
///
/// [gmaps.MapMouseEventOrIconMouseEvent] only binds `latLng` upstream. POI
/// clicks are [gmaps.IconMouseEvent]s and carry a `placeId`; this extension
/// reads that property without `dart:js_interop_unsafe`. Prefer adding
/// `placeId` to the upstream binding when possible.
extension PlaceIdExtension on gmaps.MapMouseEventOrIconMouseEvent {
/// The place ID of a tapped point of interest, if this event is an icon
/// mouse event. Otherwise `null`.
external String? placeId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: google_maps_flutter_web
description: Web platform implementation of google_maps_flutter
repository: https://github.com/flutter/packages/tree/main/packages/google_maps_flutter/google_maps_flutter_web
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+maps%22
version: 0.6.3+1
version: 0.6.4

environment:
sdk: ^3.10.0
Expand All @@ -23,7 +23,7 @@ dependencies:
flutter_web_plugins:
sdk: flutter
google_maps: ^8.1.0
google_maps_flutter_platform_interface: ^2.16.0
google_maps_flutter_platform_interface: ^2.17.0
sanitize_html: ^2.0.0
stream_transform: ^2.0.0
web: ^1.0.0
Expand Down
Loading