'agm-snazzy-window handle map edge scenarios

I have an application where I am using agm-map and agm-snazzy-window to show custom pins on the map. I have created offset for the snazzy-window based on the solution provided here: Setting info-window offset for agm snazzy-info-window

I have currently set the panOnOpen property to false for the infobox. The issue/scenario I am trying to handle is to somehow dynamically move the window in the visible map area if the infobox is going to bleed over the visible map area. Meaning if the marker is close to the top edge of map then it to dynamically open at the bottom of the marker. If marker is close to the left edge then it needs to open the popup to the right side of the visible map area. So on...

Is there a good way to achieve this with snazzy-window. I have previously used bing maps where i convert the location to pixels and consider the width and height of map and infobox to sort of move the offset around but I am not able to convert that logic into something that works with agm-map/agm-snazzy-window.

Any help is appreciated.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source