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 8 forks source link

Error in `dynamicmap.js`: `this._markerClick` is not a function #49

Closed MoritzLost closed 2 years ago

MoritzLost commented 2 years ago

I'm trying to initialize an info window in JavaScript, but it's not working correctly. In 4.1.1, the following code worked fine (simplified to relevant parts):

const marker = {
    id: `marker-lat-lng-123,456`,
    lat: 123,
    lng: 456,
};
const infoWindowHtml = '<p>the title</p>';
map.markers(marker, {
    infoWindowOptions: {
        content: infoWindowHtml,
    },
})

While this doesn't cause any errors, the info window doesn't open when the marker is clicked. I tried to attach an event listener to open it manually using the markerClick option, at which point I get the following error message in the console:

Uncaught (in promise) TypeError: this._markerClick is not a function markers dynamicmap.js:174

Indeed it looks like the _markerClick function doesn't exist anymore in dynamicmap.js. I checked the JS file in 4.1.1, which still includes the _markerClick function. Regression bug?

In addition to this bug, what is the 'correct' way to attach simple info windows to markers in 4.1.5?

lindseydiloreto commented 2 years ago

Definitely a regression bug. Good catch, thanks for reporting it!

I'll follow up with you via Discord DM to resolve this and #48.

MoritzLost commented 2 years ago

@lindseydiloreto Thanks! I've tried the latest branch and it does fix the error message – but I still can't get the info window to show up. I've tried to show all info windows just to test if they're being created at all, but it looks like they aren't:

const marker = {
    id: `marker-lat-lng-123,456`,
    lat: 123,
    lng: 456,
};
const infoWindowHtml = '<p>the title</p>';
map.markers(marker, {
    infoWindowOptions: {
        content: infoWindowHtml,
    },
    markerClick: () => map.openInfoWindow('*'),
})

This doesn't do anything. I've also put some logging inside dynamicmap.js just to check, looks like this._infoWindows is completely empty, even after calling the map.markers with the infoWindowOptions shown above. I've looked through the 4.1.1 branch again, in this version, the map.markers function included some code to attach the info window. Those lines are gone in 4.1.5, so maybe the info windows aren't being attached at all?

lindseydiloreto commented 2 years ago

This is now fixed in v4.1.6. Thanks again for reporting it! 👍