GoogleMapController constructor

GoogleMapController({
  1. required int mapId,
  2. required StreamController<MapEvent<Object?>> streamController,
  3. required MapWidgetConfiguration widgetConfiguration,
  4. MapObjects mapObjects = const MapObjects(),
  5. MapConfiguration mapConfiguration = const MapConfiguration(),
})

Initializes the GMap, and the sub-controllers related to it. Wires events.

Implementation

GoogleMapController({
  required int mapId, // 必要的参数 _mapId
  required StreamController<MapEvent<Object?>> streamController,

  /// 必要的 参数 _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,
      _heatPoints = mapObjects.heatPoints,

      /// 这些就是插件前传递过来的参数
      _tileOverlays = mapObjects.tileOverlays,
      _lastMapConfiguration = mapConfiguration {
  _circlesController = CirclesController(stream: _streamController);
  _polygonsController = PolygonsController(stream: _streamController);
  _polylinesController = PolylinesController(stream: _streamController);
  _markersController = MarkersController(stream: _streamController);
  _tileOverlaysController = TileOverlaysController();

  // 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.GMap] in the `init()` method of this class.
  _div = DivElement()
    ..id = _getViewType(mapId)
    ..style.width = '100%'
    ..style.height = '100%';

  ui.platformViewRegistry.registerViewFactory(
    _getViewType(mapId),
    (int viewId) => _div,
  );
}