11import 'package:flutter/widgets.dart' ;
22import 'package:flutter_map/flutter_map.dart' ;
3- import 'package:flutter_map/src/layer/shared/feature_layer_utils.dart' ;
43import 'package:latlong2/latlong.dart' ;
54import 'package:meta/meta.dart' ;
65
@@ -42,8 +41,7 @@ mixin HitDetectablePainter<R extends Object, E extends HitDetectableElement<R>>
4241 /// Avoid performing calculations that are not dependent on [element] . Instead,
4342 /// override [hitTest] , store the necessary calculation results in
4443 /// (`late` non-`null` able) members, and call `super.hitTest(position)` at the
45- /// end. To calculate the camera origin in this way, instead mix in and use
46- /// [FeatureLayerUtils.origin] .
44+ /// end. The camera origin may be retrieved with [MapCamera.pixelOrigin] .
4745 ///
4846 /// Should return whether an element has been hit.
4947 bool elementHitTest (
@@ -60,13 +58,12 @@ mixin HitDetectablePainter<R extends Object, E extends HitDetectableElement<R>>
6058 _hits.clear ();
6159 bool hasHit = false ;
6260
63- final point = position;
64- final coordinate = camera.screenOffsetToLatLng (point);
61+ final coordinate = camera.unprojectAtZoom (camera.pixelOrigin + position);
6562
6663 for (int i = elements.length - 1 ; i >= 0 ; i-- ) {
6764 final element = elements.elementAt (i);
6865 if (hasHit && element.hitValue == null ) continue ;
69- if (elementHitTest (element, point: point , coordinate: coordinate)) {
66+ if (elementHitTest (element, point: position , coordinate: coordinate)) {
7067 if (element.hitValue != null ) _hits.add (element.hitValue! );
7168 hasHit = true ;
7269 }
@@ -80,7 +77,7 @@ mixin HitDetectablePainter<R extends Object, E extends HitDetectableElement<R>>
8077 hitNotifier? .value = LayerHitResult (
8178 hitValues: _hits,
8279 coordinate: coordinate,
83- point: point ,
80+ point: position ,
8481 );
8582 return true ;
8683 }
0 commit comments