Skip to main content

PDF for GravityView Hooks – gfpdf_gv_static_map_scale

Description​

Sets the resolution of the map images requested from Google. Use it when the maps in your Multiple Entries PDF look soft or pixelated next to the one in your Single Entry PDF.

Google's Static Maps API has a scale setting. At 1 you get an image at the requested size. At 2 you get the same map with twice the pixels on each side, which prints crisply. PDF for GravityView uses:

  • 2 for a map drawn once in a PDF: an Entry Map field in a Single Entry PDF, and the Multiple Entries Map widget.
  • 1 for an Entry Map field in the rows of a Multiple Entries PDF.

Rows default to 1 because scale 2 images are about 2.5 times larger, which slows long PDFs and increases file size.

Set rows to 2 when print quality matters more than speed. Each PDF will take longer to generate and be noticeably larger, and on a slow connection more maps may run out of time (see gfpdf_gv_static_map_timeout).

Version​

This hook was introduced in PDF for GravityView 2.0.

Arguments​

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

$scale | int​

  • 1 or 2. Any other value is treated as 2.
  • The default value is 1 for a directory row and 2 for every other map.

$context | string​

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

$shape | string​

  • row: an Entry Map field repeated down a Multiple Entries PDF.
  • document: a map drawn once, such as an Entry Map field in a Single Entry PDF or the Multiple Entries Map widget.

Usage​

Sharpen the maps in directory rows:

add_filter( 'gfpdf_gv_static_map_scale', function( $scale, $context, $shape ) {
return $shape === 'row' ? 2 : $scale;
}, 10, 3 );

Use single-resolution maps everywhere, for the smallest, fastest PDFs:

add_filter( 'gfpdf_gv_static_map_scale', function() {
return 1;
} );

Source Code​

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