blob: 412fd156524b44b06e6fbc29876b98cf1d06398e [file] [log] [blame]
// 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.
part of google_maps_flutter_web;
/// This class manages a set of [PolygonController]s associated to a [GoogleMapController].
class PolygonsController extends GeometryController {
/// Initializes the cache. The [StreamController] comes from the [GoogleMapController], and is shared with other controllers.
required StreamController<MapEvent<Object?>> stream,
}) : _streamController = stream,
_polygonIdToController = <PolygonId, PolygonController>{};
// A cache of [PolygonController]s indexed by their [PolygonId].
final Map<PolygonId, PolygonController> _polygonIdToController;
// The stream over which polygons broadcast events
final StreamController<MapEvent<Object?>> _streamController;
/// Returns the cache of [PolygonController]s. Test only.
Map<PolygonId, PolygonController> get polygons => _polygonIdToController;
/// Adds a set of [Polygon] objects to the cache.
/// Wraps each Polygon into its corresponding [PolygonController].
void addPolygons(Set<Polygon> polygonsToAdd) {
void _addPolygon(Polygon polygon) {
final gmaps.PolygonOptions polygonOptions =
_polygonOptionsFromPolygon(googleMap, polygon);
final gmaps.Polygon gmPolygon = gmaps.Polygon(polygonOptions) = googleMap;
final PolygonController controller = PolygonController(
polygon: gmPolygon,
consumeTapEvents: polygon.consumeTapEvents,
onTap: () {
_polygonIdToController[polygon.polygonId] = controller;
/// Updates a set of [Polygon] objects with new options.
void changePolygons(Set<Polygon> polygonsToChange) {
void _changePolygon(Polygon polygon) {
final PolygonController? polygonController =
polygonController?.update(_polygonOptionsFromPolygon(googleMap, polygon));
/// Removes a set of [PolygonId]s from the cache.
void removePolygons(Set<PolygonId> polygonIdsToRemove) {
// Removes a polygon and its controller by its [PolygonId].
void _removePolygon(PolygonId polygonId) {
final PolygonController? polygonController =
// Handle internal events
bool _onPolygonTap(PolygonId polygonId) {
// Have you ended here on your debugging? Is this wrong?
// Comment here:
_streamController.add(PolygonTapEvent(mapId, polygonId));
return _polygonIdToController[polygonId]?.consumeTapEvents ?? false;