You are here

function staticmap_field_formatter_view in Static Map 7

Implements hook_field_formatter_view().

File

./staticmap.module, line 158
SiteMap module.

Code

function staticmap_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  $element = array();
  $settings = $display['settings'];
  ctools_include('export');
  $preset = ctools_export_crud_load('staticmap_presets', $settings['preset']);
  $settings['preset'] = unserialize($preset->data);
  $provider = staticmap_load_provider($settings['preset']['provider']);
  $field_processor = staticmap_load_field($field['type']);
  switch ($display['type']) {
    case 'staticmap':
      if ($provider) {
        $geodata = $field_processor
          ->provideGeodata($items, $settings);
        $parameters = $provider
          ->buildParams($geodata, $settings);
        $url = $provider->apiUri . http_build_query($parameters);
        if (!empty($settings['preset']['cache'])) {
          $uri = static_map_cache_file_uri($entity_type, $entity, $instance, $url);
          if (!file_exists($uri)) {
            static_map_cache_file_delete($entity_type, $entity, $instance);
            static_map_cache_file_save($provider->apiUri . http_build_query($parameters), $uri);
          }
          $url = file_create_url($uri);
        }
        $size = explode('x', $parameters['size']);
        $element[0] = array(
          '#markup' => theme('staticmap_map', array(
            'path' => $url,
            'width' => $size[0],
            'height' => $size[1],
          )),
        );
      }
      else {
        $element[0] = array(
          '#markup' => "ERROR: MISSING PROCESS FUNCTION",
        );
      }
      break;
  }
  return $element;
}