• Resolved logicred

    (@logicred)


    Beneath my map I would like to a number of basic hyperlinks. When a link is clicked the map zooms to the lat/long in question. Ideally as basic as possible, like a javascript onclick and passing the lat/long perhaps?

    I see with the pro version I have an option to show all the markers in a list next to the map which does something similar, but I have looked at the resulting code and there are no links as such, just DIV containers with lots of code which magically act as a link.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter logicred

    (@logicred)

    I see there is the following openInfoWindow(wpgmza_markerid,wpgmza_mapid,true); but I read that it is perhaps no longer supported? This looks to be what I need.

    Plugin Author DylanAuty

    (@dylanauty)

    Hi @logicred,

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

    Although we do support some types of links on a map page, in this case you would probably be better off with a custom JavaScript function that meets your needs a bit closer.

    I would firstly recommend setting up your links using data-attributes, as this can might be more modular for adding new links in the future:

    <a href="#" class="wpgmza-button-relay" data-lat="51.5286416" data-lng="-0.1015987" data-zoom="12">
       London
    </a>

    With this in place, you should be able to add the following custom JavaScript to your site to action these links:

    jQuery(function($){
        $(document.body).on('click', '.wpgmza-button-relay', function(event){
            event.preventDefault();
            const lat = $(this).data('lat');
            const lng = $(this).data('lng');
            const zoom = $(this).data('zoom');
    
            if(lat && lng){
                WPGMZA.maps[0].setCenter({lat: lat, lng: lng});
            }
    
            if(zoom){
                WPGMZA.maps[0].setZoom(zoom);
            }
        });
    });

    This can be added to the plugins custom JavaScript area, or within a custom JavaScript file if preferred.

    I hope this helps?

    Thread Starter logicred

    (@logicred)

    Thanks Dylan! Works perfectly! Could I do the same thing, but pass the function a marked ID (instead of the Lat/Long cords) and it zooms to that?

    Thank you

    Plugin Author DylanAuty

    (@dylanauty)

    Hi @logicred,

    Only a pleasure!

    Yes, you could use a Marker ID instead, as an example the following HTML:

    <a href="#" class="wpgmza-button-relay" data-marker="1">
       London
    </a>

    Could then be handled with this JavaScript:

    jQuery(function($){
        $(document.body).on('click', '.wpgmza-button-relay', function(event){
            event.preventDefault();
            const marker = $(this).data('marker');
    
            if(marker){
                WPGMZA.maps[0].getMarkerByID(marker).onSelect();
            }
        });
    });

    I hope this helps?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Fly to a given co-ordinate via basic link’ is closed to new replies.