gmap.views.inc 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. /**
  3. * @file
  4. * GMap Views support.
  5. */
  6. /**
  7. * Gmap Extended View.
  8. *
  9. * @param array $vars
  10. * Array of used variables.
  11. *
  12. * @return mixed
  13. * Rendered HTML.
  14. */
  15. function theme_gmap_views_view_gmapextended(&$vars) {
  16. $markers = array();
  17. foreach ($vars['markers'] as $offset => $data) {
  18. if (empty($data['latitude']) || empty($data['longitude'])) {
  19. continue;
  20. }
  21. $markers[] = $data;
  22. }
  23. // @@@ Move to preprocess.
  24. $map = gmap_parse_macro($vars['options']['macro']);
  25. // If center lon/lat are not empty they are used to center map.
  26. if (!empty($vars['center']['longitude']) && !empty($vars['center']['latitude'])) {
  27. $map['longitude'] = $vars['center']['longitude'];
  28. $map['latitude'] = $vars['center']['latitude'];
  29. }
  30. if (!empty($vars['options']['iwq'])) {
  31. $map['iwq'] = $vars['options']['iwq'];
  32. }
  33. $map['markers'] = $markers;
  34. $elem = array(
  35. '#type' => 'gmap',
  36. '#gmap_settings' => $map,
  37. );
  38. return drupal_render($elem);
  39. }
  40. /**
  41. * Implements template_preprocess_views_view_VIEW_NAME().
  42. *
  43. * @param array $vars
  44. * Array of used variables.
  45. */
  46. function template_preprocess_gmap_views_view_gmapextended(&$vars) {
  47. $view = $vars['view'];
  48. // We need the raw data for this
  49. // grouping, which is passed in as $vars['rows'].
  50. // However, the template also needs to use for the rendered fields. We
  51. // therefore swap the raw data out to a new variable and reset $vars['rows']
  52. // so that it can get rebuilt.
  53. // Store rows so that they may be used by further preprocess functions.
  54. $result = $vars['result'] = $vars['rows'];
  55. $vars['rows'] = array();
  56. $options = $view->style_plugin->options;
  57. $handler = $view->style_plugin;
  58. $fields = &$view->field;
  59. if ($view->style_plugin->options['center_on_proximityfilter'] && $view->style_plugin->options['datasource'] == 'location' && module_exists('location')) {
  60. $vars['center'] = location_views_proximity_get_reference_location($view, array(
  61. 'origin' => 'tied',
  62. 'relationship' => $view->style_plugin->options['center_on_proximityfilter_rel'],
  63. ));
  64. }
  65. // Render fields.
  66. $renders = $handler->render_fields($result);
  67. $markers = array();
  68. // File away fields into the marker data.
  69. foreach ($renders as $i => $row) {
  70. $markers[$i] = $options['fallback_values'];
  71. foreach ($options['field_purposes'] as $field => $purpose) {
  72. if (!isset($markers[$i][$purpose])) {
  73. $markers[$i][$purpose] = '';
  74. }
  75. if ($purpose) {
  76. $markers[$i][$purpose] .= $row[$field];
  77. }
  78. }
  79. }
  80. foreach ($markers as $offset => $marker) {
  81. // Set up 'opts' array to make tooltips work.
  82. $markers[$offset]['opts'] = array('title' => isset($marker['title']) ? decode_entities($marker['title']) : NULL);
  83. switch ($options['clickmode']) {
  84. case 'render':
  85. $markers[$offset]['text'] = $vars['result'][$offset];
  86. // Fallthrough.
  87. case 'text':
  88. unset ($markers[$offset]['link']);
  89. unset ($markers[$offset]['rmt']);
  90. unset ($markers[$offset]['iwq']);
  91. unset ($markers[$offset]['iwo']);
  92. break;
  93. case 'rmt':
  94. unset ($markers[$offset]['text']);
  95. unset ($markers[$offset]['link']);
  96. unset ($markers[$offset]['iwq']);
  97. unset ($markers[$offset]['iwo']);
  98. break;
  99. case 'link':
  100. unset ($markers[$offset]['text']);
  101. unset ($markers[$offset]['rmt']);
  102. unset ($markers[$offset]['iwq']);
  103. unset ($markers[$offset]['iwo']);
  104. break;
  105. case 'iwq':
  106. // @@@ May need to parse entities for stuff like .foo>.bar.
  107. $markers[$offset]['iwq'] = trim($markers[$offset]['iwq']);
  108. $markers[$offset]['iwo'] = (int) trim($markers[$offset]['iwo']);
  109. if (empty($markers[$offset]['iwq']) || $markers[$offset]['iwq'] == $options['iwq']) {
  110. unset($markers[$offset]['iwq']);
  111. }
  112. unset ($markers[$offset]['text']);
  113. unset ($markers[$offset]['link']);
  114. unset ($markers[$offset]['rmt']);
  115. break;
  116. }
  117. }
  118. // Marker cleanup.
  119. foreach ($markers as $offset => $marker) {
  120. $marker['latitude'] = isset($marker['latitude']) ? (float) $marker['latitude'] : NULL;
  121. $marker['longitude'] = isset($marker['longitude']) ? (float) $marker['longitude'] : NULL;
  122. }
  123. $vars['markers'] = $markers;
  124. }