function gm3_get_map in Google Maps API V3 7
Function to return a renderable array for a map.
2 calls to gm3_get_map()
- gm3_field_field_formatter_view in gm3_field/
gm3_field.module - Implements hook_field_formatter_view().
- theme_gm3_map in ./
gm3.theme.inc - Simple theme function
File
- ./
gm3.theme.inc, line 14
Code
function gm3_get_map($variables) {
// No need to use drupal_static here!
static $info = array();
if (!isset($variables['map']['id'])) {
// Could we get this dynamically from hook_theme?
$variables['map']['id'] = 'gm3-map';
}
if (isset($variables['map']['libraries']['point']['convexhull']) && $variables['map']['libraries']['point']['convexhull']) {
// We need to add a convex hull polygon. Lets do so.
if (gm3_load_geophp()) {
$points = array();
foreach ($variables['map']['libraries']['point']['points'] as $point) {
$points[] = new Point($point['latitude'], $point['longitude']);
}
$multipoint = new MultiPoint($points);
$convexhull = json_decode(@$multipoint
->convexHull()
->out('json'));
$poly = array();
foreach ($convexhull->coordinates[0] as $latlng) {
$poly[] = array(
$latlng[1],
// WHY OH WHY is this the reverse order of what we expect?
$latlng[0],
);
}
$variables['map']['libraries']['polygon']['polygons'][] = array(
'polygon' => $poly,
'editable' => FALSE,
'content' => t('Convex hull for the points within it.'),
);
}
}
if (isset($info[$variables['map']['id']])) {
// this map has already been initialized.
// We can alter settings for the map, but won't be able to add any tools
// to the map. This won't be a problem for viewing a map, but may be an
// issue for editing.
drupal_add_js(array(
'gm3' => array(
'maps' => array(
$variables['map']['id'] => array(
'libraries' => $variables['map']['libraries'],
),
),
),
), 'setting');
return FALSE;
}
else {
$info[$variables['map']['id']] = TRUE;
gm3_add($variables['map']);
$tools = '';
if (isset($variables['map']['tools'])) {
$tools = '<div class="gm3-tools"><ul id="toolbar-' . $variables['map']['id'] . '"><li class="gm3-clicked"><div data-gm3-class="default" class="gm3-tools-button"><p>' . t('Move') . '</p></div></li><li>' . implode("</li><li>", $variables['map']['tools']) . '</li></ul></div>';
}
return array(
'#attached' => array(
'css' => array(
drupal_get_path('module', 'gm3') . '/css/gm3.css',
),
),
'#markup' => '<div class="gm3-container">' . $tools . '<div class="gm3-map-wrapper"><div id="' . $variables['map']['id'] . '"></div></div></div>',
);
}
}