Change map marker list to direct links

New home Forums Pro Add-on General queries Change map marker list to direct links

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #24048
    adambradford
    Member

    Is there a way to change the behaviour of the map marker list so that when you click an item in the list, instead of opening a popup on the map, it takes you straight through to the link URL specified in the marker details?

    Thanks,

    Adam.

    #24050
    Nick Duncan
    Keymaster

    Hi there Adam
    Thank you for getting in touch and for using my plugin!

    This can definitely be done with a bit of manipulation of the code.

    Which marker list are you currently using? If you let me know that I will be able to let you know which part of the code to change.

    Kind regards
    Nick

    #24054
    adambradford
    Member

    Thanks Nick. I’m using Basic List, Below Map

    #24057
    Nick Duncan
    Keymaster

    Thanks Adam

    Please open wp-google-maps-pro/wpgmza.php and find the following code (around line 439)

    else if ($type == 4) {
    
        $wpgmza_tmp_body .= "<div id=\"wpgmza_marker_".$result->id."\" mid=\"".$result->id."\" mapid=\"".$map_id."\" class=\"wpgmaps_blist_row\">";
    
        if (isset($hide_icon_column) && $hide_icon_column == "yes") { } else { $wpgmza_tmp_body .= "   <div class='wpgmza-basic-list-item wpgmza_div_marker' style='max-width: 14px; max-height: 14px;'>".str_replace("'","\"",$icon)."</div>"; }
        if (isset($hide_title_column) && $hide_title_column == "yes") { } else { $wpgmza_tmp_body .= "   <div class='wpgmza-basic-list-item wpgmza_div_title'> ".stripslashes($result->title)."</div>"; }
        if (isset($hide_address_column) && $hide_address_column == "yes") { } else { $wpgmza_tmp_body .= " <div class='wpgmza-basic-list-item wpgmza_div_address'> (".stripslashes($result->address).")</div>"; }
        $wpgmza_tmp_body .= "</div>"; 
    
    }

    and change it to this:

    else if ($type == 4) {
        $wpgmza_tmp_body .= "<div id=\"wpgmza_marker_".$result->id."\" mid=\"".$result->id."\" mapid=\"".$map_id."\" class=\"wpgmaps_blist_row\">";
        if (isset($hide_icon_column) && $hide_icon_column == "yes") { } else { $wpgmza_tmp_body .= "   <div class='wpgmza-basic-list-item wpgmza_div_marker' style='max-width: 14px; max-height: 14px;'>".str_replace("'","\"",$icon)."</div>"; }
        if (isset($hide_title_column) && $hide_title_column == "yes") { } else { $wpgmza_tmp_body .= "   <div class='wpgmza-basic-list-item wpgmza_div_title'> ".stripslashes($result->title)."</div>"; }
        if (isset($hide_address_column) && $hide_address_column == "yes") { } else { $wpgmza_tmp_body .= " <div class='wpgmza-basic-list-item wpgmza_div_address'> (".stripslashes($result->address).")</div>"; }
        if (isset($result->link) && $result->link !== "") { $wpgmza_tmp_body .= " <div class='wpgmza-basic-list-item wpgmza_div_link' style='display:none;'>".stripslashes($result->link)."</div>"; }
        $wpgmza_tmp_body .= "</div>"; 
    }

    Then open up wp-google-maps-pro/js/core.js and look for this section (around line 932)

    jQuery("body").on("click", ".wpgmaps_blist_row", function() {
        var wpgmza_markerid = jQuery(this).attr("mid");
        var wpgmza_mapid = jQuery(this).attr("mapid");
        openInfoWindow(wpgmza_markerid,wpgmza_mapid,true);
        
    });

    and change it to this:

    jQuery("body").on("click", ".wpgmaps_blist_row", function() {
        if (jQuery(this).find(".wpgmza_div_link").length>0) {
            window.open(jQuery(this).find(".wpgmza_div_link").html(),"_blank");
        }
        var wpgmza_markerid = jQuery(this).attr("mid");
        var wpgmza_mapid = jQuery(this).attr("mapid");
    
        openInfoWindow(wpgmza_markerid,wpgmza_mapid,true);
        
    });

    Is this what you were after?

    This will only work if there is a link assigned to that marker, otherwise it will continue with the normal behaviour. If you don’t want to open the link in a new window, simply remove the ,”_blank” section.

    Kind regards
    Nick

    #24070
    Nick Duncan
    Keymaster

    Hi Adam
    Shout if you need help with this. I can log in and do it for you if you wish. If you prefer this then please send me temp account details below in a private reply.

    Kind regards
    Nick

    #24080
    adambradford
    Member

    Yes, that’s exactly what I was after! It works a treat.

    Removing the “_blank” part didn’t seem to do anything, so I changed it to “_self” instead. Now the link opens in the same window.

    Many thanks Nick, great support as ever!

    #24081
    Nick Duncan
    Keymaster

    It was my pleasure! Thank you Adam!
    Nice work on the “_self” change 🙂

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