This hook allows developers to customize the spiderfier settings in the WP Maps Pro plugin, which is used for clustering overlapping markers on a map. It is triggered when the map marker spiderfier settings are being retrieved, allowing modifications to the default settings.
Usage
Developers can implement this hook in their theme’s functions.php
file or a custom plugin. It is useful for altering how markers are displayed when they overlap, such as changing the behavior of spiraling or the minimum number of markers required to trigger spiderfying. Here are some practical tips: ensure your changes don’t conflict with other map settings, and test across different browsers to ensure compatibility.
Example 1
Modify spiderfier settings to disable the spiral feature and require only 5 markers to spiderfy.
add_filter('wpgmp_map_marker_spiderfier_settings', function($settings, $map) { $settings['marker_enable_spiral'] = 'false'; $settings['minimum_markers'] = '5'; return $settings; }, 10, 2);
Example 2
Enable spiderfying only if the map being displayed has a specific ID, e.g., map ID 123.
add_filter('wpgmp_map_marker_spiderfier_settings', function($settings, $map) { if ($map->map_id == 123) { $settings['marker_spiderfy'] = 'true'; } return $settings; }, 10, 2);
Example 3
Change the spiderfy settings based on a custom field value associated with the map.
add_filter('wpgmp_map_marker_spiderfier_settings', function($settings, $map) { $custom_value = get_post_meta($map->map_id, 'custom_spiderfy_setting', true); if ($custom_value) { $settings['minimum_markers'] = $custom_value; } return $settings; }, 10, 2);
Remember to always back up your site before implementing new hooks or modifying existing ones. Test changes in a staging environment to ensure they work as expected without affecting live site functionality.