Skip to content

Commit a2aada4

Browse files
fix: polygon hit detection when map is rotated (fleaflet#1942)
1 parent 74110db commit a2aada4

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

lib/src/layer/polygon_layer/painter.dart

+6-4
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,12 @@ base class _PolygonPainter<R extends Object>
5252
required math.Point<double> point,
5353
required LatLng coordinate,
5454
}) {
55-
final polygon = projectedPolygon.polygon;
56-
if (!polygon.boundingBox.contains(coordinate)) {
57-
return false;
58-
}
55+
// TODO: We should check the bounding box here, for efficiency
56+
// However, we need to account for map rotation
57+
//
58+
// if (!polygon.boundingBox.contains(touch)) {
59+
// continue;
60+
// }
5961

6062
final projectedCoords = getOffsetsXY(
6163
camera: camera,

lib/src/layer/polyline_layer/painter.dart

+5-3
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@ base class _PolylinePainter<R extends Object>
2525
}) {
2626
final polyline = projectedPolyline.polyline;
2727

28-
// TODO: For efficiency we'd ideally filter by bounding box here. However
29-
// we'd need to compute an extended bounding box that accounts account for
30-
// the `borderStrokeWidth` & the `minimumHitbox`
28+
// TODO: We should check the bounding box here, for efficiency
29+
// However, we need to account for:
30+
// * map rotation
31+
// * extended bbox that accounts for `minimumHitbox`
32+
//
3133
// if (!polyline.boundingBox.contains(touch)) {
3234
// continue;
3335
// }

lib/src/layer/tile_layer/tile_layer.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ class _TileLayerState extends State<TileLayer> with TickerProviderStateMixin {
347347

348348
late final _resetSub = widget.reset?.listen((_) {
349349
_tileImageManager.removeAll(widget.evictErrorTileStrategy);
350-
_loadAndPruneInVisibleBounds(MapCamera.of(context));
350+
if (mounted) _loadAndPruneInVisibleBounds(MapCamera.of(context));
351351
});
352352

353353
// This is called on every map movement so we should avoid expensive logic

0 commit comments

Comments
 (0)