class DmsConverter in Geofield 8
Helper class to convert point object from one format to the other.
Hierarchy
- class \Drupal\geofield\DmsConverter implements DmsConverterInterface
Expanded class hierarchy of DmsConverter
4 files declare their use of DmsConverter
- DmsConverterTest.php in tests/
src/ Unit/ DmsConverterTest.php - GeofieldDms.php in src/
Element/ GeofieldDms.php - GeofieldDmsWidget.php in src/
Plugin/ Field/ FieldWidget/ GeofieldDmsWidget.php - LatLonFormatter.php in src/
Plugin/ Field/ FieldFormatter/ LatLonFormatter.php
File
- src/
DmsConverter.php, line 8
Namespace
Drupal\geofieldView source
class DmsConverter implements DmsConverterInterface {
/**
* {@inheritdoc}
*/
public static function dmsToDecimal(DmsPoint $point) {
$lon_data = $point
->getLon();
$lat_data = $point
->getLat();
$lon = round($lon_data['degrees'] + $lon_data['minutes'] / 60 + $lon_data['seconds'] / 3600, 10);
$lat = round($lat_data['degrees'] + $lat_data['minutes'] / 60 + $lat_data['seconds'] / 3600, 10);
$lon = $lon_data['orientation'] == 'W' ? -1 * $lon : $lon;
$lat = $lat_data['orientation'] == 'S' ? -1 * $lat : $lat;
return [
$lon,
$lat,
];
}
/**
* {@inheritdoc}
*/
public static function decimalToDms($lon, $lat) {
$lat_direction = $lat < 0 ? 'S' : 'N';
$lon_direction = $lon < 0 ? 'W' : 'E';
$lat_in_degrees = floor(abs($lat));
$lon_in_degrees = floor(abs($lon));
$la_decimal = (abs($lat) - $lat_in_degrees) * 60;
$lon_decimal = (abs($lon) - $lon_in_degrees) * 60;
$lat_minutes = floor($la_decimal);
$lon_minutes = floor($lon_decimal);
$la_decimal = ($la_decimal - $lat_minutes) * 60;
$lon_decimal = ($lon_decimal - $lon_minutes) * 60;
$lat_seconds = round($la_decimal);
$lon_seconds = round($lon_decimal);
return new DmsPoint([
'orientation' => $lon_direction,
'degrees' => $lon_in_degrees,
'minutes' => $lon_minutes,
'seconds' => $lon_seconds,
], [
'orientation' => $lat_direction,
'degrees' => $lat_in_degrees,
'minutes' => $lat_minutes,
'seconds' => $lat_seconds,
]);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DmsConverter:: |
public static | function |
Transforms a Decimal point to a dms one. Overrides DmsConverterInterface:: |
|
DmsConverter:: |
public static | function |
Transforms a DMS point to a decimal one. Overrides DmsConverterInterface:: |