Skip Navigation

[Resuelto] Focus on map marker corresponding to post in View results

Este hilo está resuelto. Aquí tiene una descripción del problema y la solución.

Problem:
A View lists posts, and also displays the same results as markers on a map. How to click on a post result and have the map focus on the corresponding marker?

Solution:
You can insert a button for each post into the View results with a required attributes that will focus the map on the marker, like so:

<button class="js-wpv-addon-maps-focus-map" data-map="map-name" data-marker="marker-[wpv-post-id]">
Focus on marker</button>

In the thread below custom JS is also provided which means that if the marker contains pop-up content (normally shown when clicked) this will be visible without the need to click: https://toolset.com/forums/topic/map-click-button/#post-1128927

Relevant Documentation:
https://toolset.com/documentation/user-guides/maps-shortcodes/#map-focus-on-marker

This support ticket is created hace 6 años, 1 mes. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

Este tema contiene 11 respuestas, tiene 2 mensajes.

Última actualización por Akhil hace 6 años, 1 mes.

Asistido por: Nigel.

Autor
Mensajes
#1127994

Hi, in my archive page, i would like to have a map icon . when you click that it will lead to the map marker thats next to it [in my case] .

How do i achive this pls. thank you.

#1128125

Nigel
Supporter

Idiomas: Inglés (English ) Español (Español )

Zona horaria: Europe/London (GMT+00:00)

"when you click that it will lead to the map marker thats next to it"

The archive lists posts, and displays the same results as markers on a map.

Clicking either the post or the marker would normally take you to the single post (where you might also display a map with the single marker).

What is it you want to do?

If a user clicks an icon on a post in the list of results, it should, what?, stay on the same page, displaying the same map, but "lead to the map marker", which means what exactly?

#1128126

Hi nigel.

Sorry for confusion.
on the archieve page i will create a map icon.
clicking that i want it to lead to the marker on the map on the SAME page.
clicking the title of course it goes to the detail page .

Thanks

#1128181

Nigel
Supporter

Idiomas: Inglés (English ) Español (Español )

Zona horaria: Europe/London (GMT+00:00)

"lead to the marker" is the bit I'm struggling with.

You mean the related marker should be highlighted when clicking the icon, or did you have something else in mind, such as when there are a lot of results, clicking the map icon scrolls back to where the map is shown?

#1128186

Yes youre right. : related marker should be highlighted when clicking the icon,

#1128269

Hi nigel, it seems toolset already have this function inside. great . below codes works , no idea whats the differences but it works.

 

<button class="js-wpv-addon-maps-focus-map Classnames js-toolset-maps-open-infowindow-map-directory-marker-[wpv-post-id]" data-map="map-directory" data-marker="marker-[wpv-post-id]">click map</button>
      
<button class="js-wpv-addon-maps-focus-map" data-map="map-directory" data-marker="marker-[wpv-post-id]">
Focus on marker</button> <!--infowindow missing?-->

<a href="#" class="js-wpv-addon-maps-focus-map js-toolset-maps-open-infowindow-map-directory-marker-[wpv-post-id]" data-map="map-directory" data-marker="marker-[wpv-post-id]">FIND ON MAP</a>

How can i have the marker with infobox open when clicking ? should i open another thread for this ?
thanks.

#1128309

Nigel
Supporter

Idiomas: Inglés (English ) Español (Español )

Zona horaria: Europe/London (GMT+00:00)

That's right, you can add a clickable element that will focus on a marker.

(It is described here: https://toolset.com/documentation/user-guides/maps-shortcodes/#map-focus-on-marker)

But it does just that, focuses on the marker.

The info window that appears when you click on the marker itself is initially closed.

Let me check with the developer if he can short-cut me towards a JS event that could be used to simulate the click that would open the info window (otherwise it will likely mean a feature request).

I should hear from him in the morning, and I'll update you.

#1128310

Thats great, thanks. have a good day ,

#1128927

Nigel
Supporter

Idiomas: Inglés (English ) Español (Español )

Zona horaria: Europe/London (GMT+00:00)

OK, so try adding the following JS to your View that outputs the map:

jQuery( document ).ready( function( $ ) {
    $( document ).on( 'click', '.js-wpv-addon-maps-focus-map', function( e ) {
        var $this = $( this );
        var mapId;
        var markerId;

        if (
            $this.attr( 'data-map' )
            && $this.attr( 'data-marker' )
        ) {
            mapId = $this.data('map');
            markerId = $this.data('marker');

            google.maps.event.trigger( WPViews.view_addon_maps.get_map_marker( markerId, mapId ), 'click' );
        }
    } );
} );

I just tried it on my local test site and it worked.

#1128935

Thabnks but Do i need to change anything inside ?

#1128979

Nigel
Supporter

Idiomas: Inglés (English ) Español (Español )

Zona horaria: Europe/London (GMT+00:00)

Nope, unless I've misunderstood what you have done already, the code doesn't require any editing, just add it to the custom JS section of your View that displays the map and list of results.

#1129146

excellent !

My issue is resolved now. Thank you!