From 028d293ef4f864aba2e5ee4a2a5452a97974510b Mon Sep 17 00:00:00 2001 From: Joscha <34318751+josxha@users.noreply.github.com> Date: Tue, 20 Feb 2024 22:46:20 +0100 Subject: [PATCH 1/8] Update latlng_bounds.dart --- lib/src/geo/latlng_bounds.dart | 206 ++++++++++++++++++--------------- 1 file changed, 113 insertions(+), 93 deletions(-) diff --git a/lib/src/geo/latlng_bounds.dart b/lib/src/geo/latlng_bounds.dart index a9cdbae04..e0a689bd1 100644 --- a/lib/src/geo/latlng_bounds.dart +++ b/lib/src/geo/latlng_bounds.dart @@ -6,81 +6,108 @@ import 'package:vector_math/vector_math_64.dart'; /// Data structure representing rectangular bounding box constrained by its /// northwest and southeast corners class LatLngBounds { - late LatLng _sw; - late LatLng _ne; + /// The latitude north edge of the bounds + double north; + + /// The latitude south edge of the bounds + double south; + + /// The longitude east edge of the bounds + double east; + + /// The longitude west edge of the bounds + double west; + + /// Create a [LatLngBounds] instance from raw edge values. + LatLngBounds({ + required this.north, + required this.south, + required this.east, + required this.west, + }) : assert(north <= 90, "The north latitude can't be bigger than 90."), + assert(north >= -90, "The north latitude can't be smaller than -90."), + assert(south <= 90, "The south latitude can't be bigger than 90."), + assert(south >= -90, "The south latitude can't be smaller than -90."), + assert(east <= 180, "The east longitude can't be bigger than 180."), + assert(east >= -180, "The east longitude can't be smaller than -180."), + assert(west <= 180, "The west longitude can't be bigger than 180."), + assert(west >= -180, "The west longitude can't be smaller than -180."), + assert(north >= south, + "The north latitude can't be smaller than the south latitude"), + assert(east >= west, + "The west longitude can't be smaller than the east longitude"); /// Create new [LatLngBounds] by providing two corners. Both corners have to /// be on opposite sites but it doesn't matter which opposite corners or in /// what order the corners are provided. - LatLngBounds( - LatLng corner1, - LatLng corner2, - ) : this.fromPoints([corner1, corner2]); + factory LatLngBounds.fromCorners(LatLng corner1, LatLng corner2) { + final double minX; + final double maxX; + final double minY; + final double maxY; + if (corner1.longitude >= corner2.longitude) { + maxX = corner1.longitude; + minX = corner2.longitude; + } else { + maxX = corner2.longitude; + minX = corner1.longitude; + } + if (corner1.latitude >= corner2.latitude) { + maxY = corner1.latitude; + minY = corner2.latitude; + } else { + maxY = corner2.latitude; + minY = corner1.latitude; + } + return LatLngBounds(north: maxY, south: minY, east: maxX, west: minX); + } /// Create a new [LatLngBounds] from a list of [LatLng] points. This /// calculates the bounding box of the provided points. - LatLngBounds.fromPoints(List points) - : assert( - points.isNotEmpty, - 'LatLngBounds cannot be created with an empty List of LatLng', - ) { + factory LatLngBounds.fromPoints(List points) { + assert( + points.isNotEmpty, + 'LatLngBounds cannot be created with an empty List of LatLng', + ); + // initialize bounds with max values. double minX = 180; double maxX = -180; double minY = 90; double maxY = -90; - + // find the largest and smallest latitude and longitude for (final point in points) { - minX = math.min(minX, point.longitude); - minY = math.min(minY, point.latitude); - maxX = math.max(maxX, point.longitude); - maxY = math.max(maxY, point.latitude); + if (point.longitude < minX) minX = point.longitude; + if (point.longitude > maxX) maxX = point.longitude; + if (point.latitude < minY) minY = point.latitude; + if (point.latitude > maxY) maxY = point.latitude; } - - _sw = LatLng(minY, minX); - _ne = LatLng(maxY, maxX); + return LatLngBounds(north: maxY, south: minY, east: maxX, west: minX); } /// Expands bounding box by [latLng] coordinate point. This method mutates /// the bounds object on which it is called. void extend(LatLng latLng) { - _extend(latLng, latLng); + north = math.max(north, latLng.latitude); + south = math.min(south, latLng.latitude); + east = math.max(east, latLng.longitude); + west = math.min(west, latLng.longitude); } /// Expands bounding box by other [bounds] object. If provided [bounds] object /// is smaller than current one, it is not shrunk. This method mutates /// the bounds object on which it is called. void extendBounds(LatLngBounds bounds) { - _extend(bounds._sw, bounds._ne); + north = math.max(north, bounds.north); + south = math.min(south, bounds.south); + east = math.max(east, bounds.east); + west = math.min(west, bounds.west); } - void _extend(LatLng sw2, LatLng ne2) { - _sw = LatLng( - math.min(sw2.latitude, _sw.latitude), - math.min(sw2.longitude, _sw.longitude), - ); - _ne = LatLng( - math.max(ne2.latitude, _ne.latitude), - math.max(ne2.longitude, _ne.longitude), - ); - } - - /// Obtain west edge of the bounds - double get west => southWest.longitude; - - /// Obtain south edge of the bounds - double get south => southWest.latitude; - - /// Obtain east edge of the bounds - double get east => northEast.longitude; - - /// Obtain north edge of the bounds - double get north => northEast.latitude; - /// Obtain coordinates of southwest corner of the bounds - LatLng get southWest => _sw; + LatLng get southWest => LatLng(south, west); /// Obtain coordinates of northeast corner of the bounds - LatLng get northEast => _ne; + LatLng get northEast => LatLng(north, east); /// Obtain coordinates of northwest corner of the bounds LatLng get northWest => LatLng(north, west); @@ -90,23 +117,19 @@ class LatLngBounds { /// Obtain coordinates of the bounds center LatLng get center { - /* https://stackoverflow.com/a/4656937 - http://www.movable-type.co.uk/scripts/latlong.html + // https://stackoverflow.com/a/4656937 + // http://www.movable-type.co.uk/scripts/latlong.html + // coord 1: southWest + // coord 2: northEast + // phi: lat + // lambda: lng - coord 1: southWest - coord 2: northEast + final phi1 = south * degrees2Radians; + final lambda1 = west * degrees2Radians; + final phi2 = north * degrees2Radians; - phi: lat - lambda: lng - */ - - final phi1 = southWest.latitudeInRad; - final lambda1 = southWest.longitudeInRad; - final phi2 = northEast.latitudeInRad; - - final dLambda = degrees2Radians * - (northEast.longitude - - southWest.longitude); // delta lambda = lambda2-lambda1 + // delta lambda = lambda2-lambda1 + final dLambda = degrees2Radians * (east - west); final bx = math.cos(phi2) * math.cos(dLambda); final by = math.cos(phi2) * math.sin(dLambda); @@ -119,41 +142,38 @@ class LatLngBounds { } /// Checks whether [point] is inside bounds - bool contains(LatLng point) { - final sw2 = point; - final ne2 = point; - return containsBounds(LatLngBounds(sw2, ne2)); - } - - /// Checks whether [bounds] is contained inside bounds - bool containsBounds(LatLngBounds bounds) { - final sw2 = bounds._sw; - final ne2 = bounds._ne; - return (sw2.latitude >= _sw.latitude) && - (ne2.latitude <= _ne.latitude) && - (sw2.longitude >= _sw.longitude) && - (ne2.longitude <= _ne.longitude); - } - - /// Checks whether at least one edge of [bounds] is overlapping with some - /// other edge of bounds - bool isOverlapping(LatLngBounds bounds) { - /* check if bounding box rectangle is outside the other, if it is then it's - considered not overlapping - */ - if (_sw.latitude > bounds._ne.latitude || - _ne.latitude < bounds._sw.latitude || - _ne.longitude < bounds._sw.longitude || - _sw.longitude > bounds._ne.longitude) { - return false; - } - return true; - } + bool contains(LatLng point) => + point.longitude >= west && + point.longitude <= east && + point.latitude >= south && + point.latitude <= north; + + /// Checks whether the [other] bounding box is contained inside bounds. + bool containsBounds(LatLngBounds other) => + other.south >= south && + other.north <= north && + other.west >= west && + other.east <= east; + + /// Checks whether at least one edge of the [other] bounding box is + /// overlapping with this bounding box. + /// + /// Bounding boxes that touch each other but don't overlap are counted as + /// not overlapping. + bool isOverlapping(LatLngBounds other) => !(south > other.north || + north < other.south || + east < other.west || + west > other.east); @override - int get hashCode => Object.hash(_sw, _ne); + int get hashCode => Object.hash(south, north, east, west); @override bool operator ==(Object other) => - other is LatLngBounds && other._sw == _sw && other._ne == _ne; + identical(this, other) || + (other is LatLngBounds && + other.north == north && + other.south == south && + other.east == east && + other.west == west); } From c11e77891e6be52a091b5c6a71bb187a8d7034eb Mon Sep 17 00:00:00 2001 From: Joscha <34318751+josxha@users.noreply.github.com> Date: Tue, 20 Feb 2024 22:51:47 +0100 Subject: [PATCH 2/8] update tests and example app --- example/lib/pages/bundled_offline_map.dart | 2 +- .../lib/pages/cancellable_tile_provider.dart | 2 +- example/lib/pages/epsg3413_crs.dart | 2 +- example/lib/pages/home.dart | 2 +- example/lib/pages/many_circles.dart | 2 +- example/lib/pages/many_markers.dart | 2 +- example/lib/pages/overlay_image.dart | 2 +- example/lib/pages/polygon_perf_stress.dart | 2 +- example/lib/pages/sliding_map.dart | 2 +- lib/src/map/camera/camera.dart | 2 +- test/geo/latlng_bounds_test.dart | 6 +- .../tile_bounds/tile_bounds_test.dart | 2 +- test/map/camera/camera_constraint_test.dart | 2 +- test/map/map_controller_test.dart | 170 +++++++++--------- 14 files changed, 100 insertions(+), 100 deletions(-) diff --git a/example/lib/pages/bundled_offline_map.dart b/example/lib/pages/bundled_offline_map.dart index dff0ebc34..bc32f6169 100644 --- a/example/lib/pages/bundled_offline_map.dart +++ b/example/lib/pages/bundled_offline_map.dart @@ -19,7 +19,7 @@ class BundledOfflineMapPage extends StatelessWidget { minZoom: 12, maxZoom: 14, cameraConstraint: CameraConstraint.containCenter( - bounds: LatLngBounds( + bounds: LatLngBounds.fromCorners( const LatLng(56.7378, 11.6644), const LatLng(56.6877, 11.5089), ), diff --git a/example/lib/pages/cancellable_tile_provider.dart b/example/lib/pages/cancellable_tile_provider.dart index aac67c461..6fb9dbbcd 100644 --- a/example/lib/pages/cancellable_tile_provider.dart +++ b/example/lib/pages/cancellable_tile_provider.dart @@ -50,7 +50,7 @@ class _CancellableTileProviderPageState initialCenter: const LatLng(51.5, -0.09), initialZoom: 5, cameraConstraint: CameraConstraint.contain( - bounds: LatLngBounds( + bounds: LatLngBounds.fromCorners( const LatLng(-90, -180), const LatLng(90, 180), ), diff --git a/example/lib/pages/epsg3413_crs.dart b/example/lib/pages/epsg3413_crs.dart index b72fb1c36..f9ea8313f 100644 --- a/example/lib/pages/epsg3413_crs.dart +++ b/example/lib/pages/epsg3413_crs.dart @@ -153,7 +153,7 @@ class EPSG3413PageState extends State { OverlayImageLayer( overlayImages: [ OverlayImage( - bounds: LatLngBounds( + bounds: LatLngBounds.fromCorners( const LatLng(72.7911372, 162.6196478), const LatLng(85.2802493, 79.794166), ), diff --git a/example/lib/pages/home.dart b/example/lib/pages/home.dart index 2cf3c2f0b..e7be73853 100644 --- a/example/lib/pages/home.dart +++ b/example/lib/pages/home.dart @@ -37,7 +37,7 @@ class _HomePageState extends State { initialCenter: const LatLng(51.5, -0.09), initialZoom: 5, cameraConstraint: CameraConstraint.contain( - bounds: LatLngBounds( + bounds: LatLngBounds.fromCorners( const LatLng(-90, -180), const LatLng(90, 180), ), diff --git a/example/lib/pages/many_circles.dart b/example/lib/pages/many_circles.dart index 4c8989607..512c67edd 100644 --- a/example/lib/pages/many_circles.dart +++ b/example/lib/pages/many_circles.dart @@ -62,7 +62,7 @@ class ManyCirclesPageState extends State { FlutterMap( options: MapOptions( initialCameraFit: CameraFit.bounds( - bounds: LatLngBounds( + bounds: LatLngBounds.fromCorners( const LatLng(55, -9), const LatLng(37, 30), ), diff --git a/example/lib/pages/many_markers.dart b/example/lib/pages/many_markers.dart index 8b3f54545..60e395a18 100644 --- a/example/lib/pages/many_markers.dart +++ b/example/lib/pages/many_markers.dart @@ -63,7 +63,7 @@ class ManyMarkersPageState extends State { FlutterMap( options: MapOptions( initialCameraFit: CameraFit.bounds( - bounds: LatLngBounds( + bounds: LatLngBounds.fromCorners( const LatLng(55, -9), const LatLng(37, 30), ), diff --git a/example/lib/pages/overlay_image.dart b/example/lib/pages/overlay_image.dart index 761927b3c..93e22bfc3 100644 --- a/example/lib/pages/overlay_image.dart +++ b/example/lib/pages/overlay_image.dart @@ -24,7 +24,7 @@ class OverlayImagePage extends StatelessWidget { OverlayImageLayer( overlayImages: [ OverlayImage( - bounds: LatLngBounds( + bounds: LatLngBounds.fromCorners( const LatLng(51.5, -0.09), const LatLng(48.8566, 2.3522), ), diff --git a/example/lib/pages/polygon_perf_stress.dart b/example/lib/pages/polygon_perf_stress.dart index 086ab727c..61fe7bf0a 100644 --- a/example/lib/pages/polygon_perf_stress.dart +++ b/example/lib/pages/polygon_perf_stress.dart @@ -47,7 +47,7 @@ class _PolygonPerfStressPageState extends State { FlutterMap( options: MapOptions( initialCameraFit: CameraFit.bounds( - bounds: LatLngBounds( + bounds: LatLngBounds.fromCorners( const LatLng(58.93864, 47.757597), const LatLng(58.806666, 47.848959), ), diff --git a/example/lib/pages/sliding_map.dart b/example/lib/pages/sliding_map.dart index c15a32459..25520e103 100644 --- a/example/lib/pages/sliding_map.dart +++ b/example/lib/pages/sliding_map.dart @@ -32,7 +32,7 @@ class SlidingMapPage extends StatelessWidget { maxZoom: 14, initialZoom: 13, cameraConstraint: CameraConstraint.containCenter( - bounds: LatLngBounds(northEast, southWest), + bounds: LatLngBounds.fromCorners(northEast, southWest), ), ), children: [ diff --git a/lib/src/map/camera/camera.dart b/lib/src/map/camera/camera.dart index 4167930c0..3ad88e71c 100644 --- a/lib/src/map/camera/camera.dart +++ b/lib/src/map/camera/camera.dart @@ -57,7 +57,7 @@ class MapCamera { /// This is the [LatLngBounds] corresponding to four corners of this camera. /// This takes rotation in to account. - LatLngBounds get visibleBounds => _bounds ??= LatLngBounds( + LatLngBounds get visibleBounds => _bounds ??= LatLngBounds.fromCorners( unproject(pixelBounds.bottomLeft, zoom), unproject(pixelBounds.topRight, zoom), ); diff --git a/test/geo/latlng_bounds_test.dart b/test/geo/latlng_bounds_test.dart index 2509b0f60..1d00cc405 100644 --- a/test/geo/latlng_bounds_test.dart +++ b/test/geo/latlng_bounds_test.dart @@ -10,7 +10,7 @@ void main() { group('LatLngBounds constructor', () { test('with dublin, paris', () { - final bounds = LatLngBounds(dublin, paris); + final bounds = LatLngBounds.fromCorners(dublin, paris); expect(bounds, LatLngBounds.fromPoints([dublin, paris])); }); @@ -40,8 +40,8 @@ void main() { group('hashCode', () { test('with dublin, paris', () { - final bounds1 = LatLngBounds(dublin, paris); - final bounds2 = LatLngBounds(dublin, paris); + final bounds1 = LatLngBounds.fromCorners(dublin, paris); + final bounds2 = LatLngBounds.fromCorners(dublin, paris); expect(bounds1 == bounds2, isTrue); expect(bounds1.hashCode, bounds2.hashCode); diff --git a/test/layer/tile_layer/tile_bounds/tile_bounds_test.dart b/test/layer/tile_layer/tile_bounds/tile_bounds_test.dart index 354a5590e..2851358b8 100644 --- a/test/layer/tile_layer/tile_bounds/tile_bounds_test.dart +++ b/test/layer/tile_layer/tile_bounds/tile_bounds_test.dart @@ -91,7 +91,7 @@ void main() { final tileBounds = TileBounds( crs: crs, tileSize: 256, - latLngBounds: LatLngBounds( + latLngBounds: LatLngBounds.fromCorners( const LatLng(0, 0), crs.pointToLatLng(crs.getProjectedBounds(0)!.max, 0), ), diff --git a/test/map/camera/camera_constraint_test.dart b/test/map/camera/camera_constraint_test.dart index ff4a804db..a89a3859c 100644 --- a/test/map/camera/camera_constraint_test.dart +++ b/test/map/camera/camera_constraint_test.dart @@ -9,7 +9,7 @@ void main() { group('contain', () { test('rotated', () { final mapConstraint = CameraConstraint.contain( - bounds: LatLngBounds( + bounds: LatLngBounds.fromCorners( const LatLng(-90, -180), const LatLng(90, 180), ), diff --git a/test/map/map_controller_test.dart b/test/map/map_controller_test.dart index b7f8e4055..09cd81cfa 100644 --- a/test/map/map_controller_test.dart +++ b/test/map/map_controller_test.dart @@ -8,7 +8,7 @@ import '../test_utils/test_app.dart'; void main() { testWidgets('test fit bounds methods', (tester) async { final controller = MapController(); - final bounds = LatLngBounds( + final bounds = LatLngBounds.fromCorners( const LatLng(51, 0), const LatLng(52, 1), ); @@ -18,7 +18,7 @@ void main() { { final cameraConstraint = CameraFit.bounds(bounds: bounds); - final expectedBounds = LatLngBounds( + final expectedBounds = LatLngBounds.fromCorners( const LatLng(51.00145915187144, -0.3079873797085076), const LatLng(52.001427481787005, 1.298485398623206), ); @@ -38,7 +38,7 @@ void main() { forceIntegerZoomLevel: true, ); - final expectedBounds = LatLngBounds( + final expectedBounds = LatLngBounds.fromCorners( const LatLng(50.819818262156545, -0.6042480468750001), const LatLng(52.1874047455997, 1.5930175781250002), ); @@ -57,7 +57,7 @@ void main() { bounds: bounds, ); - final expectedBounds = LatLngBounds( + final expectedBounds = LatLngBounds.fromCorners( const LatLng(51.19148727133182, -6.195044477408375e-13), const LatLng(51.8139520195805, 0.999999999999397), ); @@ -78,7 +78,7 @@ void main() { forceIntegerZoomLevel: true, ); - final expectedBounds = LatLngBounds( + final expectedBounds = LatLngBounds.fromCorners( const LatLng(51.33232774035881, 0.22521972656250003), const LatLng(51.67425842259517, 0.7745361328125), ); @@ -95,7 +95,7 @@ void main() { testWidgets('test fit bounds methods with rotation', (tester) async { final controller = MapController(); - final bounds = LatLngBounds( + final bounds = LatLngBounds.fromCorners( const LatLng(4.214943, 33.925781), const LatLng(-1.362176, 29.575195), ); @@ -145,7 +145,7 @@ void main() { await testFitBounds( rotation: -360, cameraConstraint: CameraFit.bounds(bounds: bounds), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(4.220875035073316, 28.95466920920177), const LatLng(-1.3562295282017047, 34.53572340816548), ), @@ -155,7 +155,7 @@ void main() { await testFitBounds( rotation: -300, cameraConstraint: CameraFit.bounds(bounds: bounds), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(6.229878688707217, 26.943661553415026), const LatLng(-3.3298966942067114, 36.517625059412495), ), @@ -165,7 +165,7 @@ void main() { await testFitBounds( rotation: -240, cameraConstraint: CameraFit.bounds(bounds: bounds), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(6.229878688707217, 26.943661553415026), const LatLng(-3.3298966942067114, 36.517625059412495), ), @@ -175,7 +175,7 @@ void main() { await testFitBounds( rotation: -180, cameraConstraint: CameraFit.bounds(bounds: bounds), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(4.220875035073316, 28.95466920920177), const LatLng(-1.3562295282017047, 34.53572340816548), ), @@ -185,7 +185,7 @@ void main() { await testFitBounds( rotation: -120, cameraConstraint: CameraFit.bounds(bounds: bounds), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(6.2298786887073065, 26.943661553414902), const LatLng(-3.329896694206635, 36.517625059412374), ), @@ -195,7 +195,7 @@ void main() { await testFitBounds( rotation: -60, cameraConstraint: CameraFit.bounds(bounds: bounds), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(6.2298786887073065, 26.943661553414902), const LatLng(-3.329896694206635, 36.517625059412374), ), @@ -205,7 +205,7 @@ void main() { await testFitBounds( rotation: 0, cameraConstraint: CameraFit.bounds(bounds: bounds), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(4.220875035073316, 28.95466920920177), const LatLng(-1.3562295282017047, 34.53572340816548), ), @@ -215,7 +215,7 @@ void main() { await testFitBounds( rotation: 60, cameraConstraint: CameraFit.bounds(bounds: bounds), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(6.229878688707217, 26.943661553415026), const LatLng(-3.3298966942067114, 36.517625059412495), ), @@ -225,7 +225,7 @@ void main() { await testFitBounds( rotation: 120, cameraConstraint: CameraFit.bounds(bounds: bounds), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(6.229878688707217, 26.943661553415026), const LatLng(-3.3298966942067114, 36.517625059412495), ), @@ -235,7 +235,7 @@ void main() { await testFitBounds( rotation: 180, cameraConstraint: CameraFit.bounds(bounds: bounds), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(4.220875035073316, 28.95466920920177), const LatLng(-1.3562295282017047, 34.53572340816548), ), @@ -245,7 +245,7 @@ void main() { await testFitBounds( rotation: 240, cameraConstraint: CameraFit.bounds(bounds: bounds), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(6.229878688706365, 26.94366155341602), const LatLng(-3.3298966942076276, 36.51762505941353), ), @@ -255,7 +255,7 @@ void main() { await testFitBounds( rotation: 300, cameraConstraint: CameraFit.bounds(bounds: bounds), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(6.229878688707217, 26.943661553415026), const LatLng(-3.3298966942067114, 36.517625059412495), ), @@ -265,7 +265,7 @@ void main() { await testFitBounds( rotation: 360, cameraConstraint: CameraFit.bounds(bounds: bounds), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(4.220875035073316, 28.95466920920177), const LatLng(-1.3562295282017047, 34.53572340816548), ), @@ -283,7 +283,7 @@ void main() { bounds: bounds, padding: symmetricPadding, ), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(4.604066851713044, 28.560190151047802), const LatLng(-1.732813138431261, 34.902297195324785), ), @@ -296,7 +296,7 @@ void main() { bounds: bounds, padding: symmetricPadding, ), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(6.862564855409817, 26.292484184306595), const LatLng(-3.997225315187129, 37.171988168394705), ), @@ -309,7 +309,7 @@ void main() { bounds: bounds, padding: symmetricPadding, ), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(6.862564855410326, 26.292484184305955), const LatLng(-3.9972253151865824, 37.17198816839402), ), @@ -322,7 +322,7 @@ void main() { bounds: bounds, padding: symmetricPadding, ), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(4.6040668517126235, 28.560190151048324), const LatLng(-1.7328131384316936, 34.9022971953253), ), @@ -335,7 +335,7 @@ void main() { bounds: bounds, padding: symmetricPadding, ), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(6.862564855410096, 26.292484184306193), const LatLng(-3.997225315186811, 37.17198816839431), ), @@ -348,7 +348,7 @@ void main() { bounds: bounds, padding: symmetricPadding, ), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(6.8625648554105165, 26.292484184305717), const LatLng(-3.9972253151863786, 37.17198816839379), ), @@ -361,7 +361,7 @@ void main() { bounds: bounds, padding: symmetricPadding, ), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(4.604066851712751, 28.560190151048204), const LatLng(-1.732813138431579, 34.90229719532515), ), @@ -374,7 +374,7 @@ void main() { bounds: bounds, padding: symmetricPadding, ), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(6.862564855410008, 26.292484184306353), const LatLng(-3.9972253151869386, 37.17198816839443), ), @@ -387,7 +387,7 @@ void main() { bounds: bounds, padding: symmetricPadding, ), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(6.8625648554105165, 26.292484184305717), const LatLng(-3.9972253151863786, 37.17198816839379), ), @@ -400,7 +400,7 @@ void main() { bounds: bounds, padding: symmetricPadding, ), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(4.6040668517126235, 28.560190151048324), const LatLng(-1.7328131384316936, 34.9022971953253), ), @@ -413,7 +413,7 @@ void main() { bounds: bounds, padding: symmetricPadding, ), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(6.862564855410008, 26.292484184306353), const LatLng(-3.9972253151869386, 37.17198816839443), ), @@ -426,7 +426,7 @@ void main() { bounds: bounds, padding: symmetricPadding, ), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(6.862564855411076, 26.292484184305035), const LatLng(-3.997225315185781, 37.171988168393064), ), @@ -439,7 +439,7 @@ void main() { bounds: bounds, padding: symmetricPadding, ), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(4.604066851711988, 28.56019015104908), const LatLng(-1.7328131384323806, 34.902297195326106), ), @@ -457,7 +457,7 @@ void main() { bounds: bounds, padding: asymmetricPadding, ), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(4.634132562246874, 28.54085445883965), const LatLng(-2.1664538621122844, 35.34701811611249), ), @@ -470,7 +470,7 @@ void main() { bounds: bounds, padding: asymmetricPadding, ), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(7.353914452121884, 26.258676859164435), const LatLng(-4.297341450189851, 37.9342421103809), ), @@ -483,7 +483,7 @@ void main() { bounds: bounds, padding: asymmetricPadding, ), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(7.6081448623143, 26.00226365003461), const LatLng(-4.041607090303907, 37.677828901251075), ), @@ -496,7 +496,7 @@ void main() { bounds: bounds, padding: asymmetricPadding, ), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(5.041046797566381, 28.132484639403017), const LatLng(-1.7583244079256093, 34.93864829667586), ), @@ -509,7 +509,7 @@ void main() { bounds: bounds, padding: asymmetricPadding, ), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(7.184346279929569, 25.53217276663045), const LatLng(-4.467783700569064, 37.207738017846864), ), @@ -522,7 +522,7 @@ void main() { bounds: bounds, padding: asymmetricPadding, ), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(6.929875826124592, 25.788585975760196), const LatLng(-4.723372343263628, 37.46415122697666), ), @@ -535,7 +535,7 @@ void main() { bounds: bounds, padding: asymmetricPadding, ), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(4.63413256224709, 28.540854458839405), const LatLng(-2.166453862112043, 35.347018116112245), ), @@ -548,7 +548,7 @@ void main() { bounds: bounds, padding: asymmetricPadding, ), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(7.353914452122737, 26.258676859163398), const LatLng(-4.297341450188935, 37.93424211037982), ), @@ -561,7 +561,7 @@ void main() { bounds: bounds, padding: asymmetricPadding, ), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(7.6081448623143, 26.00226365003461), const LatLng(-4.041607090303907, 37.677828901251075), ), @@ -574,7 +574,7 @@ void main() { bounds: bounds, padding: asymmetricPadding, ), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(5.041046797566381, 28.132484639403017), const LatLng(-1.7583244079256093, 34.93864829667586), ), @@ -587,7 +587,7 @@ void main() { bounds: bounds, padding: asymmetricPadding, ), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(7.184346279929569, 25.53217276663045), const LatLng(-4.467783700569064, 37.207738017846864), ), @@ -600,7 +600,7 @@ void main() { bounds: bounds, padding: asymmetricPadding, ), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(6.929875826125113, 25.788585975759595), const LatLng(-4.7233723432630805, 37.46415122697602), ), @@ -613,7 +613,7 @@ void main() { bounds: bounds, padding: asymmetricPadding, ), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(4.634132562246874, 28.54085445883965), const LatLng(-2.1664538621122844, 35.34701811611249), ), @@ -822,7 +822,7 @@ void main() { testWidgets('test fit inside bounds with rotation', (tester) async { final controller = MapController(); - final bounds = LatLngBounds( + final bounds = LatLngBounds.fromCorners( const LatLng(4.214943, 33.925781), const LatLng(-1.362176, 29.575195), ); @@ -874,7 +874,7 @@ void main() { cameraConstraint: CameraFit.insideBounds( bounds: bounds, ), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(3.6031134233301474, 29.56772762000039), const LatLng(-0.7450743699315154, 33.9183136200004), ), @@ -886,7 +886,7 @@ void main() { cameraConstraint: CameraFit.insideBounds( bounds: bounds, ), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(3.614278658020072, 29.56945889748712), const LatLng(-0.7338878844415404, 33.920044897487124), ), @@ -898,7 +898,7 @@ void main() { cameraConstraint: CameraFit.insideBounds( bounds: bounds, ), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(3.6142786580207207, 29.56945889748632), const LatLng(-0.7338878844408534, 33.92004489748633), ), @@ -910,7 +910,7 @@ void main() { cameraConstraint: CameraFit.insideBounds( bounds: bounds, ), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(3.6031134233301474, 29.56772762000039), const LatLng(-0.7450743699315154, 33.9183136200004), ), @@ -922,7 +922,7 @@ void main() { cameraConstraint: CameraFit.insideBounds( bounds: bounds, ), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(3.614278658020072, 29.56945889748712), const LatLng(-0.7338878844415404, 33.920044897487124), ), @@ -934,7 +934,7 @@ void main() { cameraConstraint: CameraFit.insideBounds( bounds: bounds, ), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(3.6142786580207207, 29.56945889748632), const LatLng(-0.7338878844408534, 33.92004489748633), ), @@ -946,7 +946,7 @@ void main() { cameraConstraint: CameraFit.insideBounds( bounds: bounds, ), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(3.6031134233301474, 29.56772762000039), const LatLng(-0.7450743699315154, 33.9183136200004), ), @@ -958,7 +958,7 @@ void main() { cameraConstraint: CameraFit.insideBounds( bounds: bounds, ), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(3.614278658020072, 29.56945889748712), const LatLng(-0.7338878844415404, 33.920044897487124), ), @@ -970,7 +970,7 @@ void main() { cameraConstraint: CameraFit.insideBounds( bounds: bounds, ), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(3.6142786580207207, 29.56945889748632), const LatLng(-0.7338878844408534, 33.92004489748633), ), @@ -982,7 +982,7 @@ void main() { cameraConstraint: CameraFit.insideBounds( bounds: bounds, ), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(3.6031134233301474, 29.56772762000039), const LatLng(-0.7450743699315154, 33.9183136200004), ), @@ -994,7 +994,7 @@ void main() { cameraConstraint: CameraFit.insideBounds( bounds: bounds, ), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(3.614278658020072, 29.56945889748712), const LatLng(-0.7338878844415404, 33.920044897487124), ), @@ -1006,7 +1006,7 @@ void main() { cameraConstraint: CameraFit.insideBounds( bounds: bounds, ), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(3.6142786580207207, 29.56945889748632), const LatLng(-0.7338878844408534, 33.92004489748633), ), @@ -1018,7 +1018,7 @@ void main() { cameraConstraint: CameraFit.insideBounds( bounds: bounds, ), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(3.6031134233301474, 29.56772762000039), const LatLng(-0.7450743699315154, 33.9183136200004), ), @@ -1036,7 +1036,7 @@ void main() { bounds: bounds, padding: equalPadding, ), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(3.8971355052392727, 29.273074295454837), const LatLng(-1.0436460563295582, 34.21692202272759), ), @@ -1049,7 +1049,7 @@ void main() { bounds: bounds, padding: equalPadding, ), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(3.900159833096254, 29.26631356795233), const LatLng(-1.0406152150025456, 34.21016129522507), ), @@ -1062,7 +1062,7 @@ void main() { bounds: bounds, padding: equalPadding, ), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(3.900159833095936, 29.266313567952732), const LatLng(-1.0406152150029018, 34.210161295225475), ), @@ -1075,7 +1075,7 @@ void main() { bounds: bounds, padding: equalPadding, ), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(3.897135505240036, 29.273074295453956), const LatLng(-1.0436460563287566, 34.21692202272667), ), @@ -1088,7 +1088,7 @@ void main() { bounds: bounds, padding: equalPadding, ), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(3.900159833096941, 29.26631356795153), const LatLng(-1.0406152150018586, 34.210161295224275), ), @@ -1101,7 +1101,7 @@ void main() { bounds: bounds, padding: equalPadding, ), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(3.9001598330968137, 29.266313567951688), const LatLng(-1.0406152150019858, 34.21016129522444), ), @@ -1114,7 +1114,7 @@ void main() { bounds: bounds, padding: equalPadding, ), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(3.921797222702341, 29.273074295454474), const LatLng(-1.0189308220167805, 34.21692202272719), ), @@ -1127,7 +1127,7 @@ void main() { bounds: bounds, padding: equalPadding, ), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(3.9001598330947402, 29.26631356795413), const LatLng(-1.0406152150040977, 34.21016129522692), ), @@ -1140,7 +1140,7 @@ void main() { bounds: bounds, padding: equalPadding, ), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(3.900159833097259, 29.26631356795117), const LatLng(-1.0406152150015406, 34.21016129522388), ), @@ -1153,7 +1153,7 @@ void main() { bounds: bounds, padding: equalPadding, ), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(3.897135505238624, 29.273074295455597), const LatLng(-1.0436460563302323, 34.21692202272835), ), @@ -1166,7 +1166,7 @@ void main() { bounds: bounds, padding: equalPadding, ), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(3.900159833097577, 29.266313567950775), const LatLng(-1.0406152150011843, 34.21016129522348), ), @@ -1179,7 +1179,7 @@ void main() { bounds: bounds, padding: equalPadding, ), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(3.900159833095936, 29.266313567952732), const LatLng(-1.0406152150029018, 34.210161295225475), ), @@ -1192,7 +1192,7 @@ void main() { bounds: bounds, padding: equalPadding, ), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(3.897135505240036, 29.273074295453956), const LatLng(-1.0436460563287566, 34.21692202272667), ), @@ -1210,7 +1210,7 @@ void main() { bounds: bounds, padding: asymmetricPadding, ), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(3.93081962068567, 29.252575414633416), const LatLng(-1.371554855609733, 34.558168097560255), ), @@ -1223,7 +1223,7 @@ void main() { bounds: bounds, padding: asymmetricPadding, ), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(4.12285573833763, 29.236827391148324), const LatLng(-1.179091165662991, 34.5424200740752), ), @@ -1236,7 +1236,7 @@ void main() { bounds: bounds, padding: asymmetricPadding, ), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(4.239064535667103, 29.12030848890263), const LatLng(-1.0625945779487183, 34.42590117182947), ), @@ -1249,7 +1249,7 @@ void main() { bounds: bounds, padding: asymmetricPadding, ), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(4.248344214607476, 28.934239853659207), const LatLng(-1.0532909733871119, 34.239832536586086), ), @@ -1262,7 +1262,7 @@ void main() { bounds: bounds, padding: asymmetricPadding, ), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(4.045373737414225, 28.926110318495112), const LatLng(-1.2567528788718025, 34.23170300142199), ), @@ -1275,7 +1275,7 @@ void main() { bounds: bounds, padding: asymmetricPadding, ), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(3.9291368844072636, 29.04262922073941), const LatLng(-1.373241074234739, 34.34822190366625), ), @@ -1288,7 +1288,7 @@ void main() { bounds: bounds, padding: asymmetricPadding, ), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(3.9308196206843724, 29.252575414634972), const LatLng(-1.3715548556110944, 34.55816809756181), ), @@ -1301,7 +1301,7 @@ void main() { bounds: bounds, padding: asymmetricPadding, ), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(4.122855738337325, 29.236827391148683), const LatLng(-1.179091165663309, 34.542420074075565), ), @@ -1314,7 +1314,7 @@ void main() { bounds: bounds, padding: asymmetricPadding, ), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(4.23906453566681, 29.12030848890299), const LatLng(-1.0625945779490364, 34.42590117182983), ), @@ -1327,7 +1327,7 @@ void main() { bounds: bounds, padding: asymmetricPadding, ), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(4.248344214608647, 28.934239853657804), const LatLng(-1.053290973385865, 34.23983253658464), ), @@ -1340,7 +1340,7 @@ void main() { bounds: bounds, padding: asymmetricPadding, ), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(4.045373737414429, 28.926110318494874), const LatLng(-1.2567528788715607, 34.23170300142176), ), @@ -1353,7 +1353,7 @@ void main() { bounds: bounds, padding: asymmetricPadding, ), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(3.9291368844075816, 29.04262922073901), const LatLng(-1.3732410742343828, 34.348221903665845), ), @@ -1366,7 +1366,7 @@ void main() { bounds: bounds, padding: asymmetricPadding, ), - expectedBounds: LatLngBounds( + expectedBounds: LatLngBounds.fromCorners( const LatLng(3.9308196206847033, 29.252575414634578), const LatLng(-1.3715548556107255, 34.55816809756141), ), From 630b9744f0d959d0ce73b0786da3b4ff4d7332f8 Mon Sep 17 00:00:00 2001 From: Joscha <34318751+josxha@users.noreply.github.com> Date: Tue, 20 Feb 2024 22:57:03 +0100 Subject: [PATCH 3/8] update usages of LatLngBounds in package --- lib/src/geo/latlng_bounds.dart | 4 ++++ lib/src/layer/polyline_layer/polyline_layer.dart | 12 ++++-------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/src/geo/latlng_bounds.dart b/lib/src/geo/latlng_bounds.dart index e0a689bd1..60cd6aac3 100644 --- a/lib/src/geo/latlng_bounds.dart +++ b/lib/src/geo/latlng_bounds.dart @@ -19,6 +19,10 @@ class LatLngBounds { double west; /// Create a [LatLngBounds] instance from raw edge values. + /// + /// Potentially throws assertion errors if the coordinates exceed their max + /// or min values or if coordinates are meant to be smaller / bigger + /// but aren't. LatLngBounds({ required this.north, required this.south, diff --git a/lib/src/layer/polyline_layer/polyline_layer.dart b/lib/src/layer/polyline_layer/polyline_layer.dart index 6c4a0361c..0619d52ef 100644 --- a/lib/src/layer/polyline_layer/polyline_layer.dart +++ b/lib/src/layer/polyline_layer/polyline_layer.dart @@ -168,14 +168,10 @@ class _PolylineLayerState extends State> { // The min(-90), max(180), ... are used to get around the limits of LatLng // the value cannot be greater or smaller than that final boundsAdjusted = LatLngBounds( - LatLng( - math.max(-90, bounds.southWest.latitude - margin), - math.max(-180, bounds.southWest.longitude - margin), - ), - LatLng( - math.min(90, bounds.northEast.latitude + margin), - math.min(180, bounds.northEast.longitude + margin), - ), + east: math.max(-180, bounds.southWest.longitude - margin), + west: math.min(90, bounds.northEast.latitude + margin), + north: math.max(-90, bounds.southWest.latitude - margin), + south: math.min(180, bounds.northEast.longitude + margin), ); // segment is visible From 07e302f48dd47a2b0a139ed4fcd46b37b0c3c827 Mon Sep 17 00:00:00 2001 From: Joscha <34318751+josxha@users.noreply.github.com> Date: Tue, 20 Feb 2024 23:10:13 +0100 Subject: [PATCH 4/8] make LatLngBounds extend functions safe --- lib/src/geo/latlng_bounds.dart | 52 +++++++++++-------- .../layer/polyline_layer/polyline_layer.dart | 8 +-- 2 files changed, 34 insertions(+), 26 deletions(-) diff --git a/lib/src/geo/latlng_bounds.dart b/lib/src/geo/latlng_bounds.dart index 60cd6aac3..3a6323f95 100644 --- a/lib/src/geo/latlng_bounds.dart +++ b/lib/src/geo/latlng_bounds.dart @@ -1,4 +1,4 @@ -import 'dart:math' as math; +import 'dart:math'; import 'package:latlong2/latlong.dart'; import 'package:vector_math/vector_math_64.dart'; @@ -28,14 +28,22 @@ class LatLngBounds { required this.south, required this.east, required this.west, - }) : assert(north <= 90, "The north latitude can't be bigger than 90."), - assert(north >= -90, "The north latitude can't be smaller than -90."), - assert(south <= 90, "The south latitude can't be bigger than 90."), - assert(south >= -90, "The south latitude can't be smaller than -90."), - assert(east <= 180, "The east longitude can't be bigger than 180."), - assert(east >= -180, "The east longitude can't be smaller than -180."), - assert(west <= 180, "The west longitude can't be bigger than 180."), - assert(west >= -180, "The west longitude can't be smaller than -180."), + }) : assert( + north <= 90, "The north latitude can't be bigger than 90: $north"), + assert(north >= -90, + "The north latitude can't be smaller than -90: $north"), + assert( + south <= 90, "The south latitude can't be bigger than 90: $south"), + assert(south >= -90, + "The south latitude can't be smaller than -90: $south"), + assert( + east <= 180, "The east longitude can't be bigger than 180: $east"), + assert(east >= -180, + "The east longitude can't be smaller than -180: $east"), + assert( + west <= 180, "The west longitude can't be bigger than 180: $west"), + assert(west >= -180, + "The west longitude can't be smaller than -180: $west"), assert(north >= south, "The north latitude can't be smaller than the south latitude"), assert(east >= west, @@ -91,20 +99,20 @@ class LatLngBounds { /// Expands bounding box by [latLng] coordinate point. This method mutates /// the bounds object on which it is called. void extend(LatLng latLng) { - north = math.max(north, latLng.latitude); - south = math.min(south, latLng.latitude); - east = math.max(east, latLng.longitude); - west = math.min(west, latLng.longitude); + north = min(90, max(north, latLng.latitude)); + south = max(-90, min(south, latLng.latitude)); + east = min(180, max(east, latLng.longitude)); + west = max(-180, min(west, latLng.longitude)); } /// Expands bounding box by other [bounds] object. If provided [bounds] object /// is smaller than current one, it is not shrunk. This method mutates /// the bounds object on which it is called. void extendBounds(LatLngBounds bounds) { - north = math.max(north, bounds.north); - south = math.min(south, bounds.south); - east = math.max(east, bounds.east); - west = math.min(west, bounds.west); + north = min(90, max(north, bounds.north)); + south = max(-90, min(south, bounds.south)); + east = min(180, max(east, bounds.east)); + west = max(-180, min(west, bounds.west)); } /// Obtain coordinates of southwest corner of the bounds @@ -135,11 +143,11 @@ class LatLngBounds { // delta lambda = lambda2-lambda1 final dLambda = degrees2Radians * (east - west); - final bx = math.cos(phi2) * math.cos(dLambda); - final by = math.cos(phi2) * math.sin(dLambda); - final phi3 = math.atan2(math.sin(phi1) + math.sin(phi2), - math.sqrt((math.cos(phi1) + bx) * (math.cos(phi1) + bx) + by * by)); - final lambda3 = lambda1 + math.atan2(by, math.cos(phi1) + bx); + final bx = cos(phi2) * cos(dLambda); + final by = cos(phi2) * sin(dLambda); + final phi3 = atan2(sin(phi1) + sin(phi2), + sqrt((cos(phi1) + bx) * (cos(phi1) + bx) + by * by)); + final lambda3 = lambda1 + atan2(by, cos(phi1) + bx); // phi3 and lambda3 are actually in radians and LatLng wants degrees return LatLng(phi3 * radians2Degrees, lambda3 * radians2Degrees); diff --git a/lib/src/layer/polyline_layer/polyline_layer.dart b/lib/src/layer/polyline_layer/polyline_layer.dart index 0619d52ef..c5b4df874 100644 --- a/lib/src/layer/polyline_layer/polyline_layer.dart +++ b/lib/src/layer/polyline_layer/polyline_layer.dart @@ -168,10 +168,10 @@ class _PolylineLayerState extends State> { // The min(-90), max(180), ... are used to get around the limits of LatLng // the value cannot be greater or smaller than that final boundsAdjusted = LatLngBounds( - east: math.max(-180, bounds.southWest.longitude - margin), - west: math.min(90, bounds.northEast.latitude + margin), - north: math.max(-90, bounds.southWest.latitude - margin), - south: math.min(180, bounds.northEast.longitude + margin), + west: math.max(-180, bounds.west - margin), + east: math.min(90, bounds.east + margin), + south: math.max(-90, bounds.south - margin), + north: math.min(180, bounds.north + margin), ); // segment is visible From 0b71707a9996dcd681fa532641925f4875eb4eb1 Mon Sep 17 00:00:00 2001 From: Joscha <34318751+josxha@users.noreply.github.com> Date: Tue, 12 Mar 2024 13:51:40 +0100 Subject: [PATCH 5/8] requested changes from https://github.com/fleaflet/flutter_map/pull/1834#discussion_r1518833146 --- example/lib/pages/bundled_offline_map.dart | 2 +- .../lib/pages/cancellable_tile_provider.dart | 2 +- example/lib/pages/epsg3413_crs.dart | 2 +- example/lib/pages/home.dart | 2 +- example/lib/pages/many_circles.dart | 2 +- example/lib/pages/many_markers.dart | 2 +- example/lib/pages/overlay_image.dart | 2 +- example/lib/pages/polygon_perf_stress.dart | 2 +- example/lib/pages/sliding_map.dart | 2 +- lib/src/geo/latlng_bounds.dart | 67 ++++--- .../layer/polyline_layer/polyline_layer.dart | 2 +- lib/src/map/camera/camera.dart | 2 +- test/geo/latlng_bounds_test.dart | 6 +- .../tile_bounds/tile_bounds_test.dart | 2 +- test/map/camera/camera_constraint_test.dart | 2 +- test/map/map_controller_test.dart | 170 +++++++++--------- 16 files changed, 141 insertions(+), 128 deletions(-) diff --git a/example/lib/pages/bundled_offline_map.dart b/example/lib/pages/bundled_offline_map.dart index bc32f6169..dff0ebc34 100644 --- a/example/lib/pages/bundled_offline_map.dart +++ b/example/lib/pages/bundled_offline_map.dart @@ -19,7 +19,7 @@ class BundledOfflineMapPage extends StatelessWidget { minZoom: 12, maxZoom: 14, cameraConstraint: CameraConstraint.containCenter( - bounds: LatLngBounds.fromCorners( + bounds: LatLngBounds( const LatLng(56.7378, 11.6644), const LatLng(56.6877, 11.5089), ), diff --git a/example/lib/pages/cancellable_tile_provider.dart b/example/lib/pages/cancellable_tile_provider.dart index 6fb9dbbcd..aac67c461 100644 --- a/example/lib/pages/cancellable_tile_provider.dart +++ b/example/lib/pages/cancellable_tile_provider.dart @@ -50,7 +50,7 @@ class _CancellableTileProviderPageState initialCenter: const LatLng(51.5, -0.09), initialZoom: 5, cameraConstraint: CameraConstraint.contain( - bounds: LatLngBounds.fromCorners( + bounds: LatLngBounds( const LatLng(-90, -180), const LatLng(90, 180), ), diff --git a/example/lib/pages/epsg3413_crs.dart b/example/lib/pages/epsg3413_crs.dart index f9ea8313f..b72fb1c36 100644 --- a/example/lib/pages/epsg3413_crs.dart +++ b/example/lib/pages/epsg3413_crs.dart @@ -153,7 +153,7 @@ class EPSG3413PageState extends State { OverlayImageLayer( overlayImages: [ OverlayImage( - bounds: LatLngBounds.fromCorners( + bounds: LatLngBounds( const LatLng(72.7911372, 162.6196478), const LatLng(85.2802493, 79.794166), ), diff --git a/example/lib/pages/home.dart b/example/lib/pages/home.dart index f54677596..a63062ff6 100644 --- a/example/lib/pages/home.dart +++ b/example/lib/pages/home.dart @@ -37,7 +37,7 @@ class _HomePageState extends State { initialCenter: const LatLng(51.5, -0.09), initialZoom: 5, cameraConstraint: CameraConstraint.contain( - bounds: LatLngBounds.fromCorners( + bounds: LatLngBounds( const LatLng(-90, -180), const LatLng(90, 180), ), diff --git a/example/lib/pages/many_circles.dart b/example/lib/pages/many_circles.dart index 512c67edd..4c8989607 100644 --- a/example/lib/pages/many_circles.dart +++ b/example/lib/pages/many_circles.dart @@ -62,7 +62,7 @@ class ManyCirclesPageState extends State { FlutterMap( options: MapOptions( initialCameraFit: CameraFit.bounds( - bounds: LatLngBounds.fromCorners( + bounds: LatLngBounds( const LatLng(55, -9), const LatLng(37, 30), ), diff --git a/example/lib/pages/many_markers.dart b/example/lib/pages/many_markers.dart index 60e395a18..8b3f54545 100644 --- a/example/lib/pages/many_markers.dart +++ b/example/lib/pages/many_markers.dart @@ -63,7 +63,7 @@ class ManyMarkersPageState extends State { FlutterMap( options: MapOptions( initialCameraFit: CameraFit.bounds( - bounds: LatLngBounds.fromCorners( + bounds: LatLngBounds( const LatLng(55, -9), const LatLng(37, 30), ), diff --git a/example/lib/pages/overlay_image.dart b/example/lib/pages/overlay_image.dart index 93e22bfc3..761927b3c 100644 --- a/example/lib/pages/overlay_image.dart +++ b/example/lib/pages/overlay_image.dart @@ -24,7 +24,7 @@ class OverlayImagePage extends StatelessWidget { OverlayImageLayer( overlayImages: [ OverlayImage( - bounds: LatLngBounds.fromCorners( + bounds: LatLngBounds( const LatLng(51.5, -0.09), const LatLng(48.8566, 2.3522), ), diff --git a/example/lib/pages/polygon_perf_stress.dart b/example/lib/pages/polygon_perf_stress.dart index 61fe7bf0a..086ab727c 100644 --- a/example/lib/pages/polygon_perf_stress.dart +++ b/example/lib/pages/polygon_perf_stress.dart @@ -47,7 +47,7 @@ class _PolygonPerfStressPageState extends State { FlutterMap( options: MapOptions( initialCameraFit: CameraFit.bounds( - bounds: LatLngBounds.fromCorners( + bounds: LatLngBounds( const LatLng(58.93864, 47.757597), const LatLng(58.806666, 47.848959), ), diff --git a/example/lib/pages/sliding_map.dart b/example/lib/pages/sliding_map.dart index 25520e103..c15a32459 100644 --- a/example/lib/pages/sliding_map.dart +++ b/example/lib/pages/sliding_map.dart @@ -32,7 +32,7 @@ class SlidingMapPage extends StatelessWidget { maxZoom: 14, initialZoom: 13, cameraConstraint: CameraConstraint.containCenter( - bounds: LatLngBounds.fromCorners(northEast, southWest), + bounds: LatLngBounds(northEast, southWest), ), ), children: [ diff --git a/lib/src/geo/latlng_bounds.dart b/lib/src/geo/latlng_bounds.dart index 3a6323f95..102856021 100644 --- a/lib/src/geo/latlng_bounds.dart +++ b/lib/src/geo/latlng_bounds.dart @@ -18,12 +18,45 @@ class LatLngBounds { /// The longitude west edge of the bounds double west; + /// Create new [LatLngBounds] by providing two corners. Both corners have to + /// be on opposite sites but it doesn't matter which opposite corners or in + /// what order the corners are provided. + /// + /// If you want to create [LatLngBounds] with raw values, use the + /// [LatLngBounds.unsafe] constructor instead. + factory LatLngBounds(LatLng corner1, LatLng corner2) { + final double minX; + final double maxX; + final double minY; + final double maxY; + if (corner1.longitude >= corner2.longitude) { + maxX = corner1.longitude; + minX = corner2.longitude; + } else { + maxX = corner2.longitude; + minX = corner1.longitude; + } + if (corner1.latitude >= corner2.latitude) { + maxY = corner1.latitude; + minY = corner2.latitude; + } else { + maxY = corner2.latitude; + minY = corner1.latitude; + } + return LatLngBounds.unsafe( + north: maxY, + south: minY, + east: maxX, + west: minX, + ); + } + /// Create a [LatLngBounds] instance from raw edge values. /// /// Potentially throws assertion errors if the coordinates exceed their max /// or min values or if coordinates are meant to be smaller / bigger /// but aren't. - LatLngBounds({ + LatLngBounds.unsafe({ required this.north, required this.south, required this.east, @@ -49,31 +82,6 @@ class LatLngBounds { assert(east >= west, "The west longitude can't be smaller than the east longitude"); - /// Create new [LatLngBounds] by providing two corners. Both corners have to - /// be on opposite sites but it doesn't matter which opposite corners or in - /// what order the corners are provided. - factory LatLngBounds.fromCorners(LatLng corner1, LatLng corner2) { - final double minX; - final double maxX; - final double minY; - final double maxY; - if (corner1.longitude >= corner2.longitude) { - maxX = corner1.longitude; - minX = corner2.longitude; - } else { - maxX = corner2.longitude; - minX = corner1.longitude; - } - if (corner1.latitude >= corner2.latitude) { - maxY = corner1.latitude; - minY = corner2.latitude; - } else { - maxY = corner2.latitude; - minY = corner1.latitude; - } - return LatLngBounds(north: maxY, south: minY, east: maxX, west: minX); - } - /// Create a new [LatLngBounds] from a list of [LatLng] points. This /// calculates the bounding box of the provided points. factory LatLngBounds.fromPoints(List points) { @@ -93,7 +101,12 @@ class LatLngBounds { if (point.latitude < minY) minY = point.latitude; if (point.latitude > maxY) maxY = point.latitude; } - return LatLngBounds(north: maxY, south: minY, east: maxX, west: minX); + return LatLngBounds.unsafe( + north: maxY, + south: minY, + east: maxX, + west: minX, + ); } /// Expands bounding box by [latLng] coordinate point. This method mutates diff --git a/lib/src/layer/polyline_layer/polyline_layer.dart b/lib/src/layer/polyline_layer/polyline_layer.dart index c5b4df874..a373ffbb9 100644 --- a/lib/src/layer/polyline_layer/polyline_layer.dart +++ b/lib/src/layer/polyline_layer/polyline_layer.dart @@ -167,7 +167,7 @@ class _PolylineLayerState extends State> { // The min(-90), max(180), ... are used to get around the limits of LatLng // the value cannot be greater or smaller than that - final boundsAdjusted = LatLngBounds( + final boundsAdjusted = LatLngBounds.unsafe( west: math.max(-180, bounds.west - margin), east: math.min(90, bounds.east + margin), south: math.max(-90, bounds.south - margin), diff --git a/lib/src/map/camera/camera.dart b/lib/src/map/camera/camera.dart index eb7e9a9a4..2bd37d522 100644 --- a/lib/src/map/camera/camera.dart +++ b/lib/src/map/camera/camera.dart @@ -57,7 +57,7 @@ class MapCamera { /// This is the [LatLngBounds] corresponding to four corners of this camera. /// This takes rotation in to account. - LatLngBounds get visibleBounds => _bounds ??= LatLngBounds.fromCorners( + LatLngBounds get visibleBounds => _bounds ??= LatLngBounds( unproject(pixelBounds.bottomLeft, zoom), unproject(pixelBounds.topRight, zoom), ); diff --git a/test/geo/latlng_bounds_test.dart b/test/geo/latlng_bounds_test.dart index 1d00cc405..2509b0f60 100644 --- a/test/geo/latlng_bounds_test.dart +++ b/test/geo/latlng_bounds_test.dart @@ -10,7 +10,7 @@ void main() { group('LatLngBounds constructor', () { test('with dublin, paris', () { - final bounds = LatLngBounds.fromCorners(dublin, paris); + final bounds = LatLngBounds(dublin, paris); expect(bounds, LatLngBounds.fromPoints([dublin, paris])); }); @@ -40,8 +40,8 @@ void main() { group('hashCode', () { test('with dublin, paris', () { - final bounds1 = LatLngBounds.fromCorners(dublin, paris); - final bounds2 = LatLngBounds.fromCorners(dublin, paris); + final bounds1 = LatLngBounds(dublin, paris); + final bounds2 = LatLngBounds(dublin, paris); expect(bounds1 == bounds2, isTrue); expect(bounds1.hashCode, bounds2.hashCode); diff --git a/test/layer/tile_layer/tile_bounds/tile_bounds_test.dart b/test/layer/tile_layer/tile_bounds/tile_bounds_test.dart index 2851358b8..354a5590e 100644 --- a/test/layer/tile_layer/tile_bounds/tile_bounds_test.dart +++ b/test/layer/tile_layer/tile_bounds/tile_bounds_test.dart @@ -91,7 +91,7 @@ void main() { final tileBounds = TileBounds( crs: crs, tileSize: 256, - latLngBounds: LatLngBounds.fromCorners( + latLngBounds: LatLngBounds( const LatLng(0, 0), crs.pointToLatLng(crs.getProjectedBounds(0)!.max, 0), ), diff --git a/test/map/camera/camera_constraint_test.dart b/test/map/camera/camera_constraint_test.dart index a89a3859c..ff4a804db 100644 --- a/test/map/camera/camera_constraint_test.dart +++ b/test/map/camera/camera_constraint_test.dart @@ -9,7 +9,7 @@ void main() { group('contain', () { test('rotated', () { final mapConstraint = CameraConstraint.contain( - bounds: LatLngBounds.fromCorners( + bounds: LatLngBounds( const LatLng(-90, -180), const LatLng(90, 180), ), diff --git a/test/map/map_controller_test.dart b/test/map/map_controller_test.dart index 09cd81cfa..b7f8e4055 100644 --- a/test/map/map_controller_test.dart +++ b/test/map/map_controller_test.dart @@ -8,7 +8,7 @@ import '../test_utils/test_app.dart'; void main() { testWidgets('test fit bounds methods', (tester) async { final controller = MapController(); - final bounds = LatLngBounds.fromCorners( + final bounds = LatLngBounds( const LatLng(51, 0), const LatLng(52, 1), ); @@ -18,7 +18,7 @@ void main() { { final cameraConstraint = CameraFit.bounds(bounds: bounds); - final expectedBounds = LatLngBounds.fromCorners( + final expectedBounds = LatLngBounds( const LatLng(51.00145915187144, -0.3079873797085076), const LatLng(52.001427481787005, 1.298485398623206), ); @@ -38,7 +38,7 @@ void main() { forceIntegerZoomLevel: true, ); - final expectedBounds = LatLngBounds.fromCorners( + final expectedBounds = LatLngBounds( const LatLng(50.819818262156545, -0.6042480468750001), const LatLng(52.1874047455997, 1.5930175781250002), ); @@ -57,7 +57,7 @@ void main() { bounds: bounds, ); - final expectedBounds = LatLngBounds.fromCorners( + final expectedBounds = LatLngBounds( const LatLng(51.19148727133182, -6.195044477408375e-13), const LatLng(51.8139520195805, 0.999999999999397), ); @@ -78,7 +78,7 @@ void main() { forceIntegerZoomLevel: true, ); - final expectedBounds = LatLngBounds.fromCorners( + final expectedBounds = LatLngBounds( const LatLng(51.33232774035881, 0.22521972656250003), const LatLng(51.67425842259517, 0.7745361328125), ); @@ -95,7 +95,7 @@ void main() { testWidgets('test fit bounds methods with rotation', (tester) async { final controller = MapController(); - final bounds = LatLngBounds.fromCorners( + final bounds = LatLngBounds( const LatLng(4.214943, 33.925781), const LatLng(-1.362176, 29.575195), ); @@ -145,7 +145,7 @@ void main() { await testFitBounds( rotation: -360, cameraConstraint: CameraFit.bounds(bounds: bounds), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(4.220875035073316, 28.95466920920177), const LatLng(-1.3562295282017047, 34.53572340816548), ), @@ -155,7 +155,7 @@ void main() { await testFitBounds( rotation: -300, cameraConstraint: CameraFit.bounds(bounds: bounds), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(6.229878688707217, 26.943661553415026), const LatLng(-3.3298966942067114, 36.517625059412495), ), @@ -165,7 +165,7 @@ void main() { await testFitBounds( rotation: -240, cameraConstraint: CameraFit.bounds(bounds: bounds), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(6.229878688707217, 26.943661553415026), const LatLng(-3.3298966942067114, 36.517625059412495), ), @@ -175,7 +175,7 @@ void main() { await testFitBounds( rotation: -180, cameraConstraint: CameraFit.bounds(bounds: bounds), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(4.220875035073316, 28.95466920920177), const LatLng(-1.3562295282017047, 34.53572340816548), ), @@ -185,7 +185,7 @@ void main() { await testFitBounds( rotation: -120, cameraConstraint: CameraFit.bounds(bounds: bounds), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(6.2298786887073065, 26.943661553414902), const LatLng(-3.329896694206635, 36.517625059412374), ), @@ -195,7 +195,7 @@ void main() { await testFitBounds( rotation: -60, cameraConstraint: CameraFit.bounds(bounds: bounds), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(6.2298786887073065, 26.943661553414902), const LatLng(-3.329896694206635, 36.517625059412374), ), @@ -205,7 +205,7 @@ void main() { await testFitBounds( rotation: 0, cameraConstraint: CameraFit.bounds(bounds: bounds), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(4.220875035073316, 28.95466920920177), const LatLng(-1.3562295282017047, 34.53572340816548), ), @@ -215,7 +215,7 @@ void main() { await testFitBounds( rotation: 60, cameraConstraint: CameraFit.bounds(bounds: bounds), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(6.229878688707217, 26.943661553415026), const LatLng(-3.3298966942067114, 36.517625059412495), ), @@ -225,7 +225,7 @@ void main() { await testFitBounds( rotation: 120, cameraConstraint: CameraFit.bounds(bounds: bounds), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(6.229878688707217, 26.943661553415026), const LatLng(-3.3298966942067114, 36.517625059412495), ), @@ -235,7 +235,7 @@ void main() { await testFitBounds( rotation: 180, cameraConstraint: CameraFit.bounds(bounds: bounds), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(4.220875035073316, 28.95466920920177), const LatLng(-1.3562295282017047, 34.53572340816548), ), @@ -245,7 +245,7 @@ void main() { await testFitBounds( rotation: 240, cameraConstraint: CameraFit.bounds(bounds: bounds), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(6.229878688706365, 26.94366155341602), const LatLng(-3.3298966942076276, 36.51762505941353), ), @@ -255,7 +255,7 @@ void main() { await testFitBounds( rotation: 300, cameraConstraint: CameraFit.bounds(bounds: bounds), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(6.229878688707217, 26.943661553415026), const LatLng(-3.3298966942067114, 36.517625059412495), ), @@ -265,7 +265,7 @@ void main() { await testFitBounds( rotation: 360, cameraConstraint: CameraFit.bounds(bounds: bounds), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(4.220875035073316, 28.95466920920177), const LatLng(-1.3562295282017047, 34.53572340816548), ), @@ -283,7 +283,7 @@ void main() { bounds: bounds, padding: symmetricPadding, ), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(4.604066851713044, 28.560190151047802), const LatLng(-1.732813138431261, 34.902297195324785), ), @@ -296,7 +296,7 @@ void main() { bounds: bounds, padding: symmetricPadding, ), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(6.862564855409817, 26.292484184306595), const LatLng(-3.997225315187129, 37.171988168394705), ), @@ -309,7 +309,7 @@ void main() { bounds: bounds, padding: symmetricPadding, ), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(6.862564855410326, 26.292484184305955), const LatLng(-3.9972253151865824, 37.17198816839402), ), @@ -322,7 +322,7 @@ void main() { bounds: bounds, padding: symmetricPadding, ), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(4.6040668517126235, 28.560190151048324), const LatLng(-1.7328131384316936, 34.9022971953253), ), @@ -335,7 +335,7 @@ void main() { bounds: bounds, padding: symmetricPadding, ), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(6.862564855410096, 26.292484184306193), const LatLng(-3.997225315186811, 37.17198816839431), ), @@ -348,7 +348,7 @@ void main() { bounds: bounds, padding: symmetricPadding, ), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(6.8625648554105165, 26.292484184305717), const LatLng(-3.9972253151863786, 37.17198816839379), ), @@ -361,7 +361,7 @@ void main() { bounds: bounds, padding: symmetricPadding, ), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(4.604066851712751, 28.560190151048204), const LatLng(-1.732813138431579, 34.90229719532515), ), @@ -374,7 +374,7 @@ void main() { bounds: bounds, padding: symmetricPadding, ), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(6.862564855410008, 26.292484184306353), const LatLng(-3.9972253151869386, 37.17198816839443), ), @@ -387,7 +387,7 @@ void main() { bounds: bounds, padding: symmetricPadding, ), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(6.8625648554105165, 26.292484184305717), const LatLng(-3.9972253151863786, 37.17198816839379), ), @@ -400,7 +400,7 @@ void main() { bounds: bounds, padding: symmetricPadding, ), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(4.6040668517126235, 28.560190151048324), const LatLng(-1.7328131384316936, 34.9022971953253), ), @@ -413,7 +413,7 @@ void main() { bounds: bounds, padding: symmetricPadding, ), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(6.862564855410008, 26.292484184306353), const LatLng(-3.9972253151869386, 37.17198816839443), ), @@ -426,7 +426,7 @@ void main() { bounds: bounds, padding: symmetricPadding, ), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(6.862564855411076, 26.292484184305035), const LatLng(-3.997225315185781, 37.171988168393064), ), @@ -439,7 +439,7 @@ void main() { bounds: bounds, padding: symmetricPadding, ), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(4.604066851711988, 28.56019015104908), const LatLng(-1.7328131384323806, 34.902297195326106), ), @@ -457,7 +457,7 @@ void main() { bounds: bounds, padding: asymmetricPadding, ), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(4.634132562246874, 28.54085445883965), const LatLng(-2.1664538621122844, 35.34701811611249), ), @@ -470,7 +470,7 @@ void main() { bounds: bounds, padding: asymmetricPadding, ), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(7.353914452121884, 26.258676859164435), const LatLng(-4.297341450189851, 37.9342421103809), ), @@ -483,7 +483,7 @@ void main() { bounds: bounds, padding: asymmetricPadding, ), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(7.6081448623143, 26.00226365003461), const LatLng(-4.041607090303907, 37.677828901251075), ), @@ -496,7 +496,7 @@ void main() { bounds: bounds, padding: asymmetricPadding, ), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(5.041046797566381, 28.132484639403017), const LatLng(-1.7583244079256093, 34.93864829667586), ), @@ -509,7 +509,7 @@ void main() { bounds: bounds, padding: asymmetricPadding, ), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(7.184346279929569, 25.53217276663045), const LatLng(-4.467783700569064, 37.207738017846864), ), @@ -522,7 +522,7 @@ void main() { bounds: bounds, padding: asymmetricPadding, ), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(6.929875826124592, 25.788585975760196), const LatLng(-4.723372343263628, 37.46415122697666), ), @@ -535,7 +535,7 @@ void main() { bounds: bounds, padding: asymmetricPadding, ), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(4.63413256224709, 28.540854458839405), const LatLng(-2.166453862112043, 35.347018116112245), ), @@ -548,7 +548,7 @@ void main() { bounds: bounds, padding: asymmetricPadding, ), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(7.353914452122737, 26.258676859163398), const LatLng(-4.297341450188935, 37.93424211037982), ), @@ -561,7 +561,7 @@ void main() { bounds: bounds, padding: asymmetricPadding, ), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(7.6081448623143, 26.00226365003461), const LatLng(-4.041607090303907, 37.677828901251075), ), @@ -574,7 +574,7 @@ void main() { bounds: bounds, padding: asymmetricPadding, ), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(5.041046797566381, 28.132484639403017), const LatLng(-1.7583244079256093, 34.93864829667586), ), @@ -587,7 +587,7 @@ void main() { bounds: bounds, padding: asymmetricPadding, ), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(7.184346279929569, 25.53217276663045), const LatLng(-4.467783700569064, 37.207738017846864), ), @@ -600,7 +600,7 @@ void main() { bounds: bounds, padding: asymmetricPadding, ), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(6.929875826125113, 25.788585975759595), const LatLng(-4.7233723432630805, 37.46415122697602), ), @@ -613,7 +613,7 @@ void main() { bounds: bounds, padding: asymmetricPadding, ), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(4.634132562246874, 28.54085445883965), const LatLng(-2.1664538621122844, 35.34701811611249), ), @@ -822,7 +822,7 @@ void main() { testWidgets('test fit inside bounds with rotation', (tester) async { final controller = MapController(); - final bounds = LatLngBounds.fromCorners( + final bounds = LatLngBounds( const LatLng(4.214943, 33.925781), const LatLng(-1.362176, 29.575195), ); @@ -874,7 +874,7 @@ void main() { cameraConstraint: CameraFit.insideBounds( bounds: bounds, ), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(3.6031134233301474, 29.56772762000039), const LatLng(-0.7450743699315154, 33.9183136200004), ), @@ -886,7 +886,7 @@ void main() { cameraConstraint: CameraFit.insideBounds( bounds: bounds, ), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(3.614278658020072, 29.56945889748712), const LatLng(-0.7338878844415404, 33.920044897487124), ), @@ -898,7 +898,7 @@ void main() { cameraConstraint: CameraFit.insideBounds( bounds: bounds, ), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(3.6142786580207207, 29.56945889748632), const LatLng(-0.7338878844408534, 33.92004489748633), ), @@ -910,7 +910,7 @@ void main() { cameraConstraint: CameraFit.insideBounds( bounds: bounds, ), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(3.6031134233301474, 29.56772762000039), const LatLng(-0.7450743699315154, 33.9183136200004), ), @@ -922,7 +922,7 @@ void main() { cameraConstraint: CameraFit.insideBounds( bounds: bounds, ), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(3.614278658020072, 29.56945889748712), const LatLng(-0.7338878844415404, 33.920044897487124), ), @@ -934,7 +934,7 @@ void main() { cameraConstraint: CameraFit.insideBounds( bounds: bounds, ), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(3.6142786580207207, 29.56945889748632), const LatLng(-0.7338878844408534, 33.92004489748633), ), @@ -946,7 +946,7 @@ void main() { cameraConstraint: CameraFit.insideBounds( bounds: bounds, ), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(3.6031134233301474, 29.56772762000039), const LatLng(-0.7450743699315154, 33.9183136200004), ), @@ -958,7 +958,7 @@ void main() { cameraConstraint: CameraFit.insideBounds( bounds: bounds, ), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(3.614278658020072, 29.56945889748712), const LatLng(-0.7338878844415404, 33.920044897487124), ), @@ -970,7 +970,7 @@ void main() { cameraConstraint: CameraFit.insideBounds( bounds: bounds, ), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(3.6142786580207207, 29.56945889748632), const LatLng(-0.7338878844408534, 33.92004489748633), ), @@ -982,7 +982,7 @@ void main() { cameraConstraint: CameraFit.insideBounds( bounds: bounds, ), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(3.6031134233301474, 29.56772762000039), const LatLng(-0.7450743699315154, 33.9183136200004), ), @@ -994,7 +994,7 @@ void main() { cameraConstraint: CameraFit.insideBounds( bounds: bounds, ), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(3.614278658020072, 29.56945889748712), const LatLng(-0.7338878844415404, 33.920044897487124), ), @@ -1006,7 +1006,7 @@ void main() { cameraConstraint: CameraFit.insideBounds( bounds: bounds, ), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(3.6142786580207207, 29.56945889748632), const LatLng(-0.7338878844408534, 33.92004489748633), ), @@ -1018,7 +1018,7 @@ void main() { cameraConstraint: CameraFit.insideBounds( bounds: bounds, ), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(3.6031134233301474, 29.56772762000039), const LatLng(-0.7450743699315154, 33.9183136200004), ), @@ -1036,7 +1036,7 @@ void main() { bounds: bounds, padding: equalPadding, ), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(3.8971355052392727, 29.273074295454837), const LatLng(-1.0436460563295582, 34.21692202272759), ), @@ -1049,7 +1049,7 @@ void main() { bounds: bounds, padding: equalPadding, ), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(3.900159833096254, 29.26631356795233), const LatLng(-1.0406152150025456, 34.21016129522507), ), @@ -1062,7 +1062,7 @@ void main() { bounds: bounds, padding: equalPadding, ), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(3.900159833095936, 29.266313567952732), const LatLng(-1.0406152150029018, 34.210161295225475), ), @@ -1075,7 +1075,7 @@ void main() { bounds: bounds, padding: equalPadding, ), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(3.897135505240036, 29.273074295453956), const LatLng(-1.0436460563287566, 34.21692202272667), ), @@ -1088,7 +1088,7 @@ void main() { bounds: bounds, padding: equalPadding, ), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(3.900159833096941, 29.26631356795153), const LatLng(-1.0406152150018586, 34.210161295224275), ), @@ -1101,7 +1101,7 @@ void main() { bounds: bounds, padding: equalPadding, ), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(3.9001598330968137, 29.266313567951688), const LatLng(-1.0406152150019858, 34.21016129522444), ), @@ -1114,7 +1114,7 @@ void main() { bounds: bounds, padding: equalPadding, ), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(3.921797222702341, 29.273074295454474), const LatLng(-1.0189308220167805, 34.21692202272719), ), @@ -1127,7 +1127,7 @@ void main() { bounds: bounds, padding: equalPadding, ), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(3.9001598330947402, 29.26631356795413), const LatLng(-1.0406152150040977, 34.21016129522692), ), @@ -1140,7 +1140,7 @@ void main() { bounds: bounds, padding: equalPadding, ), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(3.900159833097259, 29.26631356795117), const LatLng(-1.0406152150015406, 34.21016129522388), ), @@ -1153,7 +1153,7 @@ void main() { bounds: bounds, padding: equalPadding, ), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(3.897135505238624, 29.273074295455597), const LatLng(-1.0436460563302323, 34.21692202272835), ), @@ -1166,7 +1166,7 @@ void main() { bounds: bounds, padding: equalPadding, ), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(3.900159833097577, 29.266313567950775), const LatLng(-1.0406152150011843, 34.21016129522348), ), @@ -1179,7 +1179,7 @@ void main() { bounds: bounds, padding: equalPadding, ), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(3.900159833095936, 29.266313567952732), const LatLng(-1.0406152150029018, 34.210161295225475), ), @@ -1192,7 +1192,7 @@ void main() { bounds: bounds, padding: equalPadding, ), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(3.897135505240036, 29.273074295453956), const LatLng(-1.0436460563287566, 34.21692202272667), ), @@ -1210,7 +1210,7 @@ void main() { bounds: bounds, padding: asymmetricPadding, ), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(3.93081962068567, 29.252575414633416), const LatLng(-1.371554855609733, 34.558168097560255), ), @@ -1223,7 +1223,7 @@ void main() { bounds: bounds, padding: asymmetricPadding, ), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(4.12285573833763, 29.236827391148324), const LatLng(-1.179091165662991, 34.5424200740752), ), @@ -1236,7 +1236,7 @@ void main() { bounds: bounds, padding: asymmetricPadding, ), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(4.239064535667103, 29.12030848890263), const LatLng(-1.0625945779487183, 34.42590117182947), ), @@ -1249,7 +1249,7 @@ void main() { bounds: bounds, padding: asymmetricPadding, ), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(4.248344214607476, 28.934239853659207), const LatLng(-1.0532909733871119, 34.239832536586086), ), @@ -1262,7 +1262,7 @@ void main() { bounds: bounds, padding: asymmetricPadding, ), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(4.045373737414225, 28.926110318495112), const LatLng(-1.2567528788718025, 34.23170300142199), ), @@ -1275,7 +1275,7 @@ void main() { bounds: bounds, padding: asymmetricPadding, ), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(3.9291368844072636, 29.04262922073941), const LatLng(-1.373241074234739, 34.34822190366625), ), @@ -1288,7 +1288,7 @@ void main() { bounds: bounds, padding: asymmetricPadding, ), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(3.9308196206843724, 29.252575414634972), const LatLng(-1.3715548556110944, 34.55816809756181), ), @@ -1301,7 +1301,7 @@ void main() { bounds: bounds, padding: asymmetricPadding, ), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(4.122855738337325, 29.236827391148683), const LatLng(-1.179091165663309, 34.542420074075565), ), @@ -1314,7 +1314,7 @@ void main() { bounds: bounds, padding: asymmetricPadding, ), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(4.23906453566681, 29.12030848890299), const LatLng(-1.0625945779490364, 34.42590117182983), ), @@ -1327,7 +1327,7 @@ void main() { bounds: bounds, padding: asymmetricPadding, ), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(4.248344214608647, 28.934239853657804), const LatLng(-1.053290973385865, 34.23983253658464), ), @@ -1340,7 +1340,7 @@ void main() { bounds: bounds, padding: asymmetricPadding, ), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(4.045373737414429, 28.926110318494874), const LatLng(-1.2567528788715607, 34.23170300142176), ), @@ -1353,7 +1353,7 @@ void main() { bounds: bounds, padding: asymmetricPadding, ), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(3.9291368844075816, 29.04262922073901), const LatLng(-1.3732410742343828, 34.348221903665845), ), @@ -1366,7 +1366,7 @@ void main() { bounds: bounds, padding: asymmetricPadding, ), - expectedBounds: LatLngBounds.fromCorners( + expectedBounds: LatLngBounds( const LatLng(3.9308196206847033, 29.252575414634578), const LatLng(-1.3715548556107255, 34.55816809756141), ), From 4be43bb0f3b57869bc5c2e113e3aff6418ec22ae Mon Sep 17 00:00:00 2001 From: Joscha <34318751+josxha@users.noreply.github.com> Date: Tue, 12 Mar 2024 13:54:45 +0100 Subject: [PATCH 6/8] improve documentation --- lib/src/geo/latlng_bounds.dart | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/src/geo/latlng_bounds.dart b/lib/src/geo/latlng_bounds.dart index 102856021..793c83bdd 100644 --- a/lib/src/geo/latlng_bounds.dart +++ b/lib/src/geo/latlng_bounds.dart @@ -128,17 +128,29 @@ class LatLngBounds { west = max(-180, min(west, bounds.west)); } - /// Obtain coordinates of southwest corner of the bounds + /// Obtain coordinates of southwest corner of the bounds. + /// + /// Instead of using latitude or longitude of the corner, use [south] or + /// [west] instead! LatLng get southWest => LatLng(south, west); /// Obtain coordinates of northeast corner of the bounds + /// + /// Instead of using latitude or longitude of the corner, use [north] or + /// [east] instead! LatLng get northEast => LatLng(north, east); /// Obtain coordinates of northwest corner of the bounds + /// + /// Instead of using latitude or longitude of the corner, use [north] or + /// [west] instead! LatLng get northWest => LatLng(north, west); /// Obtain coordinates of southeast corner of the bounds - LatLng get southEast => LatLng(south, east); + /// + /// Instead of using latitude or longitude of the corner, use [south] or + /// [west] instead! + LatLng get southEast => LatLng(south, west); /// Obtain coordinates of the bounds center LatLng get center { From 95a43505d9d56e448d1fe5c6576aacd00e73b633 Mon Sep 17 00:00:00 2001 From: Joscha <34318751+josxha@users.noreply.github.com> Date: Tue, 12 Mar 2024 14:26:25 +0100 Subject: [PATCH 7/8] add `toString()` --- lib/src/geo/latlng_bounds.dart | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/src/geo/latlng_bounds.dart b/lib/src/geo/latlng_bounds.dart index 793c83bdd..80202f272 100644 --- a/lib/src/geo/latlng_bounds.dart +++ b/lib/src/geo/latlng_bounds.dart @@ -213,4 +213,8 @@ class LatLngBounds { other.south == south && other.east == east && other.west == west); + + @override + String toString() => + 'LatLngBounds(north: $north, south: $south, east: $east, west: $west)'; } From 2a0c4efba7a2eb570756a5a46e50acd0a05910a4 Mon Sep 17 00:00:00 2001 From: Joscha <34318751+josxha@users.noreply.github.com> Date: Tue, 12 Mar 2024 14:38:30 +0100 Subject: [PATCH 8/8] fix copy paste error --- lib/src/geo/latlng_bounds.dart | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/src/geo/latlng_bounds.dart b/lib/src/geo/latlng_bounds.dart index 80202f272..d227378a7 100644 --- a/lib/src/geo/latlng_bounds.dart +++ b/lib/src/geo/latlng_bounds.dart @@ -134,23 +134,23 @@ class LatLngBounds { /// [west] instead! LatLng get southWest => LatLng(south, west); - /// Obtain coordinates of northeast corner of the bounds + /// Obtain coordinates of northeast corner of the bounds. /// /// Instead of using latitude or longitude of the corner, use [north] or /// [east] instead! LatLng get northEast => LatLng(north, east); - /// Obtain coordinates of northwest corner of the bounds + /// Obtain coordinates of northwest corner of the bounds. /// /// Instead of using latitude or longitude of the corner, use [north] or /// [west] instead! LatLng get northWest => LatLng(north, west); - /// Obtain coordinates of southeast corner of the bounds + /// Obtain coordinates of southeast corner of the bounds. /// /// Instead of using latitude or longitude of the corner, use [south] or - /// [west] instead! - LatLng get southEast => LatLng(south, west); + /// [east] instead! + LatLng get southEast => LatLng(south, east); /// Obtain coordinates of the bounds center LatLng get center {