doublesecretagency / craft-googlemaps

Google Maps plugin for Craft CMS - Maps in minutes. Powered by the Google Maps API.
https://plugins.doublesecretagency.com/google-maps/
Other
10 stars 10 forks source link

.collect() stops some functions from working #100

Closed MattWilcox closed 10 months ago

MattWilcox commented 11 months ago

Sorry, don't have a reduced test case. We had things all working but then swapped some non-maps Twig to use .collect() instead of .all() - and the Google Maps infoWindows stopped working.

Looks like the plugin is not finding something when the main pins query(s) use .collect() instead of .all().

querys

Allows the later code to work:

{% set protectedParksInRange = craft.entries
    .section([
        "protectedParks"
    ])
    .googleMap({
        'target': {
            'address': searchFromLocation,
            'components': {
                'country': 'UK'
            }
        },
        'range': searchedRadius,
        'units': 'km',
        'cluster': true,
    })
    .all()
%}

Breaks the later code:

{% set protectedParksInRange = craft.entries
    .section([
        "protectedParks"
    ])
    .googleMap({
        'target': {
            'address': searchFromLocation,
            'components': {
                'country': 'UK'
            }
        },
        'range': searchedRadius,
        'units': 'km',
        'cluster': true,
    })
    .collect()
%}

map code

{# Create the map with no markers #}
    {% set map = googleMaps.map() %}

{# Configure the icons #}
    {% set iconProtected = {
        'url': '/dist/images/pins/protected-park.svg',
        'scaledSize': {'width': 30, 'height': 40}
    } %}
    {% set iconUnprotected = {
        'url': '/dist/images/pins/unprotected-park.svg',
        'scaledSize': {'width': 30, 'height': 40}
    } %}

{# Add all the protected park markers to the map #}
    {% do map.markers(protectedParksInRange, {
        'icon': iconProtected,
        'infoWindowTemplate': '_partials/map-info-window',
        'components': {
            'country': 'UK'
        }
    }) %}

{# Add all the unprotected park markers to the map #}
    {% do map.markers(unprotectedParksInRange, {
        'icon': iconUnprotected,
        'infoWindowTemplate': '_partials/map-info-window',
        'components': {
            'country': 'UK'
        }
    }) %}

{# Draw the range circle #}
    {% do map.circles(locationSearchMatchedAddress, {
        'circleOptions': {
            'radius': searchedRadius * 1000,
            'fillColor': '#7A9F35',
            'fillOpacity': 0.35,
            'strokeColor': '#7A9F35',
            'strokeOpacity': 0.8,
            'strokeWeight': 2,
        }
    }) %}

{# Apply the styles #}
    {% do map.styles(styles) %}

{# Output the map to markup #}
    {{ map.tag() }}

Map and pins load fine; clicking on the pins to trigger a pop-up will only work if the original query was a .all(), nothing at all happens on click of the pin when the original query is a .collect()

lindseydiloreto commented 10 months ago

Congrats on opening ticket #100!! 🎉 🎊

Great catch, thanks for reporting. This has been fixed in v4.3.11.