From f2b9caf4ad89eddd06575e3021438890ef6cd99b Mon Sep 17 00:00:00 2001 From: Jefferey Petersen Date: Tue, 2 Aug 2022 11:08:44 -0700 Subject: [PATCH 1/3] Force move to pick center even if max bounds does not fit If bounds do not fit first attempt to zoom up to the max zoom. If center still cannot work then just set center with max zoom and live with the grey borders. --- lib/src/map/map.dart | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/src/map/map.dart b/lib/src/map/map.dart index aa9e6e78d..48a038a64 100644 --- a/lib/src/map/map.dart +++ b/lib/src/map/map.dart @@ -377,15 +377,19 @@ class MapState { } // Try and fit the corners of the map inside the visible area. - // If it's still outside (so response is null), don't perform a move. + // If it's still outside (so response is null), Adjust zoom to either fit + // the options.maxZoom or do a best approx center with grey boundaries to + // avoid center never being set. if (options.maxBounds != null) { - final adjustedCenter = + LatLng? adjustedCenter = adjustCenterIfOutsideMaxBounds(center, zoom, options.maxBounds!); if (adjustedCenter == null) { - return false; - } else { - center = adjustedCenter; + final centerZoom = getBoundsCenterZoom(options.maxBounds!, + FitBoundsOptions(inside: true, maxZoom: options.maxZoom ?? 17)); + adjustedCenter = centerZoom.center; + zoom = centerZoom.zoom; } + center = adjustedCenter; } _handleMoveEmit(center, zoom, hasGesture, source, id); From e070b40cc19e89a983cba452f6652e419d0a81d7 Mon Sep 17 00:00:00 2001 From: Jefferey Petersen Date: Tue, 2 Aug 2022 11:52:38 -0700 Subject: [PATCH 2/3] Only adjust is _lastCenter is not yet set --- lib/src/map/map.dart | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/src/map/map.dart b/lib/src/map/map.dart index 48a038a64..81def9a8e 100644 --- a/lib/src/map/map.dart +++ b/lib/src/map/map.dart @@ -383,13 +383,17 @@ class MapState { if (options.maxBounds != null) { LatLng? adjustedCenter = adjustCenterIfOutsideMaxBounds(center, zoom, options.maxBounds!); - if (adjustedCenter == null) { + if (adjustedCenter == null && _lastCenter == null) { final centerZoom = getBoundsCenterZoom(options.maxBounds!, FitBoundsOptions(inside: true, maxZoom: options.maxZoom ?? 17)); adjustedCenter = centerZoom.center; zoom = centerZoom.zoom; } - center = adjustedCenter; + if (adjustedCenter == null) { + return false; + } else { + center = adjustedCenter; + } } _handleMoveEmit(center, zoom, hasGesture, source, id); From b1f5b0ab2b480ebe3048381feef561990f789bb1 Mon Sep 17 00:00:00 2001 From: Jefferey Petersen Date: Tue, 2 Aug 2022 12:30:19 -0700 Subject: [PATCH 3/3] Update max bounds comment to better describe its workings --- lib/src/map/map.dart | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/src/map/map.dart b/lib/src/map/map.dart index 81def9a8e..5515a7a27 100644 --- a/lib/src/map/map.dart +++ b/lib/src/map/map.dart @@ -377,9 +377,11 @@ class MapState { } // Try and fit the corners of the map inside the visible area. - // If it's still outside (so response is null), Adjust zoom to either fit - // the options.maxZoom or do a best approx center with grey boundaries to - // avoid center never being set. + // If it's still outside (so response is null) and the map as already been + // drawn do nothing, otherwise on first pass adjust zoom to either fit + // the options.maxZoom or draw at max zoom with allowing map to draw + // ouside boundaries to avoid center never being set. In this state the map + // is not movable except to rotate. if (options.maxBounds != null) { LatLng? adjustedCenter = adjustCenterIfOutsideMaxBounds(center, zoom, options.maxBounds!);