Skip to main content

PDF for GravityView Hooks – gfpdf_gv_static_map_markers

Description​

Use this filter to change an entry's markers before its map is drawn. It runs once per entry, after the GravityView Maps add-on has worked out where the markers go. Common uses:

  • Supply coordinates for entries the add-on couldn't place, such as latitude and longitude saved in their own form fields.
  • Change an entry's marker icon, for example by status or category.
  • Keep an entry off the map by returning an empty array.

It runs for both kinds of map:

  • Entry Map field: the markers on that entry's map. An empty array means no map is drawn for the entry.
  • Multiple Entries Map widget: once for each entry in the PDF. An empty array leaves the entry off the shared map, and it's counted as missing in the caption.

Check the type of $field to target one of them. See Maps in PDFs to set up both.

Version​

This hook was introduced in PDF for GravityView 2.0.

Arguments​

The following arguments are passed to functions that use this hook:

$markers | array​

  • The entry's markers, as a list. Each marker is an array with these keys:
    • lat (float): latitude
    • long (float): longitude
    • icon_url (string): the marker image, or '' for Google's default pin
  • Coordinates are rounded to five decimal places (about a meter).
  • A custom icon must be a public https:// PNG, JPEG or GIF URL with no query string. Otherwise, the default pin is drawn (see Differences from the website map).
  • The default value is the markers the GravityView Maps add-on resolved for the entry. Entries without their own icon use the View's Default Pin Icon.

$view | \GV\View​

  • The View being rendered.

$entry | array​

  • The Gravity Forms entry the markers belong to.

$field | \GV\Field|\GV\Widget|null​

  • The Entry Map field being rendered, or the Multiple Entries Map widget when the markers are for the widget's shared map.

Usage​

Place entries using latitude and longitude saved in fields 12 and 13, when the add-on found no location for them:

add_filter( 'gfpdf_gv_static_map_markers', function( $markers, $view, $entry ) {
if ( ! empty( $markers ) || ! is_numeric( rgar( $entry, '12' ) ) || ! is_numeric( rgar( $entry, '13' ) ) ) {
return $markers;
}

return [
[
'lat' => (float) $entry['12'],
'long' => (float) $entry['13'],
'icon_url' => '',
],
];
}, 10, 3 );

Use a red pin for entries whose field 5 is "Urgent":

add_filter( 'gfpdf_gv_static_map_markers', function( $markers, $view, $entry ) {
if ( rgar( $entry, '5' ) !== 'Urgent' ) {
return $markers;
}

foreach ( $markers as &$marker ) {
$marker['icon_url'] = 'https://example.com/wp-content/uploads/pins/red.png';
}

return $markers;
}, 10, 3 );

Leave cancelled entries off the Multiple Entries Map widget, but still draw their Entry Map field:

add_filter( 'gfpdf_gv_static_map_markers', function( $markers, $view, $entry, $field ) {
if ( $field instanceof \GV\Widget && rgar( $entry, '7' ) === 'Cancelled' ) {
return [];
}

return $markers;
}, 10, 4 );

Source Code​

This filter is located in src/Pdf/Maps/StaticMapRenderer.php of the PDF for GravityView extension.