Skip Navigation

[Résolu] Retrieving marker id or custom post id in a view based on focus within map

Ce fil est résolu. Voici une description du problème et la solution proposée.

Problem: I would like to be able to access marker information using JavaScript.

Solution: You can access all the Marker objects in JavaScript here:

WPViews.view_addon_maps.markers

They are organized by map ID and marker ID.

You can also add event listeners that respond to marker clicks. See the example "Using Closures in Event Listeners" in the documentation below. If you add a click handler to the Markers, then inside the callback you can access the marker ID. You could use that ID to show and hide other content on the page. For example if the marker ID is 'marker123', then you could add a CSS class "marker123" to some div in the second View. When the marker is clicked, hide all the other content in the second View, and show div.marker123

Relevant Documentation:
https://developers.google.com/maps/documentation/javascript/events

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.

This topic contains 2 réponses, has 2 voix.

Last updated by Dido Il y a 2 années et 6 mois.

Assigned support staff: Christian Cox.

Auteur
Publications
#1197940
Ashampoo_Snap_Friday, 8 February 2019_18h15m58s_001_.png

Tell us what you are trying to do? Trying to display some information (details) to the right of a toolset map.
Currently multiple markers are displayed on the map using a loop. Details of all the locations are displayed next to the map. However, the window next to the map should only display details of the selected (clicked) location. Maybe I should use two views on this page? But I don't know how to retrieve that single marker id or custom post id in the second view.

Is there any documentation that you are following? Yes, I have looked at https://toolset.com/documentation/user-guides/maps-shortcodes/#wpv-map-marker hoping to find an attribute (boolean) specifying whether a marker is selected or not. But these shortcodes may not have implemented all attributes in the object model?

Is there a similar example that we can see? hidden link

What is the link to your site? hidden link

#1198248

Christian Cox
Supporter

Languages: Anglais (English )

Timezone: America/New_York (GMT-04:00)

Hi, you can access all the Marker objects in JavaScript here:

WPViews.view_addon_maps.markers

They are organized by map ID and marker ID.

You can also add event listeners that respond to marker clicks. See the example "Using Closures in Event Listeners" in the documentation here: https://developers.google.com/maps/documentation/javascript/events

If you add a click handler to the Markers, then inside the callback you can access the marker ID. You could use that ID to show and hide other content on the page. For example if the marker ID is 'marker123', then you could add a CSS class "marker123" to some div in the second View. When the marker is clicked, hide all the other content in the second View, and show div.marker123

#1220923

My issue is resolved now. Thank you!