blob: 0384ea16cc4bd56304b5b54623d4ed9d61cbc5a9 [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 [PolylinesController]s associated to a [GoogleMapController].
class PolylinesController extends GeometryController {
/// Initializes the cache. The [StreamController] comes from the [GoogleMapController], and is shared with other controllers.
required StreamController<MapEvent<Object?>> stream,
}) : _streamController = stream,
_polylineIdToController = <PolylineId, PolylineController>{};
// A cache of [PolylineController]s indexed by their [PolylineId].
final Map<PolylineId, PolylineController> _polylineIdToController;
// The stream over which polylines broadcast their events
final StreamController<MapEvent<Object?>> _streamController;
/// Returns the cache of [PolylineContrller]s. Test only.
Map<PolylineId, PolylineController> get lines => _polylineIdToController;
/// Adds a set of [Polyline] objects to the cache.
/// Wraps each line into its corresponding [PolylineController].
void addPolylines(Set<Polyline> polylinesToAdd) {
void _addPolyline(Polyline polyline) {
final gmaps.PolylineOptions polylineOptions =
_polylineOptionsFromPolyline(googleMap, polyline);
final gmaps.Polyline gmPolyline = gmaps.Polyline(polylineOptions) = googleMap;
final PolylineController controller = PolylineController(
polyline: gmPolyline,
consumeTapEvents: polyline.consumeTapEvents,
onTap: () {
_polylineIdToController[polyline.polylineId] = controller;
/// Updates a set of [Polyline] objects with new options.
void changePolylines(Set<Polyline> polylinesToChange) {
void _changePolyline(Polyline polyline) {
final PolylineController? polylineController =
?.update(_polylineOptionsFromPolyline(googleMap, polyline));
/// Removes a set of [PolylineId]s from the cache.
void removePolylines(Set<PolylineId> polylineIdsToRemove) {
// Removes a polyline and its controller by its [PolylineId].
void _removePolyline(PolylineId polylineId) {
final PolylineController? polylineController =
// Handle internal events
bool _onPolylineTap(PolylineId polylineId) {
// Have you ended here on your debugging? Is this wrong?
// Comment here:
_streamController.add(PolylineTapEvent(mapId, polylineId));
return _polylineIdToController[polylineId]?.consumeTapEvents ?? false;