A GMap array is used to define and render a map inside PHP code. This is useful for things like creating a map based on a database query, or doing things that you can't do with a macro.
Defaults for map attributes can be set on the GMap settings page.
These are all of the (by default) recognized keys for a map array. You usually will only use a subset of them.
$map = array(
'id' => // "Map ID" -- used to associate a map with other controls.
'width' => // Map width as a CSS dimension.
'height' => // Map height as a CSS dimension (usually px).
'latitude' => // Map center latitude.
'longitude' => // Map center longitude.
'zoom' => // Zoom level.
'maxzoom' => // Maximum zoom level for autozoom.
'extent => // Map bounds.
'maptype' => // Initial baselayer type.
'controltype' => // Size of map controls.
'align' => // CSS alignment for map div.
'mtc' => // Map type control.
'baselayers' => array(), // Enabled map baselayers.
'styles' => array(), // Shape style definitions.
'behavior' => array(), // Various map behavior flags.
'rmtcallback' => // Remote callback for ahah info windows.
'markers' => array(), // Array of markers to place on the map.
'shapes' => array(), // Array of shapes to place on the map.
);
Here is a description of the top level keys of the map array.
array(
'line_default' => array('0000ff',5,45,'',0,0),
'poly_default' => array('000000',3,25,'ff0000',45),
'green' => array('00ff00', 5, 100)
);
There are several behavior flags recognized by gmap.module, and other modules may choose to add their own behavior flags as well.
All behavior flags recognized are documented on the GMap settings page.
Core behavior flags:
array(
array(
'options' => array(),
'text' => 'start',
'longitude' => 12.196,
'latitude' => -58.13,
'markername' => 'route',
'offset' => 0,
),
array(
'options' => array(),
'text' => 'finish',
'longitude' => 12.196,
'latitude' => -58.523,
'markername' => 'route',
'offset' => 1,
),
);
There are three types of overlays you can place on a map: markers, shapes, and feeds. Each of these classes is represented by a sub-array in the GMap array.
This is not the only way to put markers on the map. It is, however, the easiest way. The markers specified here are loaded through the "static marker loader."
You can also set arbitrary keys in the array. They will be passed to the javascript side automatically.
An array of shapes to place on the map.
The format of the shape arrays depends on the type.
array(
array(
'type' => 'line',
'points' => array(
array(0.000, 0.000), // First point.
array(0.000, 0.000), // Second point.
array(0.000, 0.000), // Third point.
),
'style' => array("00ff00", 5, 80),
)
array(
'type' => 'polygon',
'points' => array(
array(0.000, 0.000), // First point.
array(0.000, 0.000), // Second point.
array(0.000, 0.000), // Third point.
),
'style' => array("ff0000", 5, 80, "00ff00", 60),
),
array(
'type' => 'circle',
'center' => array(0.000, 0.000), // Center coordinate of the circle.
'radius' => 100, // Radius of the circle in kilometers.
'style' => array(), // Style to use.
),
array(
'type' => 'rpolygon',
'center' => array(0.000, 0.000), // Center coordinate of the regular polygon.
'numpoints' => 4, // Number of vertices the polygon should have.
'point2' => array(0.000, 0.000), // One of the vertex coordinates.
'style' => array(), // Style to use.
),
array(
'type' => 'encoded_line',
'points' => 'icx~FfigvOt~CsnB~Vo`G~aDqnBp`@chB', // a series of points, encoded
'levels' => 'BBBBB', // zoom level for each point, encoded
'numLevels' => 18, // derived from the encoding algorithm
'zoomFactor' => 2, // derived from the encoding algorithm
'style' => array(),
),
array(
'type' => 'encoded_polygon',
'polylines' => array(
array(
'points' => 's{r~FnwcvO`zB{qHa}Fa`E~aC|rN',
'levels' => 'BBBB',
'numLevels' => 18,
'zoomFactor' => 2,
),
),
'style' => array(),
),
);
For both encoded_line and encoded_polyline, the 'points', 'levels', 'numLevels', and 'zoomFactor' should be generated using the gmap_polyutil_polyline() function in gmap_polyutil.inc. To use this, pass an array of points into the function:
$points = array( array(41.90625, -87.67634), array(41.91226, -87.65643), array(41.91021, -87.65059), array(41.90753, -87.64956), ); $gmap_encoding = gmap_polyutil_polyline($points);
results in:
Array
(
[points] => ayw~FbhcvOqd@m{BxKoc@vOmE
[levels] => PGFP
[numLevels] => 18
[zoomFactor] => 2
)
There are three types of overlays you can place on a map by default: markers, shapes, and feeds. Each of these classes is represented by a sub-array in the GMap array. Addon modules can add more types of overlays.
Markers are point features on a map. They are placed somewhere on the globe and can optionally be programmed to show an information window when clicked.
Any additional keys / values you put in a marker array will be passed to the javascript side automatically. This is very useful when writing custom code.
$marker = array(
'latitude' => 0.000, // Marker latitude.
'longitude' => 0.000, // Marker longitude.
'markername' => 'smileyface', // Name of marker set to use.
'offset' => 0, // Offset in marker set.
'text' => 'popup text', // GInfoWindow contents.
'tabs' => array(), // Tabbed GInfoWindow contents.
'link' => 'http://google.com', // Use marker as hyperlink.
'rmt' => '', // Argument to pass for rmt
'opts' => array(), // Use custom GMarkerOptions.
'options' => array(), // Misc. behavior modifications.
);
Here is a description of the keys of a marker array.
The code will automatically wrap around if you simply increment offset every marker.
You do not need to know how many icons are actually assigned to the marker set.
This will set up an info window popup when you click the marker.
If you specify as a string, it will make a regular GInfoWindow.
If you specify as an array, it will make a tabbed GInfoWindow, where the array keys are the tab titles, and the array values are the contents of the tabs.
array(
'Name' => '<em>United States</em>',
'Currency' => 'United States Dollar',
);
Filling out this parameter will allow you to override the GMarkerOptions that a marker is initialized with.
The icon key is automatically filled in, you can't set it here.
array(
'bouncy' => TRUE,
);
array('autoclick');
Shapes are the non point features on the map.
$shape = array(
'type' => '',
'points' => array(),
'center' => array(0,0),
'radius' => 0,
'point2' => array(0,0),
'numpoints' => 10,
'style' => array(),
);
An array of points defining the shape.
Used by the line and polygon types.
array(
array(44.205835001, -70.3674316406),
array(44.3159879052, -68.6096191406),
),
Each point itself is an array with two elements (latitude, longitude). The different shapes have different requirements with respect to points.
"line" must have at least two points. It is best to break up long lines into shorter segments, because long lines can be buggy--sometimes beginning and ending points are switched.
"polygon" should have at least three points; the first and last points should have the same coordinates.
The radius of the circle, in km.
Only used for the circle type.
The coordinate of a vertex on the rim of the rpolygon.
Only used for the rpolygon type.
Sets the number of points used to draw the circle or rpolygon.
Only used for the circle and rpolygon types.
A style array, or a key to the styles array on the map.
This is the same format used for the map level styles array.
The elements of this array MUST be in the specified order.
Stroke and fill colors should be hex color codes (without the leading "#"); Google Maps does not accept named colors.
The stroke weight is the width of the line or polygon border in pixels.
Stroke and fill opacities should be a percentage between 0 and 100.
Fill color and fill opacity are not used for type "line".
If shapes of type "line" don't have styles defined, the 'line_default' style will be used; shapes of type "polygon", "circle", and "rpolygon" will use 'poly_defalt'.
In previous versions of GMap (Specifically, all Drupal 4.6 and 4.7 versions), opacity was specified as a number between 0 and 1. It is now a number between 0 and 100.
On backwards compatibility: there were originally more style options, but they were dependant on xmaps; xmaps is no longer compatible with Google Maps, so these options are now ignored. They are: 'pattern', 'text', 'fillcolor', 'fillopacity'; all except for 'pattern' are now available with different syntax.
$map = array(...); // Set up your map array.
$output = theme('gmap', array('#settings' => $map));