This hook in WP Maps Pro allows developers to customize the map’s panning behavior at runtime. It is triggered when the map’s panning functionality is about to be processed, providing an opportunity to modify the default panning constraints.
Usage
Developers can implement this hook in their theme’s functions.php
file or a custom plugin to adjust the panning limits of a map. This is particularly useful when specific control over the map’s navigable area is needed, such as restricting user movement to a particular region.
Example 1
Modify the map to restrict panning to a more narrow area.
add_filter('wpgmp_map_panning', 'custom_map_panning_restrictions', 10, 2); function custom_map_panning_restrictions($panning_control, $map) { $panning_control['from_latitude'] = '10.0'; $panning_control['from_longitude'] = '10.0'; $panning_control['to_latitude'] = '40.0'; $panning_control['to_longitude'] = '40.0'; return $panning_control; }
Example 2
Allow the map to pan freely without any restrictions.
add_filter('wpgmp_map_panning', 'remove_map_panning_restrictions', 10, 2); function remove_map_panning_restrictions($panning_control, $map) { return array(); // Empty array to remove all panning limits. }
Example 3
Set custom panning limits based on conditions, such as user roles.
add_filter('wpgmp_map_panning', 'conditional_map_panning', 10, 2); function conditional_map_panning($panning_control, $map) { if(current_user_can('administrator')) { // Allow admin users more freedom in panning $panning_control['from_latitude'] = '0.0'; $panning_control['to_latitude'] = '50.0'; } else { // Restrict panning for other users $panning_control['from_latitude'] = '20.0'; $panning_control['to_latitude'] = '30.0'; } return $panning_control; }
Tip: Always validate user inputs and conditions when modifying map behavior with hooks to ensure a secure and user-friendly experience.