How to link directly from a polygon

New home Forums Pro Add-on General queries How to link directly from a polygon

Tagged: 

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #22381
    bencal
    Member

    Hi,
    i have four polygons on my website and each one link to a page.
    The behaviour i want it to have is to link directly to the new page without having to click on the title of the polygon.
    I would really appreciate your help.
    Thanks in advance.

    #22385
    Dylan
    Moderator

    Hi there,

    Thank you so much for taking a moment to get in touch with us.

    This can be achieved by making some alterations to the core functionality of WP Google Maps.

    Would you be comfortable with applying code changes yourself? If so I would be able to guide you through this relatively easily.

    Alternatively I would be happy to make the changes on your behalf. 🙂

    #22399
    bencal
    Member

    Hi thanks for your reply.
    No problem with code modifications, I already searched for the code to be changed but i couldn’t find it.
    I’m ready to listen to you! ;o)

    #22438
    Dylan
    Moderator

    Hi there,

    Not a problem at all, always happy to help.

    Please open the core.js file (wp-google-maps-pro/js/core.js) and find the following segment of code (At line 2792 Approx.):

     google.maps.event.addListener(WPGM_Path_Polygon[polygonid], "click", function(event) {
    
       this.setOptions({fillColor: "#"+tmp_data['ohfillcolor']});
       this.setOptions({fillOpacity: tmp_data['ohopacity']});
       this.setOptions({strokeColor: "#"+tmp_data['ohlinecolor']});
       this.setOptions({strokeWeight: 2});
       this.setOptions({strokeOpacity: 0.9});
    });

    Once you have found this, please change it to the following:

    google.maps.event.addListener(WPGM_Path_Polygon[polygonid], "click", function(event) {
        if(typeof tmp_data['link'] !== "undefined" && tmp_data['link'] !== ""){
           window.open(tmp_data['link']);
        }
    
        this.setOptions({fillColor: "#"+tmp_data['ohfillcolor']});
        this.setOptions({fillOpacity: tmp_data['ohopacity']});
        this.setOptions({strokeColor: "#"+tmp_data['ohlinecolor']});
        this.setOptions({strokeWeight: 2});
        this.setOptions({strokeOpacity: 0.9});
    });

    Once this is done, you can save the file and it should open any polygon links on click.

    I hope this helps?

    #22721
    bencal
    Member

    Hi!
    It works perfectly my friend! Thank you so much! That’s what I call efficiency ;o)
    Is there a way to keep the changes even after updates?

    #22729
    Dylan
    Moderator

    Hi there,

    Only a pleasure, so glad to hear this worked as expected. 🙂

    Unfortunately the changes will need to be re-applied if a future update is released as updates will revert the code changes applied.

    My apologies for any inconvenience caused.

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