I have 2 markers on map and expect when on click, it will display the location of each marker. However, currently when I click, the map will be auto centre and display the title of the node instead.

How can I change that?

CommentFileSizeAuthor
#6 geofield.1698352-6.patch1.22 KBjrb
#5 geofield.1698352-5.patch1.04 KBjrb
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

samgreco’s picture

I am seeing this now too. Anyone have an answer? I am displaying this in a node.

Manuel Garcia’s picture

Yup, this is hardwired into geofield_map.module

inside function geofield_map_field_formatter_view....
Line 66:
'description' => entity_label($entity_type, $entity),

I feel it would make a lot of sense to display the address field content if you are using address field as the source of the point geolocation data. Not sure if we can do this without hacking up the module... any hints anyone?

DSquaredB’s picture

Is there a solution for displaying the address field (or other fields within the entity type) instead of the name of the entity type? Entity type name is not a useful field to display in the popup.

RdeBoer’s picture

To all the above: use IP Geolocation Views and Maps in combination with Geofield (7.x-1.x or better: 7.x-2.x) to realise more advanced map configuration requirements.

jrb’s picture

Issue summary: View changes
Status: Active » Needs review
FileSize
1.04 KB

I've created a patch that makes the geofield_map module use a theme function to set that 'description'. This will allow you to use theming/preprocess functions to override this value.

I did something like this in a custom module to make the popup show the address:

/**
 * Implements hook_preprocess_geofield_map_popup_text().
 */
function mymodule_preprocess_geofield_map_popup_text(&$variables) {
  if (!empty($variables['entity']->field_address)) {
    $field = field_view_field($variables['entity_type'], $variables['entity'], 'field_address');
    $field['#label_display'] = 'hidden';
    $variables['map_popup_text'] = drupal_render($field);
  }
}

Ultimately, it might be nice to make the popup text part of the field display settings where you could even allow the use of tokens, too. But, this at least made it less hard-coded and let me set the value.

jrb’s picture

FileSize
1.22 KB

The patch above didn't apply correctly. This one's better.

hasjalil’s picture

IP Geolocation Views & Maps (IPGV&M) makes it easy to create Views-based mapping solutions using the map renderer of your choice (Google, OpenLayers or Leaflet) with any location storage module of your choice, e.g. Get Locations, Geofield, Geolocation Field or Location.
Have a glance to https://www.drupal.org/project/ip_geoloc

ITWest-jg’s picture

Could you also do this for the view plugin? geofield_map_plugin_style_map.inc At the moment it doesn't have any of the options that geofield_map_field_formatter_view has... in fact there is a lot of duplicated code, sort of.

tecjam’s picture

I created a custom plugin which

a) adds custom markers from a taxonomy term assigned to each content that should be shown in the map (to which I added an image field called 'field_store_type_icon')

b) Edits the popup description and adds any other field values to it, rather than just the single option available in the settings.

Note that some hacks need to be made to - so use this patch: https://www.drupal.org/files/issues/Geofield-Define%20custom%20marker%20...

Now you can use yourmodule_geofield_map_data_alter(&$datum, $view, $result) {}

Thanks to Arlina - https://www.drupal.org/node/2362929#comment-9279755

My Module is called geofield_maps_markers and here is the code (the comments should be enough for most people ..

<?php

/**
 * Implements hook_geofield_map_data_alter().
 *
 * @param $datum   Settings passed to js.
 * @param $view    The complete view object.
 * @param $result  The current row object.
 */
function geofield_maps_markers_geofield_map_data_alter(&$datum, $view, $result) {
  
  
  // Path to default marker icon.
  $icon = '//maps.google.com/mapfiles/ms/icons/red-dot.png';
  
  // unfortunately we require the $node object
  
  // so grab the nid
  $nodeId = $result->entity;
  
  // and load the node
  $node = node_load($nodeId);

  // get field data - language workaround
  // see: https://api.drupal.org/api/drupal/modules!field!field.module/function/field_get_items/7
  $term = field_get_items('node', $node, 'field_store_type');
  $termId = $term['0']['tid'];

  if(!empty($termId)) {
	  
	  $term = taxonomy_term_load($termId);
		  
	  // do we have an image attached to this taxonomy term
	  if(count($term->field_store_type_icon) > 0) {
		  
		  // get the icon uri
		  $icon_uri = $term->field_store_type_icon['und']['0']['uri'];
		  
		  // get full path for uri
		  $icon = file_create_url($icon_uri);
	  }
  
  }


  // Set path to custom icon.
  $datum->options['icon'] = $icon;
  
  // load the node title
  $title = '<h3>' . $node->title . '</h3>';

  // load the address
  $address = field_view_field('node', $node, 'field_store_address');
  $address = render($address);
  
  // get the edit url
  $edit = url(drupal_get_path_alias('node/' . $node->nid . '/edit'), array('absolute' => TRUE));
  $edit = '<a href="' . $edit . '">' . t('edit') . '</a>';
  
  // combine our output
  $output = $title . '<br />' . $address . '<br />' . $edit;

  $datum->properties = array(
    'description' => $output,
  );

}
RdeBoer’s picture

Hard-coding a solution is an interesting exercise.
However, as mentioned in #4 and #7, all of this has been available for years, fully configurable through the VIews UI, when you use Geofield (or one of the other coordinate storage modules) in combo with http://drupal.org/project/ip_geoloc.

fox mulder’s picture

You can try something like this to override entity label with content of some field of entity


/**
 * Implements hook_entity_info_alter().
 */
function MYMODULE_entity_info_alter(&$entity_info) {
  if (isset($entity_info['SOME_ENTITY_TYPE']['label callback'])) {
    $entity_info['SOME_ENTITY_TYPE']['label callback'] = 'MY_LABEL_CALLBACK';
  }
}

/**
 * Overridden label callback of event_location
 */
function MY_LABEL_CALLBACK($entity, $entity_type) {
  if ($entity_type == 'SOME_ENTITY_TYPE') {
    if (isset($entity->SOME_FIELD[LANGUAGE_NONE][0]['value'])) {
      return $entity->SOME_FIELD[LANGUAGE_NONE][0]['value'];
    }
  }
}
soniaojha’s picture

I am using geolocation map in drupal 8 and the map is showing on page but not showing in colorbox pop-up.