Skip to content

Commit

Permalink
fix: polygon hit detection when map is rotated (#1942)
Browse files Browse the repository at this point in the history
  • Loading branch information
monsieurtanuki committed Aug 6, 2024
1 parent 74110db commit a2aada4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
10 changes: 6 additions & 4 deletions lib/src/layer/polygon_layer/painter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,12 @@ base class _PolygonPainter<R extends Object>
required math.Point<double> point,
required LatLng coordinate,
}) {
final polygon = projectedPolygon.polygon;
if (!polygon.boundingBox.contains(coordinate)) {
return false;
}
// TODO: We should check the bounding box here, for efficiency
// However, we need to account for map rotation
//
// if (!polygon.boundingBox.contains(touch)) {
// continue;
// }

final projectedCoords = getOffsetsXY(
camera: camera,
Expand Down
8 changes: 5 additions & 3 deletions lib/src/layer/polyline_layer/painter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ base class _PolylinePainter<R extends Object>
}) {
final polyline = projectedPolyline.polyline;

// TODO: For efficiency we'd ideally filter by bounding box here. However
// we'd need to compute an extended bounding box that accounts account for
// the `borderStrokeWidth` & the `minimumHitbox`
// TODO: We should check the bounding box here, for efficiency
// However, we need to account for:
// * map rotation
// * extended bbox that accounts for `minimumHitbox`
//
// if (!polyline.boundingBox.contains(touch)) {
// continue;
// }
Expand Down
2 changes: 1 addition & 1 deletion lib/src/layer/tile_layer/tile_layer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ class _TileLayerState extends State<TileLayer> with TickerProviderStateMixin {

late final _resetSub = widget.reset?.listen((_) {
_tileImageManager.removeAll(widget.evictErrorTileStrategy);
_loadAndPruneInVisibleBounds(MapCamera.of(context));
if (mounted) _loadAndPruneInVisibleBounds(MapCamera.of(context));
});

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

0 comments on commit a2aada4

Please sign in to comment.