Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: polygon hit detection when map is rotated #1942

Merged
merged 3 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading