I have been slowing getting closer to getting gmap and location, cck and views to work together... now I'm stuck at:
http://drupal.org/node/332314#comment-1123003
and I thought it might be a new problem....

I am not using locations associated with a node, I instead have a cck field location in a node... and it looks like the view cannot access that location info... It shows up ok in the "list", but when I set the view style to "GMap", it shows nothing...

Here are some screen shots which show the direct Location: blank fields on the node are empty, event though the cck field has location info ...

CommentFileSizeAuthor
locationempty-zoomin.jpg121.19 KByesct
locationempty.jpg102.5 KByesct

Comments

yesct’s picture

Maybe the datasource part needs an option for "cck location field"?

as in:

  function query() {    
     if ($this->options['datasource'] == 'location') {      
        $this->view->query->add_field('location', 'latitude', 'gmap_lat');
        $this->view->query->add_field('location', 'longitude', 'gmap_lon');    
     }

....
    $form['datasource'] = array(
      '#type' => 'radios',
      '#title' => t('Data Source'),
      '#options' => array(
        'location' => t('Location.module'),
        'autodetect' => t('Fields named "latitude" and "longitude" @@@TODO'),
      //'geocode' => t('Just-in-time geocoding on field named "address"'),
      ),
      '#default_value' => $this->options['datasource'],
      '#multiple' => FALSE,
    );

changing it to something like:

  function query() {    
     if ($this->options['datasource'] == 'location_cck') {      
        $this->view->query->add_field('location_cck', 'latitude', 'gmap_lat');
        $this->view->query->add_field('location_cck', 'longitude', 'gmap_lon');    
     }

....
    $form['datasource'] = array(
      '#type' => 'radios',
      '#title' => t('Data Source'),
      '#options' => array(
        'location' => t('Location.module'),
        'location_cck' => t('a Location.module cck field'),
        'autodetect' => t('Fields named "latitude" and "longitude" @@@TODO'),
      //'geocode' => t('Just-in-time geocoding on field named "address"'),
      ),
      '#default_value' => $this->options['datasource'],
      '#multiple' => FALSE,
    );

from
gmap_plugin_style_gmap.inc ?

but where does it fill in the values in the query field?

yesct’s picture

I've been looking all around in the gmap and views code... and the best I have is:

<?php
// $Id: gmap_plugin_style_gmap.inc,v 1.1 2008/09/17 22:47:10 bdragon Exp $

/**
 * @file
 * GMap style plugin.
 */

/**
 * Style plugin to render a map.
 *
 * @ingroup views_style_plugins
 */
class gmap_plugin_style_gmap extends views_plugin_style {
  /**
   * Set default options
   */
  function option_definition() {
    $options = parent::option_definition();

    $options['macro'] = array(
      'default' => '[gmap ]',
    );

    $options['datasource'] = array(
      'default' => 'location',
    );

    $options['markers'] = array('default' => 'static');
    $options['markertype'] = array('default' => 'default');

    return $options;
  }

  function query() {
    if ($this->options['datasource'] == 'location') {
      $this->view->query->add_field('location', 'latitude', 'gmap_lat');
      $this->view->query->add_field('location', 'longitude', 'gmap_lon');
    } else if ($this->options['datasource'] == 'locationcckfield') {
      $this->view->query->add_field('location', 'latitude', 'gmap_lat');
      $this->view->query->add_field('location', 'longitude', 'gmap_lon');
    } 

    if ($this->options['markers'] == 'nodetype') {
      $this->view->query->add_field('node', 'type', 'gmap_node_type');
    }

  }

  function render() {
    if (empty($this->row_plugin)) {
      vpr('gmap_plugin_style_gmap: Missing row plugin');
      return;
    }

    $markername = 'drupal';

    $markertypes = variable_get('gmap_node_markers', array());
    if ($this->options['markers'] == 'nodetype') {
      $markertypes = variable_get('gmap_node_markers', array());
    }

    // Group the rows according to the grouping field, if specified.
    $sets = $this->render_grouping($this->view->result, $this->options['grouping']);

    // Render each group separately and concatenate.  Plugins may override this
    // method if they wish some other way of handling grouping.
    $output = '';
    foreach ($sets as $title => $records) {
      $markers = array();
      $offsets = array();
        foreach ($records as $label => $row) {
        $lat = (float)$row->gmap_lat;
        $lon = (float)$row->gmap_lon;
        if (!empty($lat) && !empty($lon)) {
          if ($this->options['markers'] == 'nodetype') {
            $markername = isset($markertypes[$row->gmap_node_type]) ? $markertypes[$row->gmap_node_type] : 'drupal';
          }
          if (!isset($offsets[$markername])) {
            $offsets[$markername] = 0;
          }
          $markers[] = array(
            'latitude' => $lat,
            'longitude' => $lon,
            'markername' => $markername,
            'offset' => $offsets[$markername],
            'text' => $this->row_plugin->render($row),
          );
          $offsets[$markername]++;
        }
      }
      if (!empty($markers)) { // Don't draw empty maps.
        $map = gmap_parse_macro($this->options['macro']);
        $map['markers'] = $markers;
        $map['id'] = gmap_get_auto_mapid();
        $output .= theme($this->theme_functions(), $this->view, $this->options, $map, $title);
      } else {
        // output some kind of message that the map was empty and wont draw empty maps
      }
    }
    return $output;
  }

  /**
   * Render the given style.
   */
  function options_form(&$form, &$form_state) {
    parent::options_form($form, $form_state);
    $form['macro'] = array(
      '#type' => 'textfield',
      '#title' => t('Macro'),
      '#size' => 1000,
      '#default_value' => $this->options['macro'],
    );

    $form['datasource'] = array(
      '#type' => 'radios',
      '#title' => t('Data Source'),
      '#options' => array(
        'location' => t('Location.module'),
        'locationcckfield' => t('Location.module cck field'),
        'autodetect' => t('Fields named "latitude" and "longitude" @@@TODO'),
      //'geocode' => t('Just-in-time geocoding on field named "address"'),
      ),
      '#default_value' => $this->options['datasource'],
      '#multiple' => FALSE,
    );

    $form['markers'] = array(
      '#type' => 'radios',
      '#title' => t('Marker handling'),
      // @@@ Detect view type automatically?
      '#options' => array(
        'nodetype' => t('By content type (for node views)'),
        //'taxonomy' => t('By term (for node views)'),
        'static' => t('Use single marker type'),
      ),
      '#default_value' => $this->options['markers'],
    );

    if ($this->options['markers'] == 'static') {
      $form['markertype'] = array(
        '#type' => 'gmap_markerchooser',
        '#title' => t('Marker type to use'),
        '#default_value' => $this->options['markertype'],
      );
    }

  }
}

which just has some changes here:

  function query() {
    if ($this->options['datasource'] == 'location') {
      $this->view->query->add_field('location', 'latitude', 'gmap_lat');
      $this->view->query->add_field('location', 'longitude', 'gmap_lon');
    } else if ($this->options['datasource'] == 'locationcckfield') {
      $this->view->query->add_field('location', 'latitude', 'gmap_lat');
      $this->view->query->add_field('location', 'longitude', 'gmap_lon');
    } 

and here:

   $form['datasource'] = array(
      '#type' => 'radios',
      '#title' => t('Data Source'),
      '#options' => array(
        'location' => t('Location.module'),
        'locationcckfield' => t('Location.module cck field'),
        'autodetect' => t('Fields named "latitude" and "longitude" @@@TODO'),
      //'geocode' => t('Just-in-time geocoding on field named "address"'),
      ),
      '#default_value' => $this->options['datasource'],
      '#multiple' => FALSE,
    );

and a recommendation to add some feedback for empty maps here:

   if (!empty($markers)) { // Don't draw empty maps.
        $map = gmap_parse_macro($this->options['macro']);
        $map['markers'] = $markers;
        $map['id'] = gmap_get_auto_mapid();
        $output .= theme($this->theme_functions(), $this->view, $this->options, $map, $title);
      } else {
        // output some kind of message that the map was empty and wont draw empty maps
      }

The trouble is, I dont see how to tell it to get the lat and long from a location cck field (which is an lid, to a location row in the location table, using the normal location structure)...

The "field" that contains the lid shows up in the views "field" dialog, and displays great in a "list" style, but the gmap style in views doesn't know how to find/use the location fields in the location cck field ... and since each site that uses location as a cck field, probably will call the field in the table a different name, I'm not sure how to code it anyway... well, kind of, it is already coded, I mean, it already can be selected in the "field" for the view... gmap just doesnt get the location lat and long info from it.

I'm talking in circles... more later. Thanks for any help.

drewish’s picture

Status: Active » Closed (duplicate)

I've posted a patch to add lat lon field support over on #338587: Move views integration code to gmap_location module?