• Resolved e dev

    (@efishinsea)


    I’m trying to fire a JS callback function when a map marker is clicked to act on the popup window for that marker point. I can’t seem to find this addressed in the docs. Is it possible?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author DylanAuty

    (@dylanauty)

    Hi @efishinsea,

    Thank you for getting in touch, we do appreciate your time.

    Yes, this is possible in a few ways as we offer both an extendable JavaScript core, and various document events. For this example, I’ll showcase the event system as this is a bit simpler and more future-safe as it does not override any of the core modules.

    Please see an example script below:

    jQuery(($) => {
    $(document.body).on('click.wpgmza', (event) => {
    /* Check if the click originated from a marker */
    if(event && event.target && event.target instanceof WPGMZA.Marker){
    const marker = event.target;
    const map = marker.map;
    const infowindow = marker.infoWindow;

    /* Note, the infowindow might not be ready yet. We'd recommend a short timeout here, to allow it to initialize */
    console.log(marker, map, infowindow);
    }
    });
    });

    As an alternative, you may prefer to simply listen for infowindow (popup) open calls, as seen below:

    jQuery(($) => {
    $(document.body).on('infowindowopen.wpgmza', (event) => {
    /* Act on the info-window, you can also access data from the event object */
    if(event && event.target && event.target instanceof WPGMZA.InfoWindow){
    const infowindowElement = event.target.element;
    const infowindowMarker = event.target.feature;
    const infowindowMap = event.target.parent;

    console.log(infowindowElement, infowindowMarker, infowindowMap);
    }
    });
    });

    This second option may simplify the way you integrate with the plugin, as it will trigger whenever the popups are opened, instead of opening specifically on a marker click event.

    I hope this helps?

    Thread Starter e dev

    (@efishinsea)

    thank you!

    Plugin Author DylanAuty

    (@dylanauty)

    My pleasure @efishinsea – Have a great day!

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.