How to link directly from a polygon

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

Tagged: 

This topic contains 10 replies, has 5 voices, and was last updated by  harpreetsandhu 10 months, 4 weeks ago.

Viewing 12 posts - 1 through 12 (of 12 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.

    #43428

    gcfrphoto
    Member

    does this apply to the current version as well? im having trouble finding it.

    #43432

    SupportTeam
    Moderator

    Hi there,

    Thank you so much for getting in touch with us.

    Are you looking to have the link automatically load when a visitor clicks the polygon?

    If so please try adding the following script to Maps -> Settings -> Advanced in the Custom JS field:

    https://gist.github.com/andtrev/cddc0f4ad69b0c17a428dbd398131ecb

    Thanks so much, hope this helps?

    Kind Regards,
    Trevor Anderson

    #43447

    gcfrphoto
    Member

    Yes! That worked! Thank you!

    #43480

    SupportTeam
    Moderator

    Hi there,

    So glad this worked for you. If there’s anything else I can help you with please let me know.

    If you ever have two minutes spare, please consider reviewing the plugin on https://wordpress.org/support/plugin/wp-google-maps/reviews/#new-post it would mean the world to me! (If possible, could I ask you to mention both your name and mine in the review for administrative purposes, this would be a tremendous help!)

    Thanks so much,

    Kind Regards,
    Trevor Anderson

    #45283

    Is this still valid code? It is not working for me.

    #45298

    SupportTeam
    Moderator

    Hi there,

    Thank you so much for getting in touch with us.

    The code should still be working, may I ask for a link to the map you’re trying to get this working with?

    Thanks so much,

    Kind Regards,
    Trevor Anderson

Viewing 12 posts - 1 through 12 (of 12 total)

You must be logged in to reply to this topic.