From 85ad5ed035313f8c19083885e6d2bd916460b251 Mon Sep 17 00:00:00 2001 From: aytunc Date: Wed, 29 Jun 2022 00:48:43 +0300 Subject: [PATCH 01/11] Proposed fix for unsymmetrical anchored markers disappearing --- lib/src/layer/marker_layer.dart | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/src/layer/marker_layer.dart b/lib/src/layer/marker_layer.dart index 033c2ff04..74362cafa 100644 --- a/lib/src/layer/marker_layer.dart +++ b/lib/src/layer/marker_layer.dart @@ -261,10 +261,18 @@ class _MarkerLayerState extends State { _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 resides in the map bounds + // If not, don't spend resources on build function. + // This calculation does not assume where the Anchor is or + // if it is symmetrical or not + final leftPortion = marker.width - marker.anchor.left; + final rigthPortion = marker.anchor.left; + final topPortion = marker.height - marker.anchor.top; + final bottomPortion = marker.anchor.top; + + var sw = CustomPoint(pxPoint.x + leftPortion, pxPoint.y - topPortion); + var ne = + CustomPoint(pxPoint.x - rigthPortion, pxPoint.y + bottomPortion); if (!map.pixelBounds.containsPartialBounds(Bounds(sw, ne))) { continue; From aa0493266ff09c63ea73898663398863d3adc489 Mon Sep 17 00:00:00 2001 From: aytunc Date: Wed, 29 Jun 2022 01:07:33 +0300 Subject: [PATCH 02/11] changed width&height to the new values in Positioned --- lib/src/layer/marker_layer.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/layer/marker_layer.dart b/lib/src/layer/marker_layer.dart index 74362cafa..1c8a216fe 100644 --- a/lib/src/layer/marker_layer.dart +++ b/lib/src/layer/marker_layer.dart @@ -295,8 +295,8 @@ class _MarkerLayerState extends State { 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, ), ); From a7611ee7b8ceb701bb54f7bd0e1a043a110bfd1b Mon Sep 17 00:00:00 2001 From: aytunc Date: Wed, 29 Jun 2022 01:32:20 +0300 Subject: [PATCH 03/11] added prints --- lib/src/layer/marker_layer.dart | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/src/layer/marker_layer.dart b/lib/src/layer/marker_layer.dart index 1c8a216fe..8b3d54ed4 100644 --- a/lib/src/layer/marker_layer.dart +++ b/lib/src/layer/marker_layer.dart @@ -275,6 +275,8 @@ class _MarkerLayerState extends State { CustomPoint(pxPoint.x - rigthPortion, pxPoint.y + bottomPortion); if (!map.pixelBounds.containsPartialBounds(Bounds(sw, ne))) { + print("map.pixelBounds: " + map.pixelBounds); + print("Bounds(sw, ne): " + Bounds(sw, ne)); continue; } From 24299edf5535d0a9345ead0ee1cd955b4b67a2d1 Mon Sep 17 00:00:00 2001 From: aytunc Date: Wed, 29 Jun 2022 01:40:18 +0300 Subject: [PATCH 04/11] Update marker_layer.dart --- lib/src/layer/marker_layer.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/layer/marker_layer.dart b/lib/src/layer/marker_layer.dart index 8b3d54ed4..271f514b9 100644 --- a/lib/src/layer/marker_layer.dart +++ b/lib/src/layer/marker_layer.dart @@ -275,8 +275,8 @@ class _MarkerLayerState extends State { CustomPoint(pxPoint.x - rigthPortion, pxPoint.y + bottomPortion); if (!map.pixelBounds.containsPartialBounds(Bounds(sw, ne))) { - print("map.pixelBounds: " + map.pixelBounds); - print("Bounds(sw, ne): " + Bounds(sw, ne)); + print("map.pixelBounds: " + map.pixelBounds.toString()); + print("Bounds(sw, ne): " + Bounds(sw, ne).toString()); continue; } From 64ce554e790b8f60ea13012f818c1302a1f37edb Mon Sep 17 00:00:00 2001 From: aytunc Date: Wed, 29 Jun 2022 01:55:45 +0300 Subject: [PATCH 05/11] Update marker_layer.dart --- lib/src/layer/marker_layer.dart | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/src/layer/marker_layer.dart b/lib/src/layer/marker_layer.dart index 271f514b9..d118fb965 100644 --- a/lib/src/layer/marker_layer.dart +++ b/lib/src/layer/marker_layer.dart @@ -275,6 +275,11 @@ class _MarkerLayerState extends State { CustomPoint(pxPoint.x - rigthPortion, pxPoint.y + bottomPortion); if (!map.pixelBounds.containsPartialBounds(Bounds(sw, ne))) { + print("pxPoint: " + pxPoint.toString()); + print("leftPortion: " + leftPortion.toString()); + print("rigthPortion: " + rigthPortion.toString()); + print("topPortion: " + topPortion.toString()); + print("bottomPortion: " + bottomPortion.toString()); print("map.pixelBounds: " + map.pixelBounds.toString()); print("Bounds(sw, ne): " + Bounds(sw, ne).toString()); continue; From 26a4551c1f0fb712edfdaf40cba7e0bb0bc1baf4 Mon Sep 17 00:00:00 2001 From: aytunc Date: Wed, 29 Jun 2022 02:53:50 +0300 Subject: [PATCH 06/11] Update marker_layer.dart --- lib/src/layer/marker_layer.dart | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/src/layer/marker_layer.dart b/lib/src/layer/marker_layer.dart index d118fb965..33a8ef106 100644 --- a/lib/src/layer/marker_layer.dart +++ b/lib/src/layer/marker_layer.dart @@ -270,9 +270,10 @@ class _MarkerLayerState extends State { final topPortion = marker.height - marker.anchor.top; final bottomPortion = marker.anchor.top; - var sw = CustomPoint(pxPoint.x + leftPortion, pxPoint.y - topPortion); + var sw = + CustomPoint(pxPoint.x + rigthPortion, pxPoint.y - topPortion); var ne = - CustomPoint(pxPoint.x - rigthPortion, pxPoint.y + bottomPortion); + CustomPoint(pxPoint.x - leftPortion, pxPoint.y + bottomPortion); if (!map.pixelBounds.containsPartialBounds(Bounds(sw, ne))) { print("pxPoint: " + pxPoint.toString()); From 7c848c39c297966a31dd435f76727a08a60cc9ed Mon Sep 17 00:00:00 2001 From: aytunc Date: Wed, 29 Jun 2022 03:17:14 +0300 Subject: [PATCH 07/11] fixed calculations after debug and tested --- lib/src/layer/marker_layer.dart | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/lib/src/layer/marker_layer.dart b/lib/src/layer/marker_layer.dart index 33a8ef106..d4de2f699 100644 --- a/lib/src/layer/marker_layer.dart +++ b/lib/src/layer/marker_layer.dart @@ -261,10 +261,9 @@ class _MarkerLayerState extends State { _pxCache[i] = pxPoint; } - // See if any portion of the Marker resides in the map bounds - // If not, don't spend resources on build function. - // This calculation does not assume where the Anchor is or - // if it is symmetrical or not + // 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 any Anchor position whithin the Marker final leftPortion = marker.width - marker.anchor.left; final rigthPortion = marker.anchor.left; final topPortion = marker.height - marker.anchor.top; @@ -276,13 +275,6 @@ class _MarkerLayerState extends State { CustomPoint(pxPoint.x - leftPortion, pxPoint.y + bottomPortion); if (!map.pixelBounds.containsPartialBounds(Bounds(sw, ne))) { - print("pxPoint: " + pxPoint.toString()); - print("leftPortion: " + leftPortion.toString()); - print("rigthPortion: " + rigthPortion.toString()); - print("topPortion: " + topPortion.toString()); - print("bottomPortion: " + bottomPortion.toString()); - print("map.pixelBounds: " + map.pixelBounds.toString()); - print("Bounds(sw, ne): " + Bounds(sw, ne).toString()); continue; } From 90c91bef63a41ffbbc6d162c804cd938a7df9b22 Mon Sep 17 00:00:00 2001 From: aytunc Date: Wed, 29 Jun 2022 12:47:51 +0300 Subject: [PATCH 08/11] changed var to final --- lib/src/layer/marker_layer.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/layer/marker_layer.dart b/lib/src/layer/marker_layer.dart index d4de2f699..89e764cd4 100644 --- a/lib/src/layer/marker_layer.dart +++ b/lib/src/layer/marker_layer.dart @@ -269,9 +269,9 @@ class _MarkerLayerState extends State { final topPortion = marker.height - marker.anchor.top; final bottomPortion = marker.anchor.top; - var sw = + final sw = CustomPoint(pxPoint.x + rigthPortion, pxPoint.y - topPortion); - var ne = + final ne = CustomPoint(pxPoint.x - leftPortion, pxPoint.y + bottomPortion); if (!map.pixelBounds.containsPartialBounds(Bounds(sw, ne))) { From 9967901127488553494635bd7516f7855840c05c Mon Sep 17 00:00:00 2001 From: aytunc Date: Wed, 29 Jun 2022 13:08:15 +0300 Subject: [PATCH 09/11] fixed typos --- lib/src/layer/marker_layer.dart | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/src/layer/marker_layer.dart b/lib/src/layer/marker_layer.dart index 89e764cd4..94f2dba8b 100644 --- a/lib/src/layer/marker_layer.dart +++ b/lib/src/layer/marker_layer.dart @@ -263,14 +263,14 @@ class _MarkerLayerState extends State { // 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 any Anchor position whithin the Marker + // This calculation works for any Anchor position whithin the Marker final leftPortion = marker.width - marker.anchor.left; - final rigthPortion = 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 + rigthPortion, pxPoint.y - topPortion); + CustomPoint(pxPoint.x + rightPortion, pxPoint.y - topPortion); final ne = CustomPoint(pxPoint.x - leftPortion, pxPoint.y + bottomPortion); From 52b23529feed2cecc4cbb76834bd0af3949de2cd Mon Sep 17 00:00:00 2001 From: aytunc Date: Wed, 29 Jun 2022 17:31:26 +0300 Subject: [PATCH 10/11] changed naming convention for sw and ne to make more sense --- lib/src/layer/marker_layer.dart | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/src/layer/marker_layer.dart b/lib/src/layer/marker_layer.dart index 94f2dba8b..33a2bd4c8 100644 --- a/lib/src/layer/marker_layer.dart +++ b/lib/src/layer/marker_layer.dart @@ -264,15 +264,15 @@ class _MarkerLayerState extends State { // 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 rightPortion = marker.width - marker.anchor.left; + final leftPortion = marker.anchor.left; + final bottomPortion = marker.height - marker.anchor.top; + final topPortion = marker.anchor.top; final sw = - CustomPoint(pxPoint.x + rightPortion, pxPoint.y - topPortion); + CustomPoint(pxPoint.x + leftPortion, pxPoint.y - bottomPortion); final ne = - CustomPoint(pxPoint.x - leftPortion, pxPoint.y + bottomPortion); + CustomPoint(pxPoint.x - rightPortion, pxPoint.y + topPortion); if (!map.pixelBounds.containsPartialBounds(Bounds(sw, ne))) { continue; @@ -295,8 +295,8 @@ class _MarkerLayerState extends State { key: marker.key, width: marker.width, height: marker.height, - left: pos.x - leftPortion, - top: pos.y - topPortion, + left: pos.x - rightPortion, + top: pos.y - bottomPortion, child: markerWidget, ), ); From 4bbf1cbdd29f201994e3606db7b370033f4db741 Mon Sep 17 00:00:00 2001 From: aytunc Date: Wed, 29 Jun 2022 18:24:38 +0300 Subject: [PATCH 11/11] added comment for the coordinate system confusion of Anchors --- lib/src/layer/marker_layer.dart | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/src/layer/marker_layer.dart b/lib/src/layer/marker_layer.dart index 33a2bd4c8..1a258c2e8 100644 --- a/lib/src/layer/marker_layer.dart +++ b/lib/src/layer/marker_layer.dart @@ -264,6 +264,8 @@ class _MarkerLayerState extends State { // 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 + // Note that Anchor coordinates of (0,0) are at bottom-right of the Marker + // unlike the map coordinates. final rightPortion = marker.width - marker.anchor.left; final leftPortion = marker.anchor.left; final bottomPortion = marker.height - marker.anchor.top;