Skip to content

Commit

Permalink
fix some nits
Browse files Browse the repository at this point in the history
  • Loading branch information
mootw committed Dec 5, 2024
1 parent 72f2fd2 commit 8603d71
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion example/lib/pages/screen_point_to_latlng.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class PointToLatlngPage extends State<ScreenPointToLatLngPage> {
}

void updatePoint(BuildContext context) => setState(() => latLng =
mapController.camera.offsetToLatLng(Offset(_getPointX(context), pointY)));
mapController.camera.screenOffsetToLatLng(Offset(_getPointX(context), pointY)));

double _getPointX(BuildContext context) =>
MediaQuery.sizeOf(context).width / 2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ abstract base class HitDetectablePainter<R extends Object,
/// [HitDetectableElement.hitValue] is `null` on this element.
///
/// [Offset] and [coordinate]
/// ([MapCamera.offsetToLatLng]) are provided for simplicity.
/// ([MapCamera.screenOffsetToLatLng]) are provided for simplicity.
///
/// Avoid performing calculations that are not dependent on [element]. Instead,
/// override [hitTest], store the necessary calculation results in
Expand All @@ -65,7 +65,7 @@ abstract base class HitDetectablePainter<R extends Object,
bool hasHit = false;

final point = position;
final coordinate = camera.offsetToLatLng(point);
final coordinate = camera.screenOffsetToLatLng(point);

for (int i = elements.length - 1; i >= 0; i--) {
final element = elements.elementAt(i);
Expand Down Expand Up @@ -96,7 +96,7 @@ base mixin HitTestRequiresCameraOrigin<R extends Object,
/// Calculated [MapCamera] origin, using the following formula:
///
/// ```dart
/// camera.project(camera.center) - camera.size / 2
/// camera.project(camera.center) - camera.size.center(Offset.zero)
/// ```
///
/// Only initialised after [hitTest] is invoked. Recalculated every time
Expand Down
10 changes: 4 additions & 6 deletions lib/src/map/camera/camera.dart
Original file line number Diff line number Diff line change
Expand Up @@ -296,12 +296,10 @@ class MapCamera {
return point - nonRotatedPixelOrigin;
}

/// Calculate the [LatLng] coordinates for a [localPoint].
LatLng offsetToLatLng(Offset localPoint) {
final localPointCenterDistance = Offset(
(nonRotatedSize.width / 2) - localPoint.dx,
(nonRotatedSize.height / 2) - localPoint.dy,
);
/// Calculate the [LatLng] coordinates for a [offset].
LatLng screenOffsetToLatLng(Offset offset) {
final localPointCenterDistance =
nonRotatedSize.center(Offset.zero) - offset;
final mapCenter = crs.latLngToOffset(center, zoom);

var point = mapCenter - localPointCenterDistance;
Expand Down

0 comments on commit 8603d71

Please sign in to comment.