init method
Starts the JS Maps SDK into the target _div
with rawOptions
.
(Also initializes the geometry/traffic layers.)
The first part of this method starts the rendering of a gmaps.GMap
inside
of the target _div
, with configuration from rawOptions
. It then stores
the created GMap in the _googleMap
attribute.
Not everything is rendered with the initial rawOptions
configuration,
geometry and traffic layers (and possibly others in the future) have their
own configuration and are rendered on top of a GMap instance later. This
happens in the second half of this method.
This method is eagerly called from the GoogleMapsPlugin.buildView method
so the internal GoogleMapsController
of a Web Map initializes as soon as
possible. Check _attachMapEvents
to see how this controller notifies the
plugin of it being fully ready (through the onTilesloaded.first
event).
Failure to call this method would result in the GMap not rendering at all, and most of the public methods on this class no-op'ing.
Implementation
void init() {
gmaps.MapOptions options = _configurationAndStyleToGmapsOptions(
_lastMapConfiguration, _lastStyles);
// Initial position can only to be set here!
options = _applyInitialPosition(_initialCameraPosition, options);
// Fully disable 45 degree imagery if desired
if (options.rotateControl == false) {
options.tilt = 0;
}
///
/// Create the map...
/// div创建
///
final gmaps.GMap map = _createMap(_div, options);
_googleMap = map;
_attachMapEvents(map);
_attachGeometryControllers(map);
// Now attach the geometry, traffic and any other layers...
_renderInitialGeometry();
///
/// 设置 gmap - darwing 参数
///
_setTrafficLayer(map, _lastMapConfiguration.trafficEnabled ?? false);
///
/// 设置 drawmanager google map
///
if (_heatPoints.isEmpty) {
_setDrawmanager(map);
}
///
/// 设置 visualization google map
///
if (_heatPoints.isNotEmpty) {
_setVisualization(map);
}
}