From 36d83a4d13c895bde8637e7d1ee30beed3af9cf5 Mon Sep 17 00:00:00 2001 From: mootw Date: Mon, 2 Dec 2024 20:31:28 -0600 Subject: [PATCH] more stuffffffffff --- example/lib/pages/latlng_to_screen_point.dart | 10 ++++------ lib/src/layer/tile_layer/tile_layer.dart | 6 +++--- lib/src/layer/tile_layer/tile_range.dart | 3 ++- lib/src/map/camera/camera_fit.dart | 2 +- lib/src/misc/bounds.dart | 6 ++---- test/core/bounds_test.dart | 4 ++-- 6 files changed, 14 insertions(+), 17 deletions(-) diff --git a/example/lib/pages/latlng_to_screen_point.dart b/example/lib/pages/latlng_to_screen_point.dart index 08c03ac7d..8f69d9a1c 100644 --- a/example/lib/pages/latlng_to_screen_point.dart +++ b/example/lib/pages/latlng_to_screen_point.dart @@ -1,5 +1,3 @@ -import 'dart:math'; - import 'package:flutter/material.dart'; import 'package:flutter/scheduler.dart'; import 'package:flutter_map/flutter_map.dart'; @@ -23,7 +21,7 @@ class _LatLngToScreenPointPageState extends State { final mapController = MapController(); LatLng? tappedCoords; - Point? tappedPoint; + Offset? tappedPoint; @override void initState() { @@ -53,7 +51,7 @@ class _LatLngToScreenPointPageState extends State { onTap: (_, latLng) { final point = mapController.camera .latLngToScreenOffset(tappedCoords = latLng); - setState(() => tappedPoint = Point(point.dx, point.dy)); + setState(() => tappedPoint = Offset(point.dx, point.dy)); }, ), children: [ @@ -77,8 +75,8 @@ class _LatLngToScreenPointPageState extends State { ), if (tappedPoint != null) Positioned( - left: tappedPoint!.x - 60 / 2, - top: tappedPoint!.y - 60 / 2, + left: tappedPoint!.dx - 60 / 2, + top: tappedPoint!.dy - 60 / 2, child: const IgnorePointer( child: Icon( Icons.center_focus_strong_outlined, diff --git a/lib/src/layer/tile_layer/tile_layer.dart b/lib/src/layer/tile_layer/tile_layer.dart index c516673c6..43629e3a5 100644 --- a/lib/src/layer/tile_layer/tile_layer.dart +++ b/lib/src/layer/tile_layer/tile_layer.dart @@ -759,8 +759,8 @@ class _TileLayerState extends State with TickerProviderStateMixin { } // TODO replace with simple implementation of (Offset - Offset).distanceSq -double _distanceSq(TileCoordinates coord, Point center) { - final dx = center.x - coord.x; - final dy = center.y - coord.y; +double _distanceSq(TileCoordinates coord, Offset center) { + final dx = center.dx - coord.x; + final dy = center.dy - coord.y; return dx * dx + dy * dy; } diff --git a/lib/src/layer/tile_layer/tile_range.dart b/lib/src/layer/tile_layer/tile_range.dart index 088f3450b..4b235932c 100644 --- a/lib/src/layer/tile_layer/tile_range.dart +++ b/lib/src/layer/tile_layer/tile_range.dart @@ -1,5 +1,6 @@ import 'dart:math' as math hide Point; import 'dart:math' show Point; +import 'dart:ui'; import 'package:flutter_map/flutter_map.dart'; import 'package:meta/meta.dart'; @@ -151,7 +152,7 @@ class DiscreteTileRange extends TileRange { Point get max => _bounds.max; /// The center [Point] of the [DiscreteTileRange] - Point get center => _bounds.center; + Offset get center => _bounds.center; /// Get a list of [TileCoordinates] for the [DiscreteTileRange]. @override diff --git a/lib/src/map/camera/camera_fit.dart b/lib/src/map/camera/camera_fit.dart index fe3d1ec2f..8765c4a81 100644 --- a/lib/src/map/camera/camera_fit.dart +++ b/lib/src/map/camera/camera_fit.dart @@ -442,7 +442,7 @@ class FitCoordinates extends CameraFit { // Apply padding final paddingOffset = (paddingBR - paddingTL) / 2; - final rotatedNewCenter = rotatedBounds.center.toOffset() + paddingOffset; + final rotatedNewCenter = rotatedBounds.center + paddingOffset; // Undo the rotation final unrotatedNewCenter = rotatedNewCenter.rotate(camera.rotationRad); diff --git a/lib/src/misc/bounds.dart b/lib/src/misc/bounds.dart index fa60aac79..f4d4551e4 100644 --- a/lib/src/misc/bounds.dart +++ b/lib/src/misc/bounds.dart @@ -2,6 +2,7 @@ import 'dart:math' as math hide Point; import 'dart:math' show Point; import 'dart:ui'; +import 'package:flutter_map/flutter_map.dart'; import 'package:meta/meta.dart'; /// Rectangular bound delimited by orthogonal lines passing through two @@ -68,10 +69,7 @@ class Bounds { } /// This [Bounds] central point. - Point get center => Point( - (min.x + max.x) / 2, - (min.y + max.y) / 2, - ); + Offset get center => (min.toOffset() + max.toOffset()) / 2; /// Bottom-Left corner's point. Point get bottomLeft => Point(min.x, max.y); diff --git a/test/core/bounds_test.dart b/test/core/bounds_test.dart index 51bcd34ba..b6539f10e 100644 --- a/test/core/bounds_test.dart +++ b/test/core/bounds_test.dart @@ -47,7 +47,7 @@ void main() { expect( Bounds(Point(5.5, randomDouble()), Point(3.3, randomDouble())) .center - .x, + .dx, equals(4.4)); }); @@ -55,7 +55,7 @@ void main() { expect( Bounds(Point(randomDouble(), 3.2), Point(randomDouble(), 6.6)) .center - .y, + .dy, equals(4.9)); });