You are here

function geolocation_html5_field_formatter_view in Geolocation Field 7

Implements hook_field_formatter_view().

File

modules/geolocation_html5/geolocation_html5.module, line 22
HTML5 widget and formaters for Geolocation.

Code

function geolocation_html5_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  $element = array();
  drupal_add_css(drupal_get_path('module', 'geolocation_html5') . '/geolocation_html5.css', 'file');
  switch ($display['type']) {
    case 'geolocation_html5_mapimage':
      foreach ($items as $delta => $item) {

        // Calculate dot position.
        $latitude = $item['lat'];
        $longitude = $item['lng'];
        $left = _geolocation_html5_lng2px($longitude, -168, 450);
        $bottom = _geolocation_html5_lat2px($latitude, 78, -58, 250);
        $dot_style = ' style="display:block; left:' . $left . 'px; bottom:' . $bottom . 'px;"';
        $element[$delta]['mapimage'] = array(
          '#type' => 'markup',
          '#markup' => '<div class="geolocation-html5-map" style="display:block;"><div class="dot"' . $dot_style . '></div></div>',
        );
      }
      break;
  }
  return $element;
}