protected function ThemeService::bearingToText in Weather 2.0.x
Same name and namespace in other branches
- 8 src/Service/ThemeService.php \Drupal\weather\Service\ThemeService::bearingToText()
Converts a compass bearing to a text direction.
This function can be used to get a text representation of a compass bearing (for example, 0° North, 86° East, ...).
Parameters
string $bearing: Compass bearing in degrees.
bool $abbreviated: If true, return abbreviated directions (N, NNW) instead of full text (North, North-Northwest). Defaults to full text directions.
Return value
string Formatted representation.
1 call to ThemeService::bearingToText()
- ThemeService::formatWind in src/
Service/ ThemeService.php - Convert wind.
File
- src/
Service/ ThemeService.php, line 655
Class
- ThemeService
- Prepare forecast data for displaying.
Namespace
Drupal\weather\ServiceCode
protected function bearingToText($bearing, $abbreviated = FALSE) {
// Determine the sector. This works for 0° up to 348.75°
// If the bearing was greater than 348.75°, perform a wrap (%16)
$sector = floor(($bearing + 11.25) / 22.5) % 16;
if (!$abbreviated) {
$direction = [
$this
->t('North'),
$this
->t('North-Northeast'),
$this
->t('Northeast'),
$this
->t('East-Northeast'),
$this
->t('East'),
$this
->t('East-Southeast'),
$this
->t('Southeast'),
$this
->t('South-Southeast'),
$this
->t('South'),
$this
->t('South-Southwest'),
$this
->t('Southwest'),
$this
->t('West-Southwest'),
$this
->t('West'),
$this
->t('West-Northwest'),
$this
->t('Northwest'),
$this
->t('North-Northwest'),
];
}
else {
$direction = [
$this
->t('N'),
$this
->t('NNE'),
$this
->t('NE'),
$this
->t('ENE'),
$this
->t('E'),
$this
->t('ESE'),
$this
->t('SE'),
$this
->t('SSE'),
$this
->t('S'),
$this
->t('SSW'),
$this
->t('SW'),
$this
->t('WSW'),
$this
->t('W'),
$this
->t('WNW'),
$this
->t('NW'),
$this
->t('NNW'),
];
}
return $direction[$sector];
}