Set the zIndex of a specific marker


All markers are displayed on the map in order of their zIndex, with higher values displaying in front of markers with lower values. By default, markers are displayed according to their vertical position on screen, with lower markers appearing in front of markers further up the screen.

To change the zIndex of a specific marker on your map, add the following code to the file “functions.php” of your theme/child theme:

/**
 * Set zIndex of a marker */

function cspm_set_marker_zIndex($default, $map_id){
	
	$output = "
		plugin_map.gmap3({
			exec: {
				name: 'marker',
				all: true,
				func: function(data){
					var marker = data.object;
					var post_id = marker.post_id;
					
					// Replace 'YOUR_POST_ID' with the ID of the post associated with the marker for which you want to adjust the zIndex
					if(post_id == 'YOUR_POST_ID'){
                        marker.setZIndex(9999); // You can modify the zIndex to any value greater or less than 9999!
                    }
				}
			}
		});
	";
	
	echo $output;
	
}
add_filter('cspm_after_map_load', 'cspm_set_marker_zIndex', 10, 2);

In the above code, replace 'YOUR_POST_ID' with the ID of the post associated with the marker for which you want to adjust the zIndex!


In the same context