Browse Source

Add absolute urls to embedded map

The embedded map /map now provides absolute urls for group pages instead
of relative ones. The map marker's title contains plain text, and the
click event on marker icon redirects to group page directly instead of
showing a balloon popup.

Change-Id: Ib4c1e35b20bc287b275b072e65369de18e574b7b
tags/0.48^0
Marton Kiss 1 year ago
parent
commit
7f67c8b9c1

+ 9
- 0
modules/groups/groups_directory/groups_directory.module View File

@@ -184,4 +184,13 @@ function groups_directory_filter_form_submit($form, &$form_state) {
184 184
 function groups_directory_filter_form_clear_filters($form, &$form_state) {
185 185
   $path=$GLOBALS['base_url'].strtok($_SERVER["REQUEST_URI"],'?');
186 186
   drupal_goto($path);
187
+}
188
+
189
+/**
190
+ * Implements hook_leaflet_map_prebuild_alter()
191
+ *
192
+ * Add custom map js to override marker hover and popup balloon behavior.
193
+ */
194
+function groups_directory_leaflet_map_prebuild_alter(&$vars) {
195
+  drupal_add_js(drupal_get_path('module', 'groups_directory') . '/js/groups_directory_map.js');
187 196
 }

+ 11
- 1
modules/groups/groups_directory/groups_directory.views_default.inc View File

@@ -105,7 +105,7 @@ function groups_directory_views_default_views() {
105 105
   $handler->display->display_options['style_plugin'] = 'leaflet';
106 106
   $handler->display->display_options['style_options']['data_source'] = 'field_geofield';
107 107
   $handler->display->display_options['style_options']['name_field'] = 'title';
108
-  $handler->display->display_options['style_options']['description_field'] = '#rendered_entity';
108
+  $handler->display->display_options['style_options']['description_field'] = 'path';
109 109
   $handler->display->display_options['style_options']['view_mode'] = 'teaser';
110 110
   $handler->display->display_options['style_options']['map'] = 'leaflet-mapbox';
111 111
   /* Field: Content: Title */
@@ -115,6 +115,7 @@ function groups_directory_views_default_views() {
115 115
   $handler->display->display_options['fields']['title']['label'] = '';
116 116
   $handler->display->display_options['fields']['title']['alter']['word_boundary'] = FALSE;
117 117
   $handler->display->display_options['fields']['title']['alter']['ellipsis'] = FALSE;
118
+  $handler->display->display_options['fields']['title']['link_to_node'] = FALSE;
118 119
   /* Field: Content: geofield */
119 120
   $handler->display->display_options['fields']['field_geofield']['id'] = 'field_geofield';
120 121
   $handler->display->display_options['fields']['field_geofield']['table'] = 'field_data_field_geofield';
@@ -125,6 +126,15 @@ function groups_directory_views_default_views() {
125 126
   $handler->display->display_options['fields']['field_geofield']['settings'] = array(
126 127
     'data' => 'full',
127 128
   );
129
+  /* Field: Content: Path */
130
+  $handler->display->display_options['fields']['path']['id'] = 'path';
131
+  $handler->display->display_options['fields']['path']['table'] = 'node';
132
+  $handler->display->display_options['fields']['path']['field'] = 'path';
133
+  $handler->display->display_options['fields']['path']['label'] = '';
134
+  $handler->display->display_options['fields']['path']['alter']['alter_text'] = TRUE;
135
+  $handler->display->display_options['fields']['path']['alter']['text'] = '[path]';
136
+  $handler->display->display_options['fields']['path']['element_label_colon'] = FALSE;
137
+  $handler->display->display_options['fields']['path']['absolute'] = TRUE;
128 138
   /* Filter criterion: Content: Published */
129 139
   $handler->display->display_options['filters']['status']['id'] = 'status';
130 140
   $handler->display->display_options['filters']['status']['table'] = 'node';

+ 28
- 0
modules/groups/groups_directory/js/groups_directory_map.js View File

@@ -0,0 +1,28 @@
1
+(function ($) {
2
+
3
+  /**
4
+   * For leafleat API docs, see:
5
+   * http://leafletjs.com/reference.html
6
+   **/
7
+
8
+  var cnt = 0;
9
+  // Attach to Leaflet object via its API
10
+  $(document).bind('leaflet.feature', function(e, lFeature, feature) {
11
+    // Remove default click event (infoWindow Popup) and add our own
12
+    if (feature.label) {
13
+      var contents = feature.contents;
14
+      lFeature.on('click', function() {
15
+        var img = $(lFeature._icon);
16
+        img.addClass('active').siblings().removeClass('active');
17
+        redirectMarkerURL(feature);
18
+      });
19
+      lFeature.unbindPopup();
20
+      cnt++;
21
+    }
22
+  });
23
+
24
+  function redirectMarkerURL(marker) {
25
+    window.top.location.href = marker.popup;
26
+  }
27
+
28
+})(jQuery);

Loading…
Cancel
Save