Skip to content
Snippets Groups Projects
Commit a9853550 authored by Reuben Turk's avatar Reuben Turk
Browse files

#679804 by srobert72 (some modifications by myself) - adds:

* Add Google Bar to search on map
* Add option for a marker tooltip field on gmap views
* Add option to highlight markers on mouse rollover event
* Add option to center Gmap on marker of node passed as argument in view
* Add option to highlight markers of node passed as argument in view
parent b2b2fa57
No related branches found
No related tags found
No related merge requests found
...@@ -32,3 +32,12 @@ ...@@ -32,3 +32,12 @@
/* Don't let long copyright texts stick out the side of the map div. */ /* Don't let long copyright texts stick out the side of the map div. */
overflow: hidden; overflow: hidden;
} }
/* Clean up unwanted styling for google toolbar */
.gmap-map .gmnoprint table {
margin: 0;
}
.gmap-map .gmnoprint tbody {
border-top: none;
}
...@@ -38,6 +38,7 @@ function gmap_defaults() { ...@@ -38,6 +38,7 @@ function gmap_defaults() {
'styles' => array( 'styles' => array(
'line_default' => array('0000ff', 5, 45, '', 0, 0), 'line_default' => array('0000ff', 5, 45, '', 0, 0),
'poly_default' => array('000000', 3, 25, 'ff0000', 45), 'poly_default' => array('000000', 3, 25, 'ff0000', 45),
'highlight_color' => 'ff0000',
), ),
'line_colors' => array('#00cc00', '#ff0000', '#0000ff'), 'line_colors' => array('#00cc00', '#ff0000', '#0000ff'),
); );
...@@ -119,6 +120,7 @@ function gmap_gmap($op, &$map) { ...@@ -119,6 +120,7 @@ function gmap_gmap($op, &$map) {
drupal_add_js($path . 'icon.js'); drupal_add_js($path . 'icon.js');
drupal_add_js($path . 'marker.js'); drupal_add_js($path . 'marker.js');
drupal_add_js($path .'highlight.js');
$mm = variable_get('gmap_mm_type', 'gmap'); $mm = variable_get('gmap_mm_type', 'gmap');
// If you really really want to override the marker manager, implement // If you really really want to override the marker manager, implement
...@@ -220,6 +222,18 @@ function gmap_gmap($op, &$map) { ...@@ -220,6 +222,18 @@ function gmap_gmap($op, &$map) {
'help' => t('Used for advanced javascript work, this will enable the <em>clickshape</em> event.'), 'help' => t('Used for advanced javascript work, this will enable the <em>clickshape</em> event.'),
'internal' => TRUE, 'internal' => TRUE,
), ),
'googlebar' => array(
'title' => t('Enable Google Bar'),
'default' => FALSE,
'help' => t('Enable the "Google Bar" at bottom of the map.'),
'previewable' => TRUE,
),
'highlight' => array(
'title' => t('Highlight marker on rollover'),
'default' => FALSE,
'help' => t('Highlight marker by creating circle on mouse rollover event.'),
'previewable' => TRUE,
),
); );
break; break;
...@@ -279,6 +293,7 @@ function _gmap_doheader() { ...@@ -279,6 +293,7 @@ function _gmap_doheader() {
drupal_add_js($gmap_path . '/thirdparty/' . $mms[$mm]['filename']); drupal_add_js($gmap_path . '/thirdparty/' . $mms[$mm]['filename']);
} }
drupal_add_js($gmap_path . '/js/marker.js'); drupal_add_js($gmap_path . '/js/marker.js');
drupal_add_js($gmap_path . '/js/highlight.js');
drupal_add_js($gmap_path . '/js/' . $mm . '_marker.js'); drupal_add_js($gmap_path . '/js/' . $mm . '_marker.js');
drupal_add_js(array('gmap_markermanager' => $mms[$mm]), 'setting'); drupal_add_js(array('gmap_markermanager' => $mms[$mm]), 'setting');
// @@@ // @@@
......
...@@ -33,6 +33,16 @@ class gmap_plugin_style_gmap extends views_plugin_style { ...@@ -33,6 +33,16 @@ class gmap_plugin_style_gmap extends views_plugin_style {
$options['lonfield'] = array('default' => ''); $options['lonfield'] = array('default' => '');
$options['markerfield'] = array('default' => ''); $options['markerfield'] = array('default' => '');
$options['center_on_nodearg'] = array('default' => 0);
$options['center_on_nodearg_arg'] = array('default' => '');
$options['highlight_nodearg'] = array('default' => 0);
$options['highlight_nodearg_arg'] = array('default' => '');
$options['highlight_nodearg_color'] = array('default' => '#FF0000');
$options['tooltipenabled'] = array('default' => 0);
$options['tooltipfield'] = array('default' => '');
return $options; return $options;
} }
...@@ -81,11 +91,16 @@ class gmap_plugin_style_gmap extends views_plugin_style { ...@@ -81,11 +91,16 @@ class gmap_plugin_style_gmap extends views_plugin_style {
if ($this->options['datasource'] == 'fields') { if ($this->options['datasource'] == 'fields') {
$lat_fied_obj = $this->view->display_handler->get_handler('field', $this->options['latfield']); $lat_fied_obj = $this->view->display_handler->get_handler('field', $this->options['latfield']);
$lon_field_obj = $this->view->display_handler->get_handler('field', $this->options['lonfield']); $lon_field_obj = $this->view->display_handler->get_handler('field', $this->options['lonfield']);
$lat_field = $lat_fied_obj->field_alias; $lat_field = $lat_fied_obj->field_alias;
$lon_field = $lon_field_obj->field_alias; $lon_field = $lon_field_obj->field_alias;
} }
$tooltip_field = '';
if ($this->options['tooltipenabled']) {
$tooltip_field_obj = $this->view->display_handler->get_handler('field', $this->options['tooltipfield']);
$tooltip_field = $tooltip_field_obj->field_alias;
}
// Determine fieldname for marker field. // Determine fieldname for marker field.
if ($this->options['markers'] == 'field') { if ($this->options['markers'] == 'field') {
$marker_field_obj = $this->view->display_handler->get_handler('field', $this->options['markerfield']); $marker_field_obj = $this->view->display_handler->get_handler('field', $this->options['markerfield']);
...@@ -111,10 +126,31 @@ class gmap_plugin_style_gmap extends views_plugin_style { ...@@ -111,10 +126,31 @@ class gmap_plugin_style_gmap extends views_plugin_style {
foreach ($sets as $title => $records) { foreach ($sets as $title => $records) {
$markers = array(); $markers = array();
$offsets = array(); $offsets = array();
$center_lat = null;
$center_lon = null;
$center_nid = null;
$highlight_nid = null;
// We search nid argument used to center map
if ($this->options['center_on_nodearg'] && $nodehandler = $this->view->display_handler->get_handler('argument', $this->options['center_on_nodearg_arg'])) {
$center_nid = $nodehandler->get_value();
}
if ($this->options['highlight_nodearg'] && $nodehandler = $this->view->display_handler->get_handler('argument', $this->options['highlight_nodearg_arg'])) {
$highlight_nid = $nodehandler->get_value();
}
foreach ($records as $row_index => $row) { foreach ($records as $row_index => $row) {
$this->view->row_index = $row_index; $this->view->row_index = $row_index;
$lat = (float)$row->{$lat_field}; $lat = (float)$row->{$lat_field};
$lon = (float)$row->{$lon_field}; $lon = (float)$row->{$lon_field};
// If this row will be used as center map then we keep its lon/lat
// If there are multiple points on a single node take the first match
if (!empty($center_nid) && $center_nid == $row->nid && ($center_lon === NULL || $center_lat === NULL)) {
$center_lon = $lon;
$center_lat = $lat;
}
if (!empty($lat) && !empty($lon)) { if (!empty($lat) && !empty($lon)) {
if ($this->options['markers'] == 'nodetype') { if ($this->options['markers'] == 'nodetype') {
if (isset($markertypes[$row->gmap_node_type])) { if (isset($markertypes[$row->gmap_node_type])) {
...@@ -142,22 +178,42 @@ class gmap_plugin_style_gmap extends views_plugin_style { ...@@ -142,22 +178,42 @@ class gmap_plugin_style_gmap extends views_plugin_style {
if (!isset($offsets[$markername])) { if (!isset($offsets[$markername])) {
$offsets[$markername] = 0; $offsets[$markername] = 0;
} }
$tooltip = "";
if ($this->options['tooltipenabled'] && $row->$tooltip_field) {
$tooltip = $row->$tooltip_field;
}
$markers[] = array( $markers[] = array(
'latitude' => $lat, 'latitude' => $lat,
'longitude' => $lon, 'longitude' => $lon,
'markername' => $markername, 'markername' => $markername,
'offset' => $offsets[$markername], 'offset' => $offsets[$markername],
'text' => $this->row_plugin->render($row), 'text' => $this->row_plugin->render($row),
'opts' => array(
'title' => $tooltip,
'highlight' => ($highlight_nid == $row->nid) ? 1 : 0,
'highlightcolor' => $this->options['highlight_nodearg_color'],
),
); );
$offsets[$markername]++; $offsets[$markername]++;
} }
} }
if (!empty($markers)) { // Don't draw empty maps. if (!empty($markers)) { // Don't draw empty maps.
$map = gmap_parse_macro($this->options['macro']); $map = gmap_parse_macro($this->options['macro']);
// If center lon/lat are not empty they are used to center map
if (!empty($center_lon) && !empty($center_lat)) {
$map['longitude'] = $center_lon;
$map['latitude'] = $center_lat;
}
$map['markers'] = $markers; $map['markers'] = $markers;
$output .= theme($this->theme_functions(), $this->view, $this->options, $map, $title); $output .= theme($this->theme_functions(), $this->view, $this->options, $map, $title);
} }
} }
unset($this->view->row_index); unset($this->view->row_index);
return $output; return $output;
} }
...@@ -167,6 +223,19 @@ class gmap_plugin_style_gmap extends views_plugin_style { ...@@ -167,6 +223,19 @@ class gmap_plugin_style_gmap extends views_plugin_style {
*/ */
function options_form(&$form, &$form_state) { function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state); parent::options_form($form, $form_state);
$field_options = array();
$fields = $this->display->handler->get_handlers('field');
foreach ($fields as $id => $handler) {
$field_options[$id] = $handler->ui_name(FALSE);
}
$argument_options = array();
$arguments = $this->display->handler->get_handlers('argument');
foreach ($arguments as $id => $handler) {
$argument_options[$id] = $handler->ui_name(FALSE);
}
$form['macro'] = array( $form['macro'] = array(
'#type' => 'textfield', '#type' => 'textfield',
'#title' => t('Macro'), '#title' => t('Macro'),
...@@ -185,19 +254,11 @@ class gmap_plugin_style_gmap extends views_plugin_style { ...@@ -185,19 +254,11 @@ class gmap_plugin_style_gmap extends views_plugin_style {
'#default_value' => $this->options['datasource'], '#default_value' => $this->options['datasource'],
'#multiple' => FALSE, '#multiple' => FALSE,
); );
$options = array();
$fields = $this->display->handler->get_handlers('field');
foreach ($fields as $id => $handler) {
$options[$id] = $handler->ui_name(FALSE);
}
$form['latfield'] = array( $form['latfield'] = array(
'#title' => t('Latitude field'), '#title' => t('Latitude field'),
'#description' => t('Format must be degrees decimal.'), '#description' => t('Format must be degrees decimal.'),
'#type' => 'select', '#type' => 'select',
'#options' => $options, '#options' => $field_options,
'#default_value' => $this->options['latfield'], '#default_value' => $this->options['latfield'],
'#process' => array('views_process_dependency'), '#process' => array('views_process_dependency'),
'#dependency' => array('edit-style-options-datasource' => array('fields')), '#dependency' => array('edit-style-options-datasource' => array('fields')),
...@@ -206,7 +267,7 @@ class gmap_plugin_style_gmap extends views_plugin_style { ...@@ -206,7 +267,7 @@ class gmap_plugin_style_gmap extends views_plugin_style {
'#title' => t('Longitude field'), '#title' => t('Longitude field'),
'#description' => t('Format must be degrees decimal.'), '#description' => t('Format must be degrees decimal.'),
'#type' => 'select', '#type' => 'select',
'#options' => $options, '#options' => $field_options,
'#default_value' => $this->options['lonfield'], '#default_value' => $this->options['lonfield'],
'#process' => array('views_process_dependency'), '#process' => array('views_process_dependency'),
'#dependency' => array('edit-style-options-datasource' => array('fields')), '#dependency' => array('edit-style-options-datasource' => array('fields')),
...@@ -225,12 +286,11 @@ class gmap_plugin_style_gmap extends views_plugin_style { ...@@ -225,12 +286,11 @@ class gmap_plugin_style_gmap extends views_plugin_style {
), ),
'#default_value' => $this->options['markers'], '#default_value' => $this->options['markers'],
); );
$form['markerfield'] = array( $form['markerfield'] = array(
'#type' => 'select', '#type' => 'select',
'#title' => t('Marker field'), '#title' => t('Marker field'),
'#description' => t('You can use a views field to set the <em>markername</em> property of the markers.'), '#description' => t('You can use a views field to set the <em>markername</em> property of the markers.'),
'#options' => $options, '#options' => $field_options,
'#default_value' => $this->options['markerfield'], '#default_value' => $this->options['markerfield'],
'#process' => array('views_process_dependency'), '#process' => array('views_process_dependency'),
'#dependency' => array('edit-style-options-markers' => array('field')), '#dependency' => array('edit-style-options-markers' => array('field')),
...@@ -246,5 +306,72 @@ class gmap_plugin_style_gmap extends views_plugin_style { ...@@ -246,5 +306,72 @@ class gmap_plugin_style_gmap extends views_plugin_style {
'#title' => t('Marker / fallback marker to use'), '#title' => t('Marker / fallback marker to use'),
'#default_value' => $this->options['markertype'], '#default_value' => $this->options['markertype'],
); );
$form['center_on_nodearg'] = array(
'#type' => 'checkbox',
'#title' => t('Center on node argument'),
'#default_value' => $this->options['center_on_nodearg'],
'#description' => t('Note: The view must contain a node by node id as an argument Global:Null'),
);
$form['center_on_nodearg_arg'] = array(
'#title' => t('Argument'),
'#description' => empty($argument_options) ? t("The value of the selected argument must be a number that matches a node ID. Use the 'Global: Null' argument if you don't want to also restrict results to that node ID. You must have added arguments to the view to use this option.") : t("The selected argument must be a number that matches a node ID. Use the 'Global: Null' argument if you don't want to also restrict results to that node ID."),
'#type' => 'select',
'#options' => $argument_options,
'#default_value' => $this->options['center_on_nodearg_arg'],
'#process' => array('views_process_dependency'),
'#dependency' => array('edit-style-options-center-on-nodearg' => array(TRUE)),
);
$form['highlight_nodearg'] = array(
'#type' => 'checkbox',
'#title' => t('Highlight marker for node argument'),
'#default_value' => $this->options['highlight_nodearg'],
'#description' => t('Note: The view must contain a node by node id as an argument Global:Null'),
);
$form['highlight_nodearg_arg'] = array(
'#title' => t('Argument'),
'#description' => empty($argument_options) ? t("The value of the selected argument must be a number that matches a node ID. Use the 'Global: Null' argument if you don't want to also restrict results to that node ID. You must have added arguments to the view to use this option.") : t("The value of the selected argument must be a number that matches a node ID. Use the 'Global: Null' argument if you don't want to also restrict results to that node ID."),
'#type' => 'select',
'#options' => $argument_options,
'#default_value' => $this->options['highlight_nodearg_arg'],
'#process' => array('views_process_dependency'),
'#dependency' => array('edit-style-options-highlight-nodearg' => array(TRUE)),
);
$form['highlight_nodearg_color'] = array(
'#title' => t('Highlight color'),
'#description' => t("A 6 digit hex color value to use for the highlight. Include preceding hash. Example #FF0000"),
'#type' => 'textfield',
'#size' => 7,
'#maxlength' => 7,
'#default_value' => $this->options['highlight_nodearg_color'],
'#process' => array('views_process_dependency'),
'#dependency' => array('edit-style-options-highlight-nodearg' => array(TRUE)),
);
$form['tooltipenabled'] = array(
'#type' => 'checkbox',
'#title' => t('Display a tooltip when hovering over markers'),
'#default_value' => $this->options['tooltipenabled'],
);
$form['tooltipfield'] = array(
'#title' => t('Tooltip field'),
'#description' => empty($field_options) ? t("The field's format must be text. You must be using the fields row style and have added fields to the view to use this option.") : t("The field's format must be text."),
'#type' => 'select',
'#options' => $field_options,
'#default_value' => $this->options['tooltipfield'],
'#process' => array('views_process_dependency'),
'#dependency' => array('edit-style-options-tooltipenabled' => array(TRUE)),
);
}
/**
* Validate the options form.
*/
function options_validate(&$form, &$form_state) {
// Check if highlight color is a valid hex color
if (!preg_match('/^#[a-f0-9]{6}$/i', $form_state['values']['style_options']['highlight_nodearg_color'])) {
form_error($form['highlight_nodearg_color'], t('Highlight colour must be a valid hex code in the form #FF0000.'));
}
} }
} }
...@@ -144,6 +144,15 @@ function gmap_admin_settings(&$form_state) { ...@@ -144,6 +144,15 @@ function gmap_admin_settings(&$form_state) {
'#description' => t('Polygons without a specific style defined will fall back to this style'), '#description' => t('Polygons without a specific style defined will fall back to this style'),
'#default_value' => $defaults['styles']['poly_default'], '#default_value' => $defaults['styles']['poly_default'],
); );
$form['gmap_default']['styles']['highlight_color'] = array(
'#type' => 'textfield',
'#title' => t('Highlight color'),
'#size' => 6,
'#maxlength' => 6,
'#field_prefix' => '#',
'#description' => t('This sets the color of the marker highlight when the "highlight : Highlight marker on rollover" behaviour is enabled. Hex color value. Example: #00AA33'),
'#default_value' => $defaults['styles']['highlight_color'],
);
$form['gmap_default']['controltype'] = array( $form['gmap_default']['controltype'] = array(
'#type' => 'select', '#type' => 'select',
......
...@@ -300,6 +300,9 @@ Drupal.gmap.addHandler('gmap', function (elem) { ...@@ -300,6 +300,9 @@ Drupal.gmap.addHandler('gmap', function (elem) {
if (obj.vars.behavior.overview) { if (obj.vars.behavior.overview) {
map.addControl(new GOverviewMapControl()); map.addControl(new GOverviewMapControl());
} }
if (obj.vars.behavior.googlebar) {
map.enableGoogleBar();
}
if (obj.vars.behavior.scale) { if (obj.vars.behavior.scale) {
map.addControl(new GScaleControl()); map.addControl(new GScaleControl());
} }
......
/* $Id$ */
/**
* @file
* Common marker highlighting routines.
*/
/**
* Highlights marker on rollover.
* Removes highlight on previous marker.
*
* Creates a "circle" using 20-sided GPolygon at the given point
* Circle polygon object is global variable as there is only one highlighted marker at a time
* and we want to remove the previously placed polygon before placing a new one.
*
* Original code "Google Maps JavaScript API Example"
*/
highlightMarker = function (map, currentMarker, highlightID, color) {
var markerPoint = currentMarker.marker.getPoint();
var polyPoints = Array();
var mapNormalProj = G_NORMAL_MAP.getProjection();
var mapZoom = map.getZoom();
var clickedPixel = mapNormalProj.fromLatLngToPixel(markerPoint, mapZoom);
var polySmallRadius = 20;
var polyNumSides = 20;
var polySideLength = 18;
for (var a = 0; a < (polyNumSides + 1); a++) {
var aRad = polySideLength * a * (Math.PI/180);
var polyRadius = polySmallRadius;
var pixelX = clickedPixel.x + polyRadius * Math.cos(aRad);
var pixelY = clickedPixel.y + polyRadius * Math.sin(aRad);
var polyPixel = new GPoint(pixelX, pixelY);
var polyPoint = mapNormalProj.fromPixelToLatLng(polyPixel, mapZoom);
polyPoints.push(polyPoint);
}
// Using GPolygon(points, strokeColor?, strokeWeight?, strokeOpacity?, fillColor?, fillOpacity?)
map.highlightID = new GPolygon(polyPoints, color, 2, 0, color, 0.5);
map.addOverlay(map.highlightID);
};
unHighlightMarker = function (map, currentMarker, highlightID) {
if (map.highlightID) {
map.removeOverlay(map.highlightID);
delete map.highlightID;
}
};
...@@ -22,6 +22,15 @@ Drupal.gmap.addHandler('gmap', function (elem) { ...@@ -22,6 +22,15 @@ Drupal.gmap.addHandler('gmap', function (elem) {
GEvent.addListener(m, 'click', function () { GEvent.addListener(m, 'click', function () {
obj.change('clickmarker', -1, marker); obj.change('clickmarker', -1, marker);
}); });
if (obj.vars.behavior.highlight) {
GEvent.addListener(m, 'mouseover', function () {
var highlightColor = '#' + obj.vars.styles.highlight_color;
highlightMarker(obj.map, marker, 'hoverHighlight', highlightColor);
});
GEvent.addListener(m, 'mouseout', function () {
unHighlightMarker(obj.map, marker, 'hoverHighlight');
});
}
if (obj.vars.behavior.extramarkerevents) { if (obj.vars.behavior.extramarkerevents) {
GEvent.addListener(m, 'mouseover', function () { GEvent.addListener(m, 'mouseover', function () {
obj.change('mouseovermarker', -1, marker); obj.change('mouseovermarker', -1, marker);
...@@ -42,6 +51,10 @@ Drupal.gmap.addHandler('gmap', function (elem) { ...@@ -42,6 +51,10 @@ Drupal.gmap.addHandler('gmap', function (elem) {
if (obj.vars.behavior.autozoom) { if (obj.vars.behavior.autozoom) {
obj.bounds.extend(marker.marker.getPoint()); obj.bounds.extend(marker.marker.getPoint());
} }
// If the highlight arg option is used in views highlight the marker.
if (marker.opts.highlight == 1) {
highlightMarker(obj.map, marker, 'viewHighlight', marker.opts.highlightcolor);
}
}); });
// Default marker actions. // Default marker actions.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment