Skip Navigation

[Resolved] custom map marker icons not updating

This support ticket is created 2 years, 10 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)

Author
Posts
#2085263

Tell us what you are trying to do?
using Comanchetown.com/map

I am showing different icons for different map markers depending on the type of object being marked
the icon is set for each item using [set_icon] :
update_post_meta( $post_ID, 'wpcf-marker-icon', 'hidden link' );}

and the URL is immediately read back to set the image for that marker :
marker_icon="[types field='marker-icon' output="raw"][/types]" -->> in Pilots Parent view

the first time I display the map (using cjstumpf@gmail.com) the stumpf icon is green as expected
the next time (using the nearby j1_gregory@us.aflac.com} the stumpf icon stays green and the gregory icon stays yellow
--- they both should have changed

if I then redisplay the map (using cjstumpf@gmail.com) the gregory icon changes to green and the stumpf icon to yellow

--- they are ONE-STEP behind what is expected, it appears to me there is a cache issue. I have checked
that the database is being updated as expected (using a diagnostic in [set_icon]) and also with the pilots directory
I also tried
marker_icon="[types field='marker-icon' "] -->> in Pilots Parent view

You have the login if you which to see the code directly

Is there any documentation that you are following?
YES, #380694

What is the link to your site?
comanchetown.com/map

#2086759

Hi, I'll be glad to take a look if you provide login credentials in the private reply fields here. I am activating private reply fields for your next reply. Please let me know where I can find this custom code you mentioned.

#2088871

I'm a bit confused by what you're trying to accomplish, there are quite a few nested Views and a lot going on here. If I understand correctly, you expect one marker to be displayed using different icons. That icon is set using the set_icon function when the page loads. So that means you're setting the icon dynamically. Walk me through why the icon would be green in one case and yellow in another case for the same item? Based on what I can see in the set_icon function, the icon is dependent upon the value of some custom fields:
- range2
- business
- buysell
- photo
- message
- content

Can you explain how those custom field values would change from the first time I see the map to the second time I see the map? And what prevents this process from happening out-of-sync, say if more than one person is visiting the map at the same time? I'm really not following the logic here.

#2088875

Sorry I should also have mentioned that if you feel it's a caching issue and you'd like to turn off Views caching for one or more nested Views as a test, feel free to set cached="off" in the View shortcode like so:

[wpv-views name="your-nested-view-slug" cached="off"]

That will disable Views-level caching on a nested View. Views that include maps are not cached by default, so caching should not be a factor in your top-level View.

#2089841

1 created page: "MAP - toolset test" (a clone of MAP)
2 created view "Pilots Parent view - toolset test" (a copy of Pilots Parent view)
3 removed all the code from this view that is not directly relevant to the unreliable icon issue)
4 access MAP - toolset test -- hidden link
5 enter cjstumpf@gmail.com - note the green marker, and yellow marker everywhere else (including James Corliss directly below)
6 enter james@tpdi.biz (James Corliss) - note: neither cjstumpf nor the james icons change when they should have)
6a check the directory listing for cjstumpf = hidden link
6b check the directory listing for james@tpdi.biz = hidden link
so the icon should have changed (based upon the updated URL in the table (Pilots)
-- note the icon URL is all the way to the right in the directory

7 enter cjstumpf@gmail.com again - note the james@tpdi.biz marker is now green and the cjstumpf@gmail.com marker is pink
7a check the directory listing for cjstumpf = hidden link
7b check the directory listing for james@tpdi.biz = hidden link
so the icon should have changed to correspond with the updated URL in the table (Pilots type))

Note the marker icon comes from: marker_icon="[types field='marker-icon' output="raw"][/types]"

The logic of the code is as follows:
(1) Find one record based upon a unique email address (Pilot Parent view)
(1a) Set this record as the Anchor pilot via [set_start], and set this record icon URL, via [set_icon]
(2) Create a Marker for this {"Anchor") pilot by (read only) the icon URL stored in this record <-- the icon should the same as 1a
(3) "Pilots-Pre-Child-view" -- calculates distances - does not touch icons
(4) "Pilots-Child-view" -- creates Markers for all other pilots, via (read only) marker_icon="[types field='marker-icon']"
(5) Render map
(6) "pilots-zero-range-view" -- strictly data-processing, does not touch field='marker-icon'
(7) Display one record from (1) above -- does not touch field='marker-icon'

In summary: the sequence: cjstumpf@gmail.com -> james@tpdi.biz -> cjstumpf@gmail.com -- does not work (1 step behind)
while the sequence: cjstumpf@gmail.com -> james@tpdi.biz -> james@tpdi.biz -- does work eventually
by work I mean, the Marker for email address being searched for shows as a Green icon

the relevant part of [set_start] is: setting range2 of the anchor pilot to zero
the relevant part of [set icon] is: if range2 = 0 then: 'wpcf-marker-icon', 'hidden link' );}
-- seeing as this is the last statement in the snippet it will take precedence

I put a diagnostic statement at the end of Template: Pilots Popup (now commented out because people are using the site)
eg., [types field='marker-icon'][/types]
if you click on either of those markers it will show the icon displayed is different from the URL stored in the database

#2090875

Thanks for the demo view and the comprehensive details, that is very helpful. I don't see any obvious reason why the icons would be displayed differently from the custom field URLs stored in the database. I think the best way for me to continue investigating here is to make a clone of the site so I can do more on-the-fly debugging, PHP logging, and alter some of these child Views without modifying the live site. If that is okay with you, I can use the Duplicator plugin I see already installed to make a clone of the site and begin those tests. Please let me know if you approve of cloning the site and installing it on my local environment, and I will get started.

#2091037

please go ahead

#2091905

I've tried to narrow things down on my local environment by working with the anchor pilot only, and commenting out all the other elements in the Pilots Parent view - toolset test View here:
hidden link

I've commented out these elements for testing purposes:

<!--[wpv-view name="Pilots-Pre-Child-view" maxrange= "[urlparam param= 'maxrange' default= 200 /]" min= "[set_min]" max= "[set_max]"] 
	[wpv-view name="Pilots-Child-view" maxrange= "[urlparam param= 'maxrange' default= 200 /]" min= "[set_min]" max= "[set_max]"]-->
...
<!--[wpv-view name="pilots-zero-range-view"]-->   <!-- Reset pilot range2 to zero miles (between runs)-->
    <!--[wpv-post-body view_template="loop-item-in-pilots-parent-view-toolset-test"] [show_ip]--> <!-- list the anchor pilot (under map) -->
...
<!--[timer]-->

Now I can see that the anchor pilot icon is green consistently, when I search by email address. As I understand it, this is expected, correct? So I don't think this is entirely a caching issue, or that the View is showing the wrong icon based on the custom field value in the database. I think that the postmeta value is being changed on-the-fly during one of these commented out processes.

#2092151

No. the icons should not remain the same (green) every time, the whole point is for all the marker icons to change

I've simplified the test even more:
I've left the two nested views commented out (just as you did)
(1) I've put in a diagnostic to display the icon URL just before, and just after it is set on the marker
(2) there is now only one snippet (set icon test], which tests the marker_icon field value
-- and simply switches back and forth between green and yellow
-- by changing the URL in the marker_icon field

if you use cjstumpf@gmail.com multiple times in a row you will see the icon does not correspond with the field setting

#2092153

I should have said:
I'm using the page hidden link {as before}
and the view: hidden link {as before}
and the new [set icon test]

#2092767
#2092989
#2094757

Okay this simpler test makes it easier for me to understand the problem. I'm still investigating and I will give you another update today, I may need to loop in my 2nd tier support team for further investigation.

#2095277
Screen Shot 2021-06-21 at 11.06.24 PM.png
Screen Shot 2021-06-21 at 11.06.16 PM.png

After a bit more investigation I was able to replicate this problem in a site I created from scratch, using a single View and a shortcode similar to your stripped-down version:

add_shortcode( 'switch-icons', 'switch_icons_function');
function switch_icons_function( $atts ){
// Attributes
	$atts = shortcode_atts(array(
		'post_index' => '',
	), $atts );
//

$post_ID = get_the_ID();

if ( get_post_type( $post_ID ) == 'book') {
	
$icon = get_post_meta($post_ID, 'wpcf-book-marker-icon-1', true);	
	if ($icon <> '<em><u>hidden link</u></em>' ) {
	update_post_meta( $post_ID, 'wpcf-book-marker-icon-1','<em><u>hidden link</u></em>' );
	} else {
	update_post_meta( $post_ID, 'wpcf-book-marker-icon-1', '<em><u>hidden link</u></em>' );}
	}	
};

View code:

[wpv-layout-start]
	[wpv-items-found]
[wpv-map-render map_id="map-2"][/wpv-map-render]
	<!-- wpv-loop-start -->
		<wpv-loop>
          [switch-icons][/switch-icons]
          Marker icon: [types field='book-marker-icon-1' output='raw'][/types]
          [wpv-map-marker map_id='map-2' marker_id='marker-2-[wpv-post-id]' marker_icon='[types field="book-marker-icon-1" output="raw"][/types]' marker_field='wpcf-book-address-1'][/wpv-map-marker]
		</wpv-loop>
	<!-- wpv-loop-end -->
	[/wpv-items-found]
	[wpv-no-items-found]
		<strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
	[/wpv-no-items-found]
[wpv-layout-end]

I only have one post, and the problem can be seen in my map with just one result when I refresh the page. It seems that the icon shown in the results and the icon in the map should be identical, but they are not, as shown in my demo and your site as well. I'm asking my 2nd tier team to take a closer look. I'm not sure if there's an issue with the timing of the marker icon assignment, or a caching issue in Google Maps, or something else I don't understand, so hopefully they can tell me what I'm missing. I'll give you an update tomorrow when I have received some feedback.

#2095927

Thanks for persisting with this
One thing I could do, if I knew how, is instead of just changing the icon, is to delete the marker and create another identical one
But fixing the refresh issue would be best
Thanks

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.