Static Map Model
The Static Map Model is used to generate Static Maps. Chaining together static map methods is very similar to chaining dynamic map methods.
# Public Properties
# id
string - The map's unique ID. Can be set manually or generated automatically.
# Public Methods
# __construct($locations = [], $options = [])
This method will be called when a new StaticMap
is initialized. It creates a starting point which sets the map-building chain in motion. You will be able to build upon the map by adding markers, paths, etc.
The "map" variable
For each of the remaining examples on this page, the map
variable will be an instance of a Static Map Model. In each example, you will see how map methods can be chained at will.
It will be assumed that the map
object has already been initialized, as demonstrated above.
Once you have the map object in hand, you can then chain other methods to further customize the map. There is no limit as to how many methods you can chain, nor what order they should be in.
Arguments
$locations
(mixed) - See a description of acceptable locations...$options
(array) - Optional parameters to configure the map. (see below)
# Static Map Options
Option | Type | Default | Description |
---|---|---|---|
id | string | "map-{random}" | Set the id attribute of the map container. |
width | int | 640 | Width of the map, in pixels. (max 640 ) |
height | int | 320 | Height of the map, in pixels. (max 640 ) |
attr | array | null | Additional attributes for the <img> tag. |
zoom | int | (automatic) | Set the default zoom level of the map. (1 -22 ) |
center | coords|string | (automatic) | Center the map. |
styles | array | null | An array of map styles. |
scale | int | 2 | Pixel density of image. (standard = 1 , retina = 2 ) |
format | string | png | Type of image format (opens new window). |
maptype | string | roadmap | Type of map format (opens new window). |
language | string | (automatic) | Language for location labels. |
region | string | null | Adjusts map based on geo-political sensitivities. |
visible | coords|string|array | null | Ensures that the specified point(s) remain visible. |
markerOptions | array | null | Allows any properties accepted by the markers method. (see below) |
# markers($locations, $options = [])
Append markers to an existing map object.
Arguments
$locations
(mixed) - See a description of acceptable locations...$options
(array) - Optional parameters to configure the markers. (see below)
Option | Type | Default | Description |
---|---|---|---|
color | string | null | A hex code or predefined color (opens new window). |
label | string | null | A single uppercase alphanumeric character from the set {A-Z, 0-9} . |
icon | string | null | URL of the marker icon. |
anchor | string | "bottom" | Set as x,y coordinates or a predefined alignment (opens new window). |
size | string | (largest) | Make generic marker icons smaller. (mid , small , tiny ) |
scale | int | 1 | Make custom marker icons smaller. (1 ,2 ,4 ) |
field | string|array | null | Address field(s) to be included on the map. (includes all by default) |
Returns
- self - A chainable self-reference to this
StaticMap
object.
# path($points, $options = [])
Draw a path on an existing map object.
Arguments
$points
(mixed) - See a description of acceptable locations...$options
(array) - Optional parameters to configure the path. (see below)
Option | Type | Default | Description |
---|---|---|---|
weight | int | 5 | Thickness of the path in pixels. |
color | string | null | The line color (opens new window). |
fillcolor | string | null | The fill color (opens new window). |
geodesic | bool | false | Whether the path should be interpreted as a geodesic line. |
field | string|array | null | Address field(s) to be included on the map. (includes all by default) |
Returns
- self - A chainable self-reference to this
StaticMap
object.
# styles($styleSet)
Style a map based on a given array of styles.
Generating Styles
For more information on how to generate a set of styles, read Styling a Map.
Arguments
$styleSet
(array) - A set of styles to be applied to the map.
Returns
- self - A chainable self-reference to this
StaticMap
object.
# zoom($level)
Set the map's zoom level.
Arguments
$level
(int) - The zoom level. Must be an integer between1
-22
.
Returns
- self - A chainable self-reference to this
StaticMap
object.
# center($coords)
Center the map.
Arguments
$coords
(coords|string) - A key-value set of coordinates, or a comma-separated string value. You can also specify the name of a location to be geocoded (ie:New York, NY
).
Returns
- self - A chainable self-reference to this
StaticMap
object.
# tag()
Renders a fully-compiled <img>
tag using the final src
output. (see the src
method below)
Returns
- Markup - A Twig Markup instance, ready to be rendered via curly braces.
See also
Internally, the tag
method relies directly on the src
method below.
# src()
Compiles the raw src
attribute value to be used in a corresponding <img>
tag.
Returns
- string - A string URL of the remote static map source. The Google Maps Static API parses the parameters of this URL to properly compile and display the final map image.
# getDna()
Get the complete map DNA.
Aliased as dna
property via magic method.
Returns
- array - An array of data containing the complete map details.