wpgmp_shapes - WP Maps Pro

15000+ live websites are using this google maps wordpress plugin.

wpgmp_shapes

The wpgmp_shapes hook in WP Maps Pro allows developers to customize the shapes displayed on Google Maps at runtime. This includes adding or removing shapes such as polygons, polylines, circles, and rectangles.

Usage

Developers can implement the wpgmp_shapes hook to modify the map data before it is rendered. This is useful for dynamically changing the map’s appearance based on user input or other conditions. The hook is typically used in the functions.php file of your theme or a custom plugin.

Example 1

Description of the first use-case: Adding a new polygon to the map.

add_filter('wpgmp_shapes', 'add_custom_polygon', 10, 3);
function add_custom_polygon($map_shapes, $map_data, $map_id) {
    $new_polygon = array(
        'cordinates' => array("35.6895,-139.6917", "35.6895,-140.6917", "36.6895,-140.6917"),
        'settings' => array(
            'stroke_color' => '#FF0000',
            'stroke_opacity' => '0.7',
            'stroke_weight' => '2',
            'fill_color' => '#FF0000',
            'fill_opacity' => '0.7'
        ),
        'events' => array(
            'url' => '',
            'message' => 'New polygon infowindow message'
        )
    );
    $map_shapes['polygons'][] = $new_polygon;
    return $map_shapes;
}

Example 2

Description of the second use-case: Removing all circles from the map.

add_filter('wpgmp_shapes', 'remove_all_circles', 10, 3);
function remove_all_circles($map_shapes, $map_data, $map_id) {
    $map_shapes['circles'] = array(); // Clear all circles
    return $map_shapes;
}

Example 3

Description of the third use-case: Modifying the message of a rectangle infowindow.

add_filter('wpgmp_shapes', 'update_rectangle_message', 10, 3);
function update_rectangle_message($map_shapes, $map_data, $map_id) {
    if (!empty($map_shapes['rectangles'])) {
        foreach ($map_shapes['rectangles'] as &$rectangle) {
            $rectangle['events']['message'] = 'Updated rectangle infowindow message';
        }
    }
    return $map_shapes;
}

Tip: Always validate and sanitize any user input used within the hook to prevent security vulnerabilities, especially when data is dynamically added to the map.

Install Plugin Now!

Buy this plugin exclusively on CodeCanyon! You’ll get free updates, full support, and if you’re not satisfied, we’ve got you covered with a 30-day money-back guarantee.