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

Ensure that map info windows are always visible #357

Merged
merged 1 commit into from
Apr 15, 2024

Conversation

dgmstuart
Copy link
Owner

Google maps handles info windows near the edge of the page by scrolling
just enough that the whole info window is in view.

But it doesn't know about the map menu we have overlaying the left side
of the screen, so we need to do this manually:

  1. get the coordinates from the click event - latLng is a property of
    the click event:

    https://developers.google.com/maps/documentation/javascript/reference/advanced-markers#AdvancedMarkerElement-Events
    https://developers.google.com/maps/documentation/javascript/reference/map#MapMouseEvent

  2. Wait for the info window to become visible:

    https://developers.google.com/maps/documentation/javascript/reference/info-window#InfoWindow.visible

  3. Now that it's visible we can get it's width, add half of that to
    the offset, and pan so that the marker is within the resulting
    padding.

Google maps handles info windows near the edge of the page by scrolling
just enough that the whole info window is in view.

But it doesn't know about the map menu we have overlaying the left side
of the screen, so we need to do this manually:

  1. get the coordinates from the click event - latLng is a property of
     the click event:

       https://developers.google.com/maps/documentation/javascript/reference/advanced-markers#AdvancedMarkerElement-Events
       https://developers.google.com/maps/documentation/javascript/reference/map#MapMouseEvent

  2. Wait for the info window to become visible:

       https://developers.google.com/maps/documentation/javascript/reference/info-window#InfoWindow.visible

  3. Now that it's visible we can get it's width, add half of that to
     the offset, and pan so that the marker is within the resulting
     padding.
@dgmstuart dgmstuart merged commit 54a6352 into main Apr 15, 2024
1 check passed
@dgmstuart dgmstuart deleted the dgms/fix/mapinfowindows branch April 15, 2024 02:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant