• Resolved Pipo

    (@epipo)


    Hi,

    First of all thanks for the plugin, it’s simple enough to be customized easily! I just need your help for a small issue I have.

    I’m trying to add the same zooming function available through the infoWindowsActions function to each #wpsl-store li. To be more precise, I want that, when clicked, each #wpsl-store li zoom on the corresponding marker in the map. I have tried to add a new event listener but I’m not sure which object to use…

    Could you help me or at least give me directions? Thanks!

    https://wordpress.org/plugins/wp-store-locator/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Tijmen Smit

    (@tijmensmit)

    Add this to the wpsl-gmap.js file.

    $( "#wpsl-stores" ).on( "click", "li", function() {
    	var i, len, storeId = $( this ).data( "store-id" );
    
    	for ( i = 0, len = markersArray.length; i < len; i++ ) {
    		if ( markersArray[i].storeId == storeId ) {
    			map.setCenter( markersArray[i].position );
    			map.setZoom( 15  );
    
    			return false;
    		}
        }
    });
    Thread Starter Pipo

    (@epipo)

    Awesome!! Thanks a lot, it’s working like a charm!!

    Yes!

    This is also a function I need, but how do I add the the function as a separate link eg. above “Show directions”?
    I want to keep the URL to the store homepage function.

    Something like this:
    Store name (with url link)
    Address
    Distances
    Zoom here
    Directions

    Thanks Tijmen, for this great plug-in!

    BR
    Simon

    Plugin Author Tijmen Smit

    (@tijmensmit)

    @simon

    If you open the /js/wpsl-gmap.js then search for ‘function storeHtml( response, url )’ or if you use the latest version go to line 1143. Then at the bottom of the function you see this.

    html = "<li data-store-id='" + id + "'>

    That line creates the html for the store listing. You can modify the order of the elements, and add a new link wherever you want and then give it an id. Something like this.

    <a id='show-directions'>Show Directions</a>

    Then copy the code from this post https://wordpress.org/support/topic/zoom-to-marker-from-store-list?replies=4#post-5794555 and change the

    $( "#wpsl-stores" )

    into this.

    $( "#show-directions" )

    Thanks for your hint!
    A friend helped me complete the function.
    Here is that solution:

    /* Zoom to store */
    $("#wpsl-stores").on('click', '.zoom-to-store', function() {
    	var i, len, $parentLi = $( this ).parents( "li" ), storeId = $parentLi.data( "store-id" );
    
    	for ( i = 0, len = markersArray.length; i < len; i++ ) {
    		if ( markersArray[i].storeId == storeId ) {
    			map.setCenter( markersArray[i].position );
    			map.setZoom( 15  );
    
    			return false;
    		}
        }
    });

    String to insert at html = “<li data-store-id='” + id + “‘>

    "<br><a class='zoom-to-store' href='#'>Zoom in map</a>"

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Zoom to Marker from Store list’ is closed to new replies.