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

"Unable to find marker" when loading map via Sprig #52

Closed
drifteaur opened this issue Apr 14, 2022 · 9 comments
Closed

"Unable to find marker" when loading map via Sprig #52

drifteaur opened this issue Apr 14, 2022 · 9 comments
Labels
Bug Report Something isn't working

Comments

@drifteaur
Copy link

I followed the guide to set up a dynamic map using Sprig:

https://plugins.doublesecretagency.com/google-maps/guides/sprig/

The map loads fine on the initial page load, and the info windows show when clicking the markers. When the map is refreshed via sprig (in this case, the map is paginated, and going to the next page loads the next set of locations) - the map shows, but the info windows won't open.

On initial load:

initial

On sprig request:

sprig

I assume googleMaps._listInfoWindows is not being refreshed on a Sprig request somehow. Any way to fix this?

@drifteaur
Copy link
Author

My Twig code, if it's relevant:

{% set mapId = 'properties-map' %}
 {% set mapOptions = {
     'id': mapId,
     'infoWindowTemplate': '_sprig-components/property-filter/_map_bubble',
     'cluster': true,
     'mapOptions': {
         'maxZoom': 17,
     },
     'markerOptions': {
         'icon': '/static/svg/marker.svg',
     }
 } %}
 
 <style>
     #{{mapId}} {
         height: 100%;
     }
 </style>
 
 {{ googleMaps.map(entries, mapOptions).tag() }}
 
 {% if sprig.isRequest %}
     <script>
         googleMaps.init('{{ mapId }}');
     </script>
 {% endif %}

@drifteaur drifteaur changed the title "Unable to find marker" when loading map via prig "Unable to find marker" when loading map via Sprig Apr 14, 2022
@lindseydiloreto
Copy link
Collaborator

Hi @drifteaur,

There have been some changes recently in that area... which version of the Google Maps plugin are you running?

Also, feel free to DM me on Discord! I can help you get this sorted out in real-time.

@lindseydiloreto
Copy link
Collaborator

lindseydiloreto commented Apr 16, 2022

I've done some digging, and you are correct... there is currently a bug when using Sprig alongside of a map with info windows. This bug was introduced recently. And unfortunately, I won't be able to fix it before updating the plugin for Craft 4 compatibility.

As a short term solution, pin your version of the plugin to 4.1.4 exactly...

"doublesecretagency/craft-googlemaps": "4.1.4",

That should lock you to the last version before this bug was introduced.

Once I've updated the plugin to Craft 4, I'll take another look at resolving this Sprig conflict. Thanks for bringing it up! 👍

@lindseydiloreto lindseydiloreto added the Bug Report Something isn't working label Apr 16, 2022
@drifteaur
Copy link
Author

@lindseydiloreto great, the workaround works, thanks :)

@lindseydiloreto
Copy link
Collaborator

This is fixed in v4.2.3.

Go ahead and update when you get a chance, let me know if i missed anything. 👍

@wesleygooch
Copy link

@lindseydiloreto Is 4.2.3 still compatible with Craft 3? Thanks for looking into this.

@lindseydiloreto
Copy link
Collaborator

@wesleygooch It's not, sorry. Since v4.2.0, the plugin requires Craft 4.

@zizther
Copy link

zizther commented May 17, 2023

For anyone looking to support Google Maps 4.2.5+ with Sprig this now requires the 'inline': true option in plugin, else the data being stored will be added to the bottom of the page which may likely be outside the sprig refreshed content.

{{ map.tag({
    'inline': true,
    'assets': false,
    'callback': 'mapReady'
}) }}

@lindseydiloreto
Copy link
Collaborator

Thanks for that note @zizther. 👍

Fortunately, the example component already includes {'inline': true}. You must have grabbed a copy between February 2022 (when Sprig support was added) and July 2022 (when the inline option was added).

To prevent other people from tripping over the same issue, I've added a note to the documentation...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Report Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants