This repository has been archived by the owner on May 6, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
google-map.php
76 lines (59 loc) · 2.21 KB
/
google-map.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
/**
* Implements hook_preprocess_HOOK().
*
* - Preprocess the styled google map view template.
*/
function gov_subtheme_preprocess_views_view(&$vars) {
$view = &$vars['view'];
// Make sure it's the correct view
if ($view->name == 'health_security_corps_map_block' || $view->name == 'health_system_research_organisation_map' || $view->name == 'national_regulators_block' || $view->name == 'where_we_work' ) {
drupal_add_js('//maps.google.com/maps/api/js?sensor=true', array('type' => 'external', 'group' => JS_LIBRARY));
// add needed javascript
drupal_add_js(drupal_get_path('theme', 'gov_subtheme') . '/js/google-map.js');
drupal_add_js(drupal_get_path('theme', 'gov_subtheme') . '/js/infobubble.js');
$locations = array();
foreach ($vars['view']->result as $row) {
$location = array();
if ( isset($row->field_field_location_latitude) && isset( $row->field_field_location_longitude) ) {
// Add geofield data.
$location = $location + array( 'location' => array( 'latitude' => $row->field_field_location_latitude[0]['raw']['value'], 'longitude' => $row->field_field_location_longitude[0]['raw']['value'] )
);
// Add pin image url.
if (isset($row->field_field_map_pin_image)) {
$location = $location + array(
'pin' => file_create_url($row->field_field_map_pin_image[0]['raw']['uri'])
);
}
// Add pin popup html.
if (isset($row->node_title) ) {
$vars['view']->row_index = 0; // TODO: Check why this is necessary.
$location = $location + array(
// 'popup' => $row->node_title,
'popup' => $vars['view']->field['title']->theme($row)
);
}
}
if ($location) {
$locations[] = $location;
}
}
$map_settings['gov_google_map'][] = array('gov-google-map');
$map_settings['idgov-google-map'] = array(
'id' => 'gov-google-map',
'locations' => $locations,
'style' => '[
{
"stylers": [
{ "gamma": 1.03 },
{ "weight": 1.2 },
{ "hue": "#00b2ff" },
{ "saturation": -28 },
{ "lightness": 10 }
]
}
]',
);
drupal_add_js($map_settings, 'setting');
}
}