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

Proposed fix for unsymmetrical anchored markers disappearing #1291

Merged
merged 11 commits into from
Jul 7, 2022
20 changes: 14 additions & 6 deletions lib/src/layer/marker_layer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,18 @@ class _MarkerLayerState extends State<MarkerLayer> {
_pxCache[i] = pxPoint;
}

final width = marker.width - marker.anchor.left;
final height = marker.height - marker.anchor.top;
final sw = CustomPoint(pxPoint.x + width, pxPoint.y - height);
final ne = CustomPoint(pxPoint.x - width, pxPoint.y + height);
// See if any portion of the Marker rect resides in the map bounds
// If not, don't spend any resources on build function.
// This calculation works for any Anchor position whithin the Marker
final leftPortion = marker.width - marker.anchor.left;
final rightPortion = marker.anchor.left;
final topPortion = marker.height - marker.anchor.top;
final bottomPortion = marker.anchor.top;

final sw =
CustomPoint(pxPoint.x + rightPortion, pxPoint.y - topPortion);
final ne =
CustomPoint(pxPoint.x - leftPortion, pxPoint.y + bottomPortion);

if (!map.pixelBounds.containsPartialBounds(Bounds(sw, ne))) {
continue;
Expand All @@ -287,8 +295,8 @@ class _MarkerLayerState extends State<MarkerLayer> {
key: marker.key,
width: marker.width,
height: marker.height,
left: pos.x - width,
top: pos.y - height,
left: pos.x - leftPortion,
top: pos.y - topPortion,
child: markerWidget,
),
);
Expand Down