Skip Navigation

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

This thread is resolved. Here is a description of the problem and solution.

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 support ticket is created 5 years, 9 months ago. 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.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 2 replies, has 2 voices.

Last updated by Dido 5 years, 8 months ago.

Assisted by: Christian Cox.

Author
Posts
#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

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!