You are here

protected function LatLonFormatter::getDmsComponents in Geofield 8

Generates the DMS expected components given a Point.

Parameters

\Point $point: The point to represent as DMS.

Return value

array The DMS LatLon components

1 call to LatLonFormatter::getDmsComponents()
LatLonFormatter::viewElements in src/Plugin/Field/FieldFormatter/LatLonFormatter.php
Builds a renderable array for a field value.

File

src/Plugin/Field/FieldFormatter/LatLonFormatter.php, line 131

Class

LatLonFormatter
Plugin implementation of the 'geofield_latlon' formatter.

Namespace

Drupal\geofield\Plugin\Field\FieldFormatter

Code

protected function getDmsComponents(\Point $point) {
  $dms_point = DmsConverter::decimalToDms($point
    ->x(), $point
    ->y());
  $components = [];
  foreach ([
    'lat',
    'lon',
  ] as $component) {
    $item = $dms_point
      ->get($component);
    if ($this
      ->getSetting('output_format') == 'dm') {
      $item['minutes'] = number_format($item['minutes'] + $item['seconds'] / 60, 5);
      $item['seconds'] = NULL;
    }
    $components[$component] = $item;
  }
  return $components;
}