Skip Navigation

[Resolved] Change map marker icon dynamically

This support ticket is created 6 years, 5 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

Author
Posts
#919603

Tell us what you are trying to do?
I am trying to build an interface which will allow users to choose a different "topic" to show content (Organisations) on a map using different marker icons. I currently have two taxonomies with custom image fields added which hold the marker icons for each term within each taxonomy. I would essentially like to add some buttons which let users select a topic, resulting in the marker icons changing on the map and those icons to be based of the term values for each post.

I do actually have it working, but I am wondering if there is a more elegant solution which needs to be less hard-coded.

What I have implemented at the moment is:
- created a CPT - "Organisation"
- added two custom taxonomies with custom image fields ("Organisation type" and "Geographical scope") - these share the same image field - "map-marker-icon"
- added some "Organisations" with values selected for the custom taxonomies mentioned above
- created a view which presents the map and the posts
- created two additional views which return the URL of the image from the desired taxonomy. These share a common custom template with the sole output being:
[types termmeta='map-marker-icon' size='thumbnail' url='true'][/types]
- inside a custom template, added the [map_marker] object and added a conditional which evaluates a URL parameter ("marker") and returns the desired view name into the marker_icon parameter of the [map_marker]. This looks like:
[wpv-conditional if="( '[wpv-search-term param='marker']' eq 'map-marker-organisation-type' )"]
marker_icon="[wpv-view name='map-marker-organisation-type']"
[/wpv-conditional]
- I then aim to add a custom button somewhere to control this functionality.

This works, but what I would like to do is pass the "marker" URL parameter directly to [wpv-view], more like:
marker_icon="[wpv-view name='[wpv-search-term param='marker']']"

This would remove the need to hard-code the view names in the conditional and just return the value directly to the view name, but this doesn't work.

When I turn on debug mode on [map_marker], it just says "Marker source unknown".

I have also tried setting up a custom shortcode to return the view name, but this ends up with the same result.

Is this possible and/or is there a better way to do this? This doesn't need to be from a URL parameter of course, definitely open to other options!

Is there any documentation that you are following?
Lots of different bits.

Is there a similar example that we can see?
Not that I have seen.

What is the link to your site?
This is extremely developmental, so excuse the horrible layout and icons - just working on functionality for now. The latest page is:
hidden link
but to get the different marker views:
hidden link
and
hidden link

As you can see, I am also going to be adding filters. I am aware that I probably also need to split this out into multiple views on a custom layout, but I will get to that.

#919775

Hello,

The attribute "marker_icon" accepts only the icon URL value, see our document:
https://toolset.com/documentation/user-guides/maps-shortcodes/#wpv-map-marker

You can output the icon in a content template, and use the content template shortcode as value of attribute "marker_icon", for example below thread:
https://toolset.com/forums/topic/different-marker-image-in-a-single-map/

#919846

Thanks for the reply,
yes, I had those elements working properly. I was trying to add an extra layer via a series of views (one per custom taxonomy) so that a user can choose different marker themes based off multiple taxonomies.

I managed to work it out but I am not entirely certain why there was an issue. It seemed that the solution related to where the "marker_icon=" text was actually added to the nest of views and templates. In the end, it seemed that it needed to be all the way down at the level of the final view, not in the first view or the template in the middle. I think I previously had it in the first view (number 1 in the list below).

The final structure from top down is:
1. Main page view containing (amongst other code of course) a reference to the content template instead of the marker_icon attribute in the wpv-map-marker object. i.e.:

[wpv-map-marker
      	map_id="map-3" 
      	marker_id="marker-[wpv-post-id]"
      	[wpv-post-body view_template='map-marker-template']
        marker_title="[wpv-post-title]" 
	marker_field="wpcf-organisation-address"
	]
	<a href="[wpv-post-url]">[wpv-post-link]</a>
[/wpv-map-marker]

2. Content template called map-marker-template (which calls one of several views based on a URL parameter) containing only:

[wpv-view name='[wpv-search-term param="marker"]']

3. The final set of views which in the loop, simply contain:

marker_icon="[types termmeta='map-marker-icon' size='thumbnail' url='true'][/types]"

Each of these final views is set to reference a different taxonomy and therefore returns the set of images for the taxonomy chosen by the "marker" URL parameter. This allows different images for each term across multiple taxonomies without any hardcoded if statements in a conditional.

I will then just add a series of buttons that control the "marker" URL parameter.