GoogleMapWidgetClusterMarkers class
This widget implements a very specific adaptation of google_maps_cluster_manager.
The original google_maps_cluster_manager package implements the following process:
- First allowing the GoogleMap widget to be built with an empty Set
- Determining the LatLng bounds of the GoogleMap view and the current zoom level,
- Calculating how many Places there are in each Cluster based on info from the previous step, and storing it in List
- Building a widget to show the number of Places in each Cluster and converting it to a Bitmap
- Calling setState on the Set
This package takes the approach a step further, allowing different Markers to be shown depending on whether it is a Cluster or a Place (Cluster of size 1). Different markers can also be shown depending on its location (allows the marker to wait for information from external APIs).
There are three types of build cycles, used to implement this
- An initMapTripleBuildCycle, which occurs the first time GoogleMap is built FIRST BUILD
- DefaultRepaintBoundaryGenerator builds
- DefaultRenderRepaintBoundaries converted to DefaultBitmaps
- GoogleMap built
- ClusterManager initialised (with Places, GoogleMapController.id) but no clusters in view (because map has not rendered)
- GoogleMap renders and calls onCameraIdle SECOND BUILD
- MapState.refreshMarkerBuilderAndUpdateMarkerCallback() to get clusters in view and use DefaultBitmaps THIRD BUILD
- MapState.updateCachedPlacesAndClusters() splits clusterManager.clusters into a List
- ClusterBoundaryGenerator and PlaceBoundaryGenerator then builds a RepaintBoundary for each CachedCluster and CachedPlace, using both the repaintBoundaryKey and other info (clusterSize, latLngId)
- MapState.storeBitmapsInCache() then converts each CachedPlace and CachedCluster repaintBoundaryKey into a bitmap and stores it
- ClusterManager.updateMap is then called, and markerBuilderCallback uses the newly generated bitmaps
- A refreshMapDoubleBuildCycle, which occurs whenever the GoogleMap is refreshed FIRST BUILD
- MapState.refreshMarkerBuilderAndUpdateMarkerCallback() to get clusters in view and use DefaultBitmaps SECOND BUILD
- MapState.updateCachedPlacesAndClusters() splits clusterManager.clusters into a List
- ClusterBoundaryGenerator and PlaceBoundaryGenerator then builds a RepaintBoundary for each CachedCluster and CachedPlace, using both the repaintBoundaryKey and other info (clusterSize, latLngId)
- MapState.storeBitmapsInCache() then converts each CachedPlace and CachedCluster repaintBoundaryKey into a bitmap and stores it
- ClusterManager.updateMap is then called, and markerBuilderCallback uses the newly generated bitmaps
- An updatePlacesDoubleBuildCycle, which occurs occurs whenever the places in clusterManager is updated. This cycle uses the second and third build of initMapTripleBuildCycle FIRST BUILD
- MapState.refreshMarkerBuilderAndUpdateMarkerCallback() to get clusters in view and use DefaultBitmaps SECOND BUILD
- MapState.updateCachedPlacesAndClusters() splits clusterManager.clusters into a List
- ClusterBoundaryGenerator and PlaceBoundaryGenerator then builds a RepaintBoundary for each CachedCluster and CachedPlace, using both the repaintBoundaryKey and other info (clusterSize, latLngId)
- MapState.storeBitmapsInCache() then converts each CachedPlace and CachedCluster repaintBoundaryKey into a bitmap and stores it
- ClusterManager.updateMap is then called, and markerBuilderCallback uses the newly generated bitmaps
Note:
- clusterManagerId == ClusterManager.cluster.getId(), has format lat_lng_clusterSize
- latLngId has format lat_lng
- RepaintBoundary is converted into Bitmap via: RepaintBoundary > RenderRepaintBoundary > Image > ByteDate > BitmapDescriptor
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatelessWidget
- GoogleMapWidgetClusterMarkers
Constructors
-
GoogleMapWidgetClusterMarkers({required List<
Place> places, required Widget defaultPlaceMarker, required Widget defaultClusterMarker, required Widget clusterMarker, required Widget placeMarkerBuilder(String latLngId), Future<void> clusterMarkerOnTap(String latLngId)?, Future<void> placeMarkerOnTap(String latLngId)?, bool showLogs = false, TextStyle? clusterMarkerTextStyle, EdgeInsets clusterTextPadding = EdgeInsets.zero, bool debugMode = false, double devicePixelRatio = 1, CameraPosition initialCameraPosition = const CameraPosition(target: LatLng(51.5136, -0.1365), zoom: 14), GoogleMapWidgetClusterMarkersController? controller, Future<void> afterInitMapCallback()?, Key? key}) -
const
Properties
-
afterInitMapCallback
→ Future<
void> Function()? -
Callback invoked when the initMapTripleBuildCycle finishes.
final
- clusterMarker → Widget
-
Widget used to display as cluster marker bitmap.
final
-
clusterMarkerOnTap
→ Future<
void> Function(String latLngId)? -
Callback to invoke when a cluster marker is tapped.
final
- clusterMarkerTextStyle → TextStyle?
-
Sets the TextStyle for the number shown in cluster markers.
final
- clusterTextPadding → EdgeInsets
-
Padding to position the cluster number within the cluster marker.
final
- controller → GoogleMapWidgetClusterMarkersController?
-
Top level controller which can be used to expose the GoogleMapWidgetClusterMarkers API.
final
- debugMode → bool
-
If set to true, shows the widgets which are used to generate the markers in a panel on the side.
final
- defaultClusterMarker → Widget
-
Widget used to display as default cluster marker.
final
- defaultPlaceMarker → Widget
-
Widget used to display as default place marker.
final
- devicePixelRatio → double
-
Controls the size of the bitmap generated from each widget.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- initialCameraPosition → CameraPosition
-
Controls the initial camera position on the Google Map
final
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- placeMarkerBuilder → Widget Function(String latLngId)
-
Widget builder used to display as place marker bitmap.
final
-
placeMarkerOnTap
→ Future<
void> Function(String latLngId)? -
Callback to invoke when a place marker is tapped.
final
-
places
→ List<
Place> -
List of all places which will be used to generate clusters/place markers on the Google Map.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- showLogs → bool
-
Set to true to see all logs, false to just show error logs
final
Methods
-
build(
BuildContext context) → Widget -
Describes the part of the user interface represented by this widget.
override
-
createElement(
) → StatelessElement -
Creates a StatelessElement to manage this widget's location in the tree.
inherited
-
debugDescribeChildren(
) → List< DiagnosticsNode> -
Returns a list of DiagnosticsNode objects describing this node's
children.
inherited
-
debugFillProperties(
DiagnosticPropertiesBuilder properties) → void -
Add additional properties associated with the node.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toDiagnosticsNode(
{String? name, DiagnosticsTreeStyle? style}) → DiagnosticsNode -
Returns a debug representation of the object that is used by debugging
tools and by DiagnosticsNode.toStringDeep.
inherited
-
toString(
{DiagnosticLevel minLevel = DiagnosticLevel.info}) → String -
A string representation of this object.
inherited
-
toStringDeep(
{String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String -
Returns a string representation of this node and its descendants.
inherited
-
toStringShallow(
{String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String -
Returns a one-line detailed description of the object.
inherited
-
toStringShort(
) → String -
A short, textual description of this widget.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited