• Resolved jonantonio

    (@jonantonio)


    Hi,

    Our client using your plugin, is it possible to get reference the map instance so I can create a custom search script using js.

    Thank you

    The page I need help with: [log in to see the link]

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

    (@dylanauty)

    Hi @jonantonio,

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

    Yes, you can access the map instance directly via JavaScript by two primary methods, which I’ll showcase below.

    Instance by Array

    // Get map by map instance array
    const map = WPGMZA.maps[0];

    Instance by ID

    // Get map by map ID
    const map = WPGMZA.getMapByID(2);

    You can access these once the page is ready, but you may find it difficult to bind events in this way, and instead we recommend you bind to one of our event listeners.

    We might recommend “init.wpgmza” or “markersplaced.wpgmza“, which would be bound via a jQuery event listener:

    // Wait for markers to be placed on the map 
    jQuery(($) => {
      $(document.body).on('markersplaced.wpgmza', () => {
        // Process here
      });
    });

    I hope this helps?

    Thread Starter jonantonio

    (@jonantonio)

    Hi Dylan,

    Thank you for your insightful answers, really helped me a lot.

    Is it possible to do programmatical search using javascript?

    Regards

    Jon

    Plugin Author DylanAuty

    (@dylanauty)

    Hi @jonantonio,

    Only a pleasure, happy to help!

    You can trigger the search via the JavaScript API, but it is often simpler to trigger a button click for the search button on your existing search form.

    I had a look at your page and it seems that you have gone that direction. ?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How can I get access to the map instance using javascript?’ is closed to new replies.