Close InfoWindow by Clicking on Map

New home Forums Pro Add-on General queries Close InfoWindow by Clicking on Map

Tagged: 

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #53604

    Is it possible to have InfoWindows close when you click anywhere outside of the infoWindow, instead of only closing when you click the X?

    #53610
    Steven
    Moderator

    Hi there,

    Thank you so much for getting in touch, we really appreciate your time.

    This is possible using the custom JavaScript field built into WP Google Maps.

    Please navigate to -> Maps -> Settings -> Advanced -> Please paste the below script into the custom JavaScript field,

    jQuery(window).load(function() {
    if(typeof MYMAP !== ‘undefined’){
    for(var mapindex in MYMAP){
    google.maps.event.addListener(MYMAP[mapindex].map.googleMap, ‘click’, function(e) {

    // close infowindows
    infoWindow.forEach(function(entry, index) {
    infoWindow[index].close();
    });
    });
    }
    }

    });

    Please then click save and confirm if this helps?

    I look forward to hearing back from you.

    Kindest Regards,
    Steven De Beer

    #53674
    bigfootjohn
    Member

    Hi,

    This didnt work for me.

    #53676
    Steven
    Moderator

    Hi there,

    Thank you so much for getting back to us.

    Could I kindly ask you to provide us with a link to your website so that we may take a closer look at some custom script specific to your site?

    I look forward to hearing back from you.

    Kindest Regards,
    Steven De Beer

    #53963
    bigfootjohn
    Member

    Seems that is issues with this forum. Sometimes it is removing some lines/snippets from code.

    Can you please check the code again and attach it in a text file instead?

    #53966
    Steven
    Moderator

    Hi again,

    Thank you so much for getting back to us.

    Could I kindly ask what versions of WP Google Maps you are currently using?

    This custom script which I have attached should function correctly on V7 of WP Google Maps, however, should probably not function on older versions of WP Google Maps.

    I look forward to hearing back from you.

    Kindest Regards,
    Steve

    Attachments:
    You must be logged in to view attached files.
    #53972
    bigfootjohn
    Member

    Worked like a charm. Thank you!

    #53973
    Steven
    Moderator

    Hi again,

    Thank you so much for getting back to me.

    I am glad to hear this worked correctly for you. 🙂

    Please do let us know if there is anything more we can help with as we are always eager to assist.

    Do have a pleasant day further.

    Kindest Regards,
    Steven De Beer

    #55688
    phi
    Member
    This reply has been marked as private.
    #55704
    Steven
    Moderator

    Hi there,

    Thank you so much for getting in touch, we really appreciate your time.

    Could I kindly ask you to replace the script above with the below?

    
    jQuery(window).load(function() {
      if(typeof MYMAP !== 'undefined'){
      	for(var mapindex in MYMAP){
            google.maps.event.addListener(MYMAP[mapindex].map.googleMap, 'click', function(e) {
                // close infowindows
                infoWindow.forEach(function(entry, index) {
                    infoWindow[index].close();
                });
            });
        }
      }
    });
    

    Kindly confirm if this helps?

    I look forward to hearing back from you.

    Kindest Regards,
    Steve

    #55816
    phi
    Member

    Hi Steven,

    Thank you for the reply. I have replaced the script, but unfortunately it did not resolve the issue.

    Instead I now have the following error in the console:

    jquery.min.js:2 Uncaught TypeError: e.indexOf is not a function
        at k.fn.init.k.fn.load (VM210 jquery.min.js:2)
        at (index):343

    Clicking on outside of the window does nothing now, does not close the map on any attempt.

    Looking forward to your reply.

    Best regards,
    Verner

    #55859
    Steven
    Moderator

    Hi Verner,

    Thank you so much for getting back to us.

    Could I kindly ask you to create a ticket here: https://www.wpgmaps.com/contact-us/ so that one of our agents may take a more personal look at your website in order to get this working correctly for you?

    We look forward to hearing back from you.

    Kindest Regards,
    Steven De Beer

    #55992
    Perry
    Moderator

    Hi there

    The updated solution for this is the following snippet

    jQuery(function($) {
    
    	$(window).on("click.wpgmza", function(event) {
    	
    		if(event.target instanceof WPGMZA.Map && event.target.lastInteractedMarker)
    			event.target.lastInteractedMarker.infoWindow.close();
    	
    	});
    
    });

    Kind regards
    – Perry

    #56005
    phi
    Member

    Hi,

    The provided code works properly, thank you very much for the assistance!

    Best regards,
    Verner

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