diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 0aeae14..051c7a3 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -1,6 +1,6 @@ name: example description: A new Flutter project. - +publish_to: 'none' # The following defines the version and build number for your application. # A version number is three numbers separated by dots, like 1.2.43 # followed by an optional build number separated by a +. @@ -20,8 +20,8 @@ dependencies: flutter: sdk: flutter - google_maps_flutter: ^2.5.2 - google_maps_flutter_web: ^0.5.4+3 + google_maps_flutter: ^2.6.0 + google_maps_flutter_web: ^0.5.6+2 google_maps_cluster_manager: path: ../ diff --git a/example/test/widget_test.dart b/example/test/widget_test.dart index f4cdd49..f317c05 100644 --- a/example/test/widget_test.dart +++ b/example/test/widget_test.dart @@ -5,11 +5,6 @@ // gestures. You can also use WidgetTester to find child widgets in the widget // tree, read text, and verify that the values of widget properties are correct. -import 'package:flutter/material.dart'; -import 'package:flutter_test/flutter_test.dart'; - -import 'package:example/main.dart'; - void main() { // testWidgets('Counter increments smoke test', (WidgetTester tester) async { // // Build our app and trigger a frame. diff --git a/lib/src/cluster_item.dart b/lib/src/cluster_item.dart index fc7d445..498471d 100644 --- a/lib/src/cluster_item.dart +++ b/lib/src/cluster_item.dart @@ -1,8 +1,9 @@ import 'package:google_maps_cluster_manager/google_maps_cluster_manager.dart'; -import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; +import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart' + as gMFPI; mixin ClusterItem { - LatLng get location; + gMFPI.LatLng get location; String? _geohash; String get geohash => _geohash ??= diff --git a/lib/src/cluster_manager.dart b/lib/src/cluster_manager.dart index 0101d83..7c3b979 100644 --- a/lib/src/cluster_manager.dart +++ b/lib/src/cluster_manager.dart @@ -5,7 +5,8 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:google_maps_cluster_manager/google_maps_cluster_manager.dart'; import 'package:google_maps_cluster_manager/src/max_dist_clustering.dart'; -import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; +import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart' + as gMFPI; enum ClusterAlgorithm { GEOHASH, MAX_DIST } @@ -17,7 +18,7 @@ class MaxDistParams { class ClusterManager { ClusterManager(this._items, this.updateMarkers, - {Future Function(Cluster)? markerBuilder, + {Future Function(Cluster)? markerBuilder, this.levels = const [1, 4.25, 6.75, 8.25, 11.5, 14.5, 16.0, 16.5, 20.0], this.extraPercent = 0.5, this.maxItemsForMaxDistAlgo = 200, @@ -28,13 +29,13 @@ class ClusterManager { assert(levels.length <= precision); /// Method to build markers - final Future Function(Cluster) markerBuilder; + final Future Function(Cluster) markerBuilder; // Num of Items to switch from MAX_DIST algo to GEOHASH final int maxItemsForMaxDistAlgo; /// Function to update Markers on Google Map - final void Function(Set) updateMarkers; + final void Function(Set) updateMarkers; /// Zoom levels configuration final List levels; @@ -68,7 +69,8 @@ class ClusterManager { /// Set Google Map Id for the cluster manager void setMapId(int mapId, {bool withUpdate = true}) async { _mapId = mapId; - _zoom = await GoogleMapsFlutterPlatform.instance.getZoomLevel(mapId: mapId); + _zoom = await gMFPI.GoogleMapsFlutterPlatform.instance + .getZoomLevel(mapId: mapId); if (withUpdate) updateMap(); } @@ -80,7 +82,7 @@ class ClusterManager { void _updateClusters() async { List> mapMarkers = await getMarkers(); - final Set markers = + final Set markers = Set.from(await Future.wait(mapMarkers.map((m) => markerBuilder(m)))); updateMarkers(markers); @@ -99,7 +101,7 @@ class ClusterManager { } /// Method called on camera move - void onCameraMove(CameraPosition position, {forceUpdate = false}) { + void onCameraMove(gMFPI.CameraPosition position, {forceUpdate = false}) { _zoom = position.zoom; if (forceUpdate) { updateMap(); @@ -110,10 +112,11 @@ class ClusterManager { Future>> getMarkers() async { if (_mapId == null) return List.empty(); - final LatLngBounds mapBounds = await GoogleMapsFlutterPlatform.instance + final gMFPI.LatLngBounds mapBounds = await gMFPI + .GoogleMapsFlutterPlatform.instance .getVisibleRegion(mapId: _mapId!); - late LatLngBounds inflatedBounds; + late gMFPI.LatLngBounds inflatedBounds; if (clusterAlgorithm == ClusterAlgorithm.GEOHASH) { inflatedBounds = _inflateBounds(mapBounds); } else { @@ -141,7 +144,7 @@ class ClusterManager { return markers; } - LatLngBounds _inflateBounds(LatLngBounds bounds) { + gMFPI.LatLngBounds _inflateBounds(gMFPI.LatLngBounds bounds) { // Bounds that cross the date line expand compared to their difference with the date line double lng = 0; if (bounds.northeast.longitude < bounds.southwest.longitude) { @@ -160,10 +163,10 @@ class ClusterManager { double eLng = (bounds.northeast.longitude + lng).clamp(-_maxLng, _maxLng); double wLng = (bounds.southwest.longitude - lng).clamp(-_maxLng, _maxLng); - return LatLngBounds( - southwest: LatLng(bounds.southwest.latitude - lat, wLng), - northeast: - LatLng(bounds.northeast.latitude + lat, lng != 0 ? eLng : _maxLng), + return gMFPI.LatLngBounds( + southwest: gMFPI.LatLng(bounds.southwest.latitude - lat, wLng), + northeast: gMFPI.LatLng( + bounds.northeast.latitude + lat, lng != 0 ? eLng : _maxLng), ); } @@ -214,10 +217,10 @@ class ClusterManager { return _computeClusters(newInputList, markerItems, level: level); } - static Future Function(Cluster) get _basicMarkerBuilder => + static Future Function(Cluster) get _basicMarkerBuilder => (cluster) async { - return Marker( - markerId: MarkerId(cluster.getId()), + return gMFPI.Marker( + markerId: gMFPI.MarkerId(cluster.getId()), position: cluster.location, onTap: () { print(cluster); @@ -227,7 +230,7 @@ class ClusterManager { ); }; - static Future _getBasicClusterBitmap(int size, + static Future _getBasicClusterBitmap(int size, {String? text}) async { final PictureRecorder pictureRecorder = PictureRecorder(); final Canvas canvas = Canvas(pictureRecorder); @@ -254,6 +257,6 @@ class ClusterManager { final img = await pictureRecorder.endRecording().toImage(size, size); final data = await img.toByteData(format: ImageByteFormat.png) as ByteData; - return BitmapDescriptor.fromBytes(data.buffer.asUint8List()); + return gMFPI.BitmapDescriptor.fromBytes(data.buffer.asUint8List()); } } diff --git a/pubspec.yaml b/pubspec.yaml index 9b960e4..ffc5e9f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -10,7 +10,7 @@ dependencies: flutter: sdk: flutter - google_maps_flutter_platform_interface: ^2.4.3 + google_maps_flutter_platform_interface: ^2.6.0 dev_dependencies: flutter_test: