From 7f67c8b9c15f90d3eca4a18c490592502f97e706 Mon Sep 17 00:00:00 2001 From: Marton Kiss Date: Tue, 1 Aug 2017 13:22:41 +0200 Subject: [PATCH] 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 --- .../groups_directory/groups_directory.module | 9 ++++++ .../groups_directory.views_default.inc | 12 +++++++- .../js/groups_directory_map.js | 28 +++++++++++++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 modules/groups/groups_directory/js/groups_directory_map.js diff --git a/modules/groups/groups_directory/groups_directory.module b/modules/groups/groups_directory/groups_directory.module index 7140e7a..8c655e2 100644 --- a/modules/groups/groups_directory/groups_directory.module +++ b/modules/groups/groups_directory/groups_directory.module @@ -184,4 +184,13 @@ function groups_directory_filter_form_submit($form, &$form_state) { function groups_directory_filter_form_clear_filters($form, &$form_state) { $path=$GLOBALS['base_url'].strtok($_SERVER["REQUEST_URI"],'?'); drupal_goto($path); +} + +/** + * Implements hook_leaflet_map_prebuild_alter() + * + * Add custom map js to override marker hover and popup balloon behavior. + */ +function groups_directory_leaflet_map_prebuild_alter(&$vars) { + drupal_add_js(drupal_get_path('module', 'groups_directory') . '/js/groups_directory_map.js'); } \ No newline at end of file diff --git a/modules/groups/groups_directory/groups_directory.views_default.inc b/modules/groups/groups_directory/groups_directory.views_default.inc index b0fb3aa..4c7432d 100644 --- a/modules/groups/groups_directory/groups_directory.views_default.inc +++ b/modules/groups/groups_directory/groups_directory.views_default.inc @@ -105,7 +105,7 @@ function groups_directory_views_default_views() { $handler->display->display_options['style_plugin'] = 'leaflet'; $handler->display->display_options['style_options']['data_source'] = 'field_geofield'; $handler->display->display_options['style_options']['name_field'] = 'title'; - $handler->display->display_options['style_options']['description_field'] = '#rendered_entity'; + $handler->display->display_options['style_options']['description_field'] = 'path'; $handler->display->display_options['style_options']['view_mode'] = 'teaser'; $handler->display->display_options['style_options']['map'] = 'leaflet-mapbox'; /* Field: Content: Title */ @@ -115,6 +115,7 @@ function groups_directory_views_default_views() { $handler->display->display_options['fields']['title']['label'] = ''; $handler->display->display_options['fields']['title']['alter']['word_boundary'] = FALSE; $handler->display->display_options['fields']['title']['alter']['ellipsis'] = FALSE; + $handler->display->display_options['fields']['title']['link_to_node'] = FALSE; /* Field: Content: geofield */ $handler->display->display_options['fields']['field_geofield']['id'] = 'field_geofield'; $handler->display->display_options['fields']['field_geofield']['table'] = 'field_data_field_geofield'; @@ -125,6 +126,15 @@ function groups_directory_views_default_views() { $handler->display->display_options['fields']['field_geofield']['settings'] = array( 'data' => 'full', ); + /* Field: Content: Path */ + $handler->display->display_options['fields']['path']['id'] = 'path'; + $handler->display->display_options['fields']['path']['table'] = 'node'; + $handler->display->display_options['fields']['path']['field'] = 'path'; + $handler->display->display_options['fields']['path']['label'] = ''; + $handler->display->display_options['fields']['path']['alter']['alter_text'] = TRUE; + $handler->display->display_options['fields']['path']['alter']['text'] = '[path]'; + $handler->display->display_options['fields']['path']['element_label_colon'] = FALSE; + $handler->display->display_options['fields']['path']['absolute'] = TRUE; /* Filter criterion: Content: Published */ $handler->display->display_options['filters']['status']['id'] = 'status'; $handler->display->display_options['filters']['status']['table'] = 'node'; diff --git a/modules/groups/groups_directory/js/groups_directory_map.js b/modules/groups/groups_directory/js/groups_directory_map.js new file mode 100644 index 0000000..256d8dc --- /dev/null +++ b/modules/groups/groups_directory/js/groups_directory_map.js @@ -0,0 +1,28 @@ +(function ($) { + + /** + * For leafleat API docs, see: + * http://leafletjs.com/reference.html + **/ + + var cnt = 0; + // Attach to Leaflet object via its API + $(document).bind('leaflet.feature', function(e, lFeature, feature) { + // Remove default click event (infoWindow Popup) and add our own + if (feature.label) { + var contents = feature.contents; + lFeature.on('click', function() { + var img = $(lFeature._icon); + img.addClass('active').siblings().removeClass('active'); + redirectMarkerURL(feature); + }); + lFeature.unbindPopup(); + cnt++; + } + }); + + function redirectMarkerURL(marker) { + window.top.location.href = marker.popup; + } + +})(jQuery);