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
This commit is contained in:
Marton Kiss 2017-08-01 13:22:41 +02:00
parent 49ccaea54f
commit 7f67c8b9c1
3 changed files with 48 additions and 1 deletions

View File

@ -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');
}

View File

@ -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';

View File

@ -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);