Define custom markers per marker type with Geofield Map

Created on 24 October 2014, almost 10 years ago
Updated 5 November 2023, 11 months ago

Creates hook_geofield_map_data_alter() in order to give the user the opportunity to modify markers options.

✨ Feature request
Status

Needs review

Version

2.0

Component

Code

Created by

πŸ‡«πŸ‡·France sebastiendan

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States markabur

    I like this approach! In my case I needed to check which view I was currently altering, and I also needed some data from the rendered row result in order to use custom numbered markers. Here's what I changed:

    -          $context = array('view_row' => $result);
    +          $context = array(
    +            'view_name' => $this->view->name,
    +            'view_display' => $this->view->current_display,
    +            'view_row' => $result,
    +            'view_row_rendered' => $this->rendered_fields[$id],
    +          );
    

    Here's how I am using the new context info. (My view is configured in Views UI with a result counter, which is available in view_row_rendered but not in view_row.)

    function mymodule_geofield_map_data_alter($datum, $context) {
      if (!empty($context['view_row']) && $context['view_name'] == 'my_map') {
        $path = '/' . drupal_get_path('module', 'mymodule') . '/markers/';
    
        // Path to custom numbered marker icon, e.g. mymodule/markers/number12.png .
        $result_counter = $context['view_row_rendered']['counter'];
        $icon = $path . 'number' . $result_counter . '.png';
    
        // Set path to custom icon.
        $datum->options['icon'] = $icon;
      }
    }
    
Production build 0.71.5 2024