PDF for GravityView Hooks – gfpdf_gv_static_map_size
Description
Changes the pixel size of the map image requested from Google. By default the size comes from the PDF Map Layout setting on the Entry Map field or Multiple Entries Map widget, and from where the map sits:
| PDF Map Layout | Single Entry PDF, or the Multiple Entries Map widget | Entry Map field in a Multiple Entries PDF row |
|---|---|---|
| Square | 640x640 | 400x400 |
| Landscape | 640x400 | 400x250 |
| Portrait | 400x640 | 250x400 |
The layout setting is described in Maps in PDFs.
In Google's Static Maps API, size sets how much of the map is shown. At the same zoom level, a bigger size shows more of the surrounding area. It doesn't make the map sharper. If a map looks soft in your PDF, use gfpdf_gv_static_map_scale instead.
The printed width comes from the column the map sits in, so changing the ratio of width to height changes the map's printed shape, up to the height limit.
Version
This hook was introduced in PDF for GravityView 2.0.
Arguments
The following arguments are passed to functions that use this hook:
$size | string
- The size to request, as
WIDTHxHEIGHTin pixels, for example640x400. - Google's maximum is 640 on either side, so larger values are reduced to 640.
- A value not in the
WIDTHxHEIGHTformat is ignored and the default is used. - The default value depends on the layout and shape, as shown in the table above.
$view | \GV\View
- The View being rendered.
$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
Make the Multiple Entries Map widget and Single Entry PDF maps a wide banner, regardless of the layout setting:
add_filter( 'gfpdf_gv_static_map_size', function( $size, $view, $shape ) {
return $shape === 'document' ? '640x300' : $size;
}, 10, 3 );
Show a tighter area around each entry in a directory PDF's rows:
add_filter( 'gfpdf_gv_static_map_size', function( $size, $view, $shape ) {
return $shape === 'row' ? '300x300' : $size;
}, 10, 3 );
Source Code
This filter is located in src/Pdf/Maps/StaticMapRenderer.php of the PDF for GravityView extension.