Skip to content

Commit

Permalink
more stuffffffffff
Browse files Browse the repository at this point in the history
  • Loading branch information
mootw committed Dec 3, 2024
1 parent 54127a9 commit 36d83a4
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 17 deletions.
10 changes: 4 additions & 6 deletions example/lib/pages/latlng_to_screen_point.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import 'dart:math';

import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import 'package:flutter_map/flutter_map.dart';
Expand All @@ -23,7 +21,7 @@ class _LatLngToScreenPointPageState extends State<LatLngToScreenPointPage> {
final mapController = MapController();

LatLng? tappedCoords;
Point<double>? tappedPoint;
Offset? tappedPoint;

@override
void initState() {
Expand Down Expand Up @@ -53,7 +51,7 @@ class _LatLngToScreenPointPageState extends State<LatLngToScreenPointPage> {
onTap: (_, latLng) {
final point = mapController.camera
.latLngToScreenOffset(tappedCoords = latLng);
setState(() => tappedPoint = Point(point.dx, point.dy));
setState(() => tappedPoint = Offset(point.dx, point.dy));
},
),
children: [
Expand All @@ -77,8 +75,8 @@ class _LatLngToScreenPointPageState extends State<LatLngToScreenPointPage> {
),
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,
Expand Down
6 changes: 3 additions & 3 deletions lib/src/layer/tile_layer/tile_layer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -759,8 +759,8 @@ class _TileLayerState extends State<TileLayer> with TickerProviderStateMixin {
}

// TODO replace with simple implementation of (Offset - Offset).distanceSq
double _distanceSq(TileCoordinates coord, Point<double> 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;
}
3 changes: 2 additions & 1 deletion lib/src/layer/tile_layer/tile_range.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -151,7 +152,7 @@ class DiscreteTileRange extends TileRange {
Point<int> get max => _bounds.max;

/// The center [Point] of the [DiscreteTileRange]
Point<double> get center => _bounds.center;
Offset get center => _bounds.center;

/// Get a list of [TileCoordinates] for the [DiscreteTileRange].
@override
Expand Down
2 changes: 1 addition & 1 deletion lib/src/map/camera/camera_fit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 2 additions & 4 deletions lib/src/misc/bounds.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -68,10 +69,7 @@ class Bounds<T extends num> {
}

/// This [Bounds] central point.
Point<double> get center => Point<double>(
(min.x + max.x) / 2,
(min.y + max.y) / 2,
);
Offset get center => (min.toOffset() + max.toOffset()) / 2;

/// Bottom-Left corner's point.
Point<T> get bottomLeft => Point(min.x, max.y);
Expand Down
4 changes: 2 additions & 2 deletions test/core/bounds_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ void main() {
expect(
Bounds(Point(5.5, randomDouble()), Point(3.3, randomDouble()))
.center
.x,
.dx,
equals(4.4));
});

test('should get center of bounds as a point with y position', () {
expect(
Bounds(Point(randomDouble(), 3.2), Point(randomDouble(), 6.6))
.center
.y,
.dy,
equals(4.9));
});

Expand Down

0 comments on commit 36d83a4

Please sign in to comment.