diff --git a/lib/ui/explore/ExploreMapPanel.dart b/lib/ui/explore/ExploreMapPanel.dart index 9a81cf7c0..dfacb09f3 100644 --- a/lib/ui/explore/ExploreMapPanel.dart +++ b/lib/ui/explore/ExploreMapPanel.dart @@ -643,27 +643,53 @@ class _ExploreMapPanelState extends State } void _selectStoriedSiteExplore(dynamic explore) { - if (explore is Place) { _storiedSightsKey.currentState?.selectPlace(explore); - } else if (explore is List) { + } + else if (explore is List) { List places = explore.cast(); _storiedSightsKey.currentState?.selectPlaces(places); _centerMapOnExplore(places); } - setState(() { - _selectedStoriedSiteExplore = explore is Explore ? explore : null; - }); - - // Rebuild markers to reflect the change in selected marker - _mapController?.getZoomLevel().then((double value) { - _buildMapContentData(_filteredExplores ?? _explores, pinnedExplore: _pinnedMapExplore, updateCamera: false, showProgress: false, zoom: value, forceRefresh: true); - }); + _updateSelectedStoriedSiteMarker(explore is Explore ? explore : null); _logAnalyticsSelect(explore); } + Future _updateSelectedStoriedSiteMarker(Explore? selectedStoriedSiteExplore) async { + Set? targetMarkers = (_targetMarkers != null) ? Set.from(_targetMarkers!) : null; + if ((targetMarkers != null) && (_selectedStoriedSiteExplore != selectedStoriedSiteExplore)) { + ImageConfiguration imageConfiguration = createLocalImageConfiguration(context); + + if (_selectedStoriedSiteExplore != null) { + Marker? selectedStoriedSiteMarker = targetMarkers.exploreMarker(_selectedStoriedSiteExplore); + Marker? selectedStoriedSiteMarkerUpd = await _createExploreMarker(_selectedStoriedSiteExplore, imageConfiguration: imageConfiguration); + if ((selectedStoriedSiteMarker != null) && (selectedStoriedSiteMarkerUpd != null)) { + targetMarkers.remove(selectedStoriedSiteMarker); + targetMarkers.add(selectedStoriedSiteMarkerUpd); + } + } + + _selectedStoriedSiteExplore = selectedStoriedSiteExplore; + + if (_selectedStoriedSiteExplore != null) { + Marker? selectedStoriedSiteMarker = targetMarkers.exploreMarker(_selectedStoriedSiteExplore); + Marker? selectedStoriedSiteMarkerUpd = await _createExploreMarker(_selectedStoriedSiteExplore, imageConfiguration: imageConfiguration, markerColor: Styles().colors.fillColorSecondary); + if ((selectedStoriedSiteMarker != null) && (selectedStoriedSiteMarkerUpd != null)) { + targetMarkers.remove(selectedStoriedSiteMarker); + targetMarkers.add(selectedStoriedSiteMarkerUpd); + } + } + } + + if (!DeepCollectionEquality().equals(_targetMarkers, targetMarkers)) { + setStateIfMounted((){ + _targetMarkers = targetMarkers; + }); + } + } + void _centerMapOnExplore(dynamic explore, {bool zoom = true}) async { LatLng? targetPosition; @@ -2155,7 +2181,7 @@ class _ExploreMapPanelState extends State // Map Content - Future _buildMapContentData(List? explores, {Explore? pinnedExplore, bool updateCamera = false, bool showProgress = false, double? zoom, bool forceRefresh = false}) async { + Future _buildMapContentData(List? explores, {Explore? pinnedExplore, bool updateCamera = false, bool showProgress = false, double? zoom}) async { LatLngBounds? exploresBounds = ExploreMap.boundsOfList(explores); CameraUpdate? targetCameraUpdate; @@ -2192,7 +2218,7 @@ class _ExploreMapPanelState extends State exploreMarkerGroups = (explores != null) ? { ExploreMap.validFromList(explores) } : null; } - if (forceRefresh || !DeepCollectionEquality().equals(_exploreMarkerGroups, exploreMarkerGroups)) { + if (!DeepCollectionEquality().equals(_exploreMarkerGroups, exploreMarkerGroups)) { Future> buildMarkersTask = _buildMarkers(context, exploreGroups: exploreMarkerGroups, pinnedExplore: pinnedExplore); _buildMarkersTask = buildMarkersTask; if (showProgress && mounted) { @@ -2369,7 +2395,7 @@ class _ExploreMapPanelState extends State } - Future _createExploreMarker(Explore? explore, {required ImageConfiguration imageConfiguration}) async { + Future _createExploreMarker(Explore? explore, {required ImageConfiguration imageConfiguration, Color? markerColor }) async { LatLng? markerPosition = explore?.exploreLocation?.exploreLocationMapCoordinate; if (markerPosition != null) { BitmapDescriptor? markerIcon; @@ -2381,10 +2407,7 @@ class _ExploreMapPanelState extends State markerAnchor = Offset(0.5, 0.5); } else { - Color? exploreColor = explore?.mapMarkerColor; - if (_selectedMapType == ExploreMapType.StoriedSites && explore == _selectedStoriedSiteExplore) { - exploreColor = Styles().colors.fillColorSecondary; - } + Color? exploreColor = markerColor ?? explore?.mapMarkerColor; markerIcon = (exploreColor != null) ? BitmapDescriptor.defaultMarkerWithHue(ColorUtils.hueFromColor(exploreColor).toDouble()) : BitmapDescriptor.defaultMarker; markerAnchor = Offset(0.5, 1); } @@ -2560,4 +2583,16 @@ String? _exploreMapTypeToString(ExploreMapType? value) { class ExploreMapSearchEventsParam { final String searchText; ExploreMapSearchEventsParam(this.searchText); -} \ No newline at end of file +} + +extension _MapMarkersSet on Set { + + Marker? exploreMarker(Explore? explore) { + LatLng? markerPosition = explore?.exploreLocation?.exploreLocationMapCoordinate; + String? markerId = (markerPosition != null) ? "${markerPosition.latitude.toStringAsFixed(6)}:${markerPosition.longitude.toStringAsFixed(6)}" : null; + return (markerId != null) ? markerById(MarkerId(markerId)) : null; + } + + Marker? markerById(MarkerId markerId) => + firstWhereOrNull((marker) => marker.markerId == markerId); +}