forked from flutter/packages
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[google_maps_flutter] Add support for marker clustering - platform in…
…terface (flutter#6158) This PR introduces support for marker clustering This is prequel PR for: flutter#4319 Containing only changes to `google_maps_flutter_platform_interface` package. Follow up PR:s will hold the platform and app-facing plugin implementations. Linked issue: flutter/flutter#26863
- Loading branch information
Showing
19 changed files
with
455 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
packages/google_maps_flutter/google_maps_flutter_platform_interface/CHANGELOG.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...ges/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/cluster.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
import 'package:flutter/foundation.dart' | ||
show immutable, listEquals, objectRuntimeType; | ||
import 'types.dart'; | ||
|
||
/// A cluster containing multiple markers. | ||
@immutable | ||
class Cluster { | ||
/// Creates a cluster with its location [LatLng], bounds [LatLngBounds], | ||
/// and list of [MarkerId]s in the cluster. | ||
const Cluster( | ||
this.clusterManagerId, | ||
this.markerIds, { | ||
required this.position, | ||
required this.bounds, | ||
}) : assert(markerIds.length > 0); | ||
|
||
/// ID of the [ClusterManager] of the cluster. | ||
final ClusterManagerId clusterManagerId; | ||
|
||
/// Cluster marker location. | ||
final LatLng position; | ||
|
||
/// The bounds containing all cluster markers. | ||
final LatLngBounds bounds; | ||
|
||
/// List of [MarkerId]s in the cluster. | ||
final List<MarkerId> markerIds; | ||
|
||
/// Returns the number of markers in the cluster. | ||
int get count => markerIds.length; | ||
|
||
@override | ||
String toString() => | ||
'${objectRuntimeType(this, 'Cluster')}($clusterManagerId, $position, $bounds, $markerIds)'; | ||
|
||
@override | ||
bool operator ==(Object other) { | ||
return other is Cluster && | ||
other.clusterManagerId == clusterManagerId && | ||
other.position == position && | ||
other.bounds == bounds && | ||
listEquals(other.markerIds, markerIds); | ||
} | ||
|
||
@override | ||
int get hashCode => | ||
Object.hash(clusterManagerId, position, bounds, markerIds); | ||
} |
82 changes: 82 additions & 0 deletions
82
...le_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/cluster_manager.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
import 'package:flutter/foundation.dart' show immutable; | ||
import 'types.dart'; | ||
|
||
/// Uniquely identifies a [ClusterManager] among [GoogleMap] clusters. | ||
/// | ||
/// This does not have to be globally unique, only unique among the list. | ||
@immutable | ||
class ClusterManagerId extends MapsObjectId<ClusterManager> { | ||
/// Creates an immutable identifier for a [ClusterManager]. | ||
const ClusterManagerId(super.value); | ||
} | ||
|
||
/// [ClusterManager] manages marker clustering for set of [Marker]s that have | ||
/// the same [ClusterManagerId] set. | ||
@immutable | ||
class ClusterManager implements MapsObject<ClusterManager> { | ||
/// Creates an immutable object for managing clustering for set of markers. | ||
const ClusterManager({ | ||
required this.clusterManagerId, | ||
this.onClusterTap, | ||
}); | ||
|
||
/// Uniquely identifies a [ClusterManager]. | ||
final ClusterManagerId clusterManagerId; | ||
|
||
@override | ||
ClusterManagerId get mapsId => clusterManagerId; | ||
|
||
/// Callback to receive tap events for cluster markers placed on this map. | ||
final ArgumentCallback<Cluster>? onClusterTap; | ||
|
||
/// Creates a new [ClusterManager] object whose values are the same as this instance, | ||
/// unless overwritten by the specified parameters. | ||
ClusterManager copyWith({ | ||
ArgumentCallback<Cluster>? onClusterTapParam, | ||
}) { | ||
return ClusterManager( | ||
clusterManagerId: clusterManagerId, | ||
onClusterTap: onClusterTapParam ?? onClusterTap, | ||
); | ||
} | ||
|
||
/// Creates a new [ClusterManager] object whose values are the same as this instance. | ||
@override | ||
ClusterManager clone() => copyWith(); | ||
|
||
/// Converts this object to something serializable in JSON. | ||
@override | ||
Object toJson() { | ||
final Map<String, Object> json = <String, Object>{}; | ||
|
||
void addIfPresent(String fieldName, Object? value) { | ||
if (value != null) { | ||
json[fieldName] = value; | ||
} | ||
} | ||
|
||
addIfPresent('clusterManagerId', clusterManagerId.value); | ||
return json; | ||
} | ||
|
||
@override | ||
bool operator ==(Object other) { | ||
if (other.runtimeType != runtimeType) { | ||
return false; | ||
} | ||
return other is ClusterManager && | ||
clusterManagerId == other.clusterManagerId; | ||
} | ||
|
||
@override | ||
int get hashCode => clusterManagerId.hashCode; | ||
|
||
@override | ||
String toString() { | ||
return 'Cluster{clusterManagerId: $clusterManagerId, onClusterTap: $onClusterTap}'; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...flutter/google_maps_flutter_platform_interface/lib/src/types/cluster_manager_updates.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
import 'types.dart'; | ||
|
||
/// [ClusterManager] update events to be applied to the [GoogleMap]. | ||
/// | ||
/// Used in [GoogleMapController] when the map is updated. | ||
// (Do not re-export) | ||
class ClusterManagerUpdates extends MapsObjectUpdates<ClusterManager> { | ||
/// Computes [ClusterManagerUpdates] given previous and current [ClusterManager]s. | ||
ClusterManagerUpdates.from(super.previous, super.current) | ||
: super.from(objectName: 'clusterManager'); | ||
|
||
/// Set of Clusters to be added in this update. | ||
Set<ClusterManager> get clusterManagersToAdd => objectsToAdd; | ||
|
||
/// Set of ClusterManagerIds to be removed in this update. | ||
Set<ClusterManagerId> get clusterManagerIdsToRemove => | ||
objectIdsToRemove.cast<ClusterManagerId>(); | ||
|
||
/// Set of Clusters to be changed in this update. | ||
Set<ClusterManager> get clusterManagersToChange => objectsToChange; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.