GoogleMapController constructor
GoogleMapController({
- required int mapId,
- required StreamController<
MapEvent< streamController,Object?> > - required MapWidgetConfiguration widgetConfiguration,
- MapObjects mapObjects = const MapObjects(),
- MapConfiguration mapConfiguration = const MapConfiguration(),
Initializes the GMap, and the sub-controllers related to it. Wires events.
Implementation
GoogleMapController({
required int mapId,
required StreamController<MapEvent<Object?>> streamController,
required MapWidgetConfiguration widgetConfiguration,
MapObjects mapObjects = const MapObjects(),
MapConfiguration mapConfiguration = const MapConfiguration(),
}) : _mapId = mapId,
_streamController = streamController,
_initialCameraPosition = widgetConfiguration.initialCameraPosition,
_markers = mapObjects.markers,
_polygons = mapObjects.polygons,
_polylines = mapObjects.polylines,
_circles = mapObjects.circles,
_clusterManagers = mapObjects.clusterManagers,
_heatmaps = mapObjects.heatmaps,
_groundOverlays = mapObjects.groundOverlays,
_tileOverlays = mapObjects.tileOverlays,
_lastMapConfiguration = mapConfiguration {
_circlesController = CirclesController(stream: _streamController);
_heatmapsController = HeatmapsController();
_polygonsController = PolygonsController(stream: _streamController);
_polylinesController = PolylinesController(stream: _streamController);
// Check if all markers are of the same type. Mixing marker types is not
// allowed.
final Set<Type> markerTypes = _markers
.map((Marker e) => e.runtimeType)
.toSet();
if (markerTypes.isNotEmpty) {
assert(markerTypes.length == 1, 'All markers must be of the same type.');
switch (mapConfiguration.markerType) {
case null:
case MarkerType.marker:
assert(
markerTypes.first == Marker,
'All markers must be of type Marker because '
'mapConfiguration.markerType is MarkerType.marker',
);
case MarkerType.advancedMarker:
assert(
markerTypes.first == AdvancedMarker,
'All markers must be of type AdvancedMarker because '
'mapConfiguration.markerType is MarkerType.advanced',
);
}
}
// Advanced and legacy markers are handled differently so markers controller
// and cluster manager need be initialized with the correct marker type.
_clusterManagersController = switch (mapConfiguration.markerType) {
null || MarkerType.marker => ClusterManagersController<gmaps.Marker>(
stream: _streamController,
),
MarkerType.advancedMarker =>
ClusterManagersController<gmaps.AdvancedMarkerElement>(
stream: _streamController,
),
};
_markersController = switch (mapConfiguration.markerType) {
null || MarkerType.marker => LegacyMarkersController(
stream: stream,
clusterManagersController:
_clusterManagersController!
as ClusterManagersController<gmaps.Marker>,
),
MarkerType.advancedMarker => AdvancedMarkersController(
stream: stream,
clusterManagersController:
_clusterManagersController!
as ClusterManagersController<gmaps.AdvancedMarkerElement>,
),
};
_tileOverlaysController = TileOverlaysController();
_groundOverlaysController = GroundOverlaysController(
stream: _streamController,
);
_updateStylesFromConfiguration(mapConfiguration);
// Register the view factory that will hold the `_div` that holds the map in the DOM.
// The `_div` needs to be created outside of the ViewFactory (and cached!) so we can
// use it to create the [gmaps.Map] in the `init()` method of this class.
_div = createDivElement()
..id = _getViewType(mapId)
..style.width = '100%'
..style.height = '100%';
ui_web.platformViewRegistry.registerViewFactory(
_getViewType(mapId),
(int viewId) => _div,
);
}