Skip to content
Snippets Groups Projects
Commit 134619f6 authored by Brandon Bergren's avatar Brandon Bergren
Browse files

Add the ability to base gmap views off of arbitrary fields. Also add a way to...

Add the ability to base gmap views off of arbitrary fields. Also add a way to specify the marker using a field.
parent fd5ab78b
No related branches found
No related tags found
No related merge requests found
...@@ -29,6 +29,10 @@ class gmap_plugin_style_gmap extends views_plugin_style { ...@@ -29,6 +29,10 @@ class gmap_plugin_style_gmap extends views_plugin_style {
$options['markers'] = array('default' => 'static'); $options['markers'] = array('default' => 'static');
$options['markertype'] = array('default' => 'drupal'); $options['markertype'] = array('default' => 'drupal');
$options['latfield'] = array('default' => '');
$options['lonfield'] = array('default' => '');
$options['markerfield'] = array('default' => '');
return $options; return $options;
} }
...@@ -53,6 +57,20 @@ class gmap_plugin_style_gmap extends views_plugin_style { ...@@ -53,6 +57,20 @@ class gmap_plugin_style_gmap extends views_plugin_style {
return; return;
} }
$lat_field = 'gmap_lat';
$lon_field = 'gmap_lon';
// Determine fieldname for latitude and longitude fields.
if ($this->options['datasource'] == 'fields') {
$lat_field = $this->view->display_handler->get_handler('field', $this->options['latfield'])->field_alias;
$lon_field = $this->view->display_handler->get_handler('field', $this->options['lonfield'])->field_alias;
}
// Determine fieldname for marker field.
if ($this->options['markers'] == 'field') {
$marker_field = $this->view->display_handler->get_handler('field', $this->options['markerfield'])->field_alias;
}
$markername = isset($this->options['markertype']) ? $this->options['markertype'] : 'drupal'; $markername = isset($this->options['markertype']) ? $this->options['markertype'] : 'drupal';
$markertypes = variable_get('gmap_node_markers', array()); $markertypes = variable_get('gmap_node_markers', array());
...@@ -70,8 +88,8 @@ class gmap_plugin_style_gmap extends views_plugin_style { ...@@ -70,8 +88,8 @@ class gmap_plugin_style_gmap extends views_plugin_style {
$markers = array(); $markers = array();
$offsets = array(); $offsets = array();
foreach ($records as $label => $row) { foreach ($records as $label => $row) {
$lat = (float)$row->gmap_lat; $lat = (float)$row->{$lat_field};
$lon = (float)$row->gmap_lon; $lon = (float)$row->{$lon_field};
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])) {
...@@ -83,6 +101,11 @@ class gmap_plugin_style_gmap extends views_plugin_style { ...@@ -83,6 +101,11 @@ class gmap_plugin_style_gmap extends views_plugin_style {
$markername = $row->gmap_node_marker; $markername = $row->gmap_node_marker;
} }
} }
else if ($this->options['markers'] == 'field') {
if (!empty($row->{$marker_field})) {
$markername = $row->{$marker_field};
}
}
if (!isset($offsets[$markername])) { if (!isset($offsets[$markername])) {
$offsets[$markername] = 0; $offsets[$markername] = 0;
} }
...@@ -119,29 +142,67 @@ class gmap_plugin_style_gmap extends views_plugin_style { ...@@ -119,29 +142,67 @@ class gmap_plugin_style_gmap extends views_plugin_style {
); );
$form['datasource'] = array( $form['datasource'] = array(
'#type' => 'radios', '#type' => 'select',
'#title' => t('Data Source'), '#title' => t('Data Source'),
'#options' => array( '#options' => array(
'location' => t('Location.module'), 'location' => t('Location.module'),
'autodetect' => t('Fields named "latitude" and "longitude" @@@TODO'), 'fields' => t('Choose latitude and longitude fields'),
//'geocode' => t('Just-in-time geocoding on field named "address"'), //'geocode' => t('Just-in-time geocoding on field named "address"'),
), ),
'#default_value' => $this->options['datasource'], '#default_value' => $this->options['datasource'],
'#multiple' => FALSE, '#multiple' => FALSE,
); );
$options = array();
// @@@ Fix this when I'm not having a monday morning.
// There's likely a more "correct" way.
foreach ($this->display->display_options['fields'] as $id => $handler) {
$data = views_fetch_data($handler['table']);
$options[$id] = $handler['label'];
}
$form['latfield'] = array(
'#title' => t('Latitude field'),
'#description' => t('Format must be degrees decimal.'),
'#type' => 'select',
'#options' => $options,
'#default_value' => $this->options['latfield'],
'#process' => array('views_process_dependency'),
'#dependency' => array('edit-style-options-datasource' => array('fields')),
);
$form['lonfield'] = array(
'#title' => t('Longitude field'),
'#description' => t('Format must be degrees decimal.'),
'#type' => 'select',
'#options' => $options,
'#default_value' => $this->options['lonfield'],
'#process' => array('views_process_dependency'),
'#dependency' => array('edit-style-options-datasource' => array('fields')),
);
$form['markers'] = array( $form['markers'] = array(
'#type' => 'radios', '#type' => 'select',
'#title' => t('Marker handling'), '#title' => t('Marker handling'),
// @@@ Detect view type automatically? // @@@ Detect view type automatically?
'#options' => array( '#options' => array(
'nodetype' => t('By content type (for node views)'), 'nodetype' => t('By content type (for node views)'),
'taxonomy' => t('By term (for node views)'), 'taxonomy' => t('By term (for node views)'),
'field' => t('Use marker field'),
'static' => t('Use single marker type'), 'static' => t('Use single marker type'),
), ),
'#default_value' => $this->options['markers'], '#default_value' => $this->options['markers'],
); );
$form['markerfield'] = array(
'#type' => 'select',
'#title' => t('Marker field'),
'#description' => t('You can use a views field to set the <em>markername</em> property of the markers.'),
'#options' => $options,
'#default_value' => $this->options['markerfield'],
'#process' => array('views_process_dependency'),
'#dependency' => array('edit-style-options-markers' => array('field')),
);
// Hide the taxonomy handling if gmap_taxonomy.module isn't installed. // Hide the taxonomy handling if gmap_taxonomy.module isn't installed.
if (!module_exists('gmap_taxonomy')) { if (!module_exists('gmap_taxonomy')) {
unset($form['markers']['#options']['taxonomy']); unset($form['markers']['#options']['taxonomy']);
......
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