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

Craft Cloud Compatibility? #121

Open AdamChlan opened 3 weeks ago

AdamChlan commented 3 weeks ago

I'm curious if this plugin is compatible with Craft Cloud. I have a site set up on Craft Cloud, and the plugin works well when running in my local environment, but not on Craft Cloud. I am noticing a couple of the JS files the plugin is trying to call are 404.

Screenshot 2024-10-29 at 1 57 21 PM
lindseydiloreto commented 2 weeks ago

Great question! I haven't tested with Craft Cloud yet, so I guess we're finding out now that there are some compatibility issues.

Are you doing anything unusual with AJAX or Sprig? If not, take a look at these docs on Required JS Assets to see if there are any helpful workarounds in there. Perhaps you could prevent the automatic loading, and manually load those files instead.

lindseydiloreto commented 2 weeks ago

I suspect Craft Cloud is having trouble loading the JS files for these two lines...

<script src="https://yourwebsite.com/cpresources/[HASH]/js/googlemaps.js" defer></script>
<script src="https://yourwebsite.com/cpresources/[HASH]/js/dynamicmap.js" defer></script>

I'll dig in and let you know what I find. 👍

AdamChlan commented 1 week ago

@lindseydiloreto no, we are not doing anything unusual with AJAX or sprig on these templates. Any findings so far?

lindseydiloreto commented 4 hours ago

I don't have a full solution yet, but this might serve as a workaround in the meantime...

  1. Make a copy of googlemaps.js and dynamicmap.js, and store them directly in your project.

  2. Disable automatic loading of those assets.

{{ map.tag({'assets': false}) }}
  1. Load the assets manually, specifying your copy of the googlemaps.js and dynamicmap.js files...
<script src="https://maps.googleapis.com/maps/api/js?key={{ googleMaps.browserKey }}" defer></script>
<script src="https://unpkg.com/@googlemaps/markerclusterer/dist/index.min.js" defer></script>
<script src="https://yourwebsite.com/path/to/googlemaps.js" defer></script>
<script src="https://yourwebsite.com/path/to/dynamicmap.js" defer></script>

Hopefully that workaround does the trick until I can properly patch it for Craft Cloud support.