Skip to main content

PDF for GravityView Hooks – gfpdf_gv_static_map_viewport

Description​

Sets a fixed center, and optionally a zoom level, for a map in a PDF. Use it when every entry is in one region and you want each map to show the same area, or when the widget map zooms out further than you'd like.

By default a map frames its own markers. A map with one marker is centered on it at the View's zoom level. A map with several markers (the Multiple Entries Map widget) is fitted by Google so every marker is in view. A visitor's pan or zoom on the website map isn't carried over (see Differences from the website map).

Version​

This hook was introduced in PDF for GravityView 2.0.

Arguments​

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

$viewport | array|null​

  • Return null to keep the default framing.
  • Return [ 'lat' => float, 'lng' => float, 'zoom' => int|null ] to force a center. The key is lng, not long.
  • zoom runs from 0 (the whole world) to 21. Values outside that range are clamped. Set it to null to use the View's zoom level, or 15 if the View doesn't set one.
  • A latitude outside -90 to 90, a longitude outside -180 to 180, or a non-numeric value is ignored and the default framing is used.
  • The default value is null.

$view | \GV\View​

  • The View being rendered.

$entry | array​

  • The Gravity Forms entry the map is for.
  • An empty array for the Multiple Entries Map widget, which covers every entry in the PDF.

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

  • The Entry Map field being rendered, or the Multiple Entries Map widget.

$context | string​

  • Which PDF the map is in: single (Single Entry PDF) or directory (Multiple Entries PDF).

Usage​

Center the Multiple Entries Map widget on Melbourne at zoom level 10:

add_filter( 'gfpdf_gv_static_map_viewport', function( $viewport, $view, $entry, $field ) {
if ( $field instanceof \GV\Widget ) {
return [ 'lat' => -37.8136, 'lng' => 144.9631, 'zoom' => 10 ];
}

return $viewport;
}, 10, 4 );

Zoom out the map in one View's Single Entry PDF, centered on coordinates the form stores in fields 12 (latitude) and 13 (longitude):

add_filter( 'gfpdf_gv_static_map_viewport', function( $viewport, $view, $entry, $field, $context ) {
if ( $view->ID !== 885 || $context !== 'single' || empty( $entry['12'] ) || empty( $entry['13'] ) ) {
return $viewport;
}

return [ 'lat' => $entry['12'], 'lng' => $entry['13'], 'zoom' => 8 ];
}, 10, 5 );

Source Code​

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