function theme_yr_verdata_wind in Yr Weatherdata 7
Same name and namespace in other branches
- 6.2 yr_verdata.module \theme_yr_verdata_wind()
Function for generating a themed wind symbol for one forecast period.
Parameters
$vars: Array with two keys: dir: The windDirection property from the loaded xml object. Should have the attributes 'deg', 'code' and 'name'. speed: The windSpeed property from the loaded xml object. Should have the attributes 'mps' and 'name'.
Return value
Returns a themed image for the wind symbol.
3 theme calls to theme_yr_verdata_wind()
- yr_verdata_generate in ./
yr_verdata.module - Function for generating a forecast for a location. This function should only be called after having checked if there is an up-to-date cache available, as this will load and parse an xml-file, possibly getting it from a remote host first, which is…
- yr_verdata_generate_forecastboxes in ./
yr_verdata.module - Function for generating one or more forecast boxes for given periods.
- yr_verdata_page_all in ./
yr_verdata.module - Function for generating the main forecast page.
File
- ./
yr_verdata.module, line 990 - yr_verdata.module This file contains the code for getting the forecast from yr.no and displaying it on a Drupal site.
Code
function theme_yr_verdata_wind($vars) {
// First, calculate different speed units.
$kph = bcmul($vars['speed']['mps'], 3.6, 1);
$mph = bcmul($vars['speed']['mps'], 2.24, 1);
$knots = bcmul($vars['speed']['mps'], 1.94, 1);
// Set up the return array.
$wind = array(
'speed' => array(
'm/s' => check_plain($vars['speed']['mps']),
'km/h' => $kph,
'mph' => $mph,
'knots' => $knots,
),
'speedname' => check_plain($vars['speed']['name']),
'deg' => check_plain($vars['dir']['deg']),
'code' => check_plain($vars['dir']['code']),
'dirname' => check_plain($vars['dir']['name']),
);
// Add the 'mps' notation for meters per second.
$wind['speed']['mps'] = $wind['speed']['m/s'];
// And then generate an image for this wind value. The image will be generated by yr.no's servers,
// so we need to set up the parameters with the correct values.
// First, we round the degrees to the nearest 5, and make sure it's a 3-digit number.
$deg = $vars['dir']['deg'] - $vars['dir']['deg'] % 5;
// Add leading zeroes as necessary.
if (drupal_strlen($deg) == 2) {
$deg = '0' . $deg;
}
elseif (drupal_strlen($deg) == 1) {
$deg = '00' . $deg;
}
// 360 degrees doesn't work in the url, but 000 does.
$deg = $deg == 360 ? '000' : $deg;
// Then we set up the speed to supply in the URL. It's supplied to the nearest 2.5, but in the URL,
// it's multiplied by 10.
$speed = $vars['speed']['mps'] * 10;
$speed = round($speed / 25) * 25;
// Speed may also need leading zeroes, but as a 4-digit number.
if (drupal_strlen($speed) == 3) {
$speed = '0' . $speed;
}
elseif (drupal_strlen($speed) == 2) {
$speed = '00' . $speed;
}
elseif (drupal_strlen($speed) == 1) {
$speed = '000' . $speed;
}
// Create the <img>.
$unit = variable_get('yr_verdata_windspeed_unit', 'm/s');
$url = variable_get('yr_verdata_wind_url', 'http://fil.nrk.no/yr/grafikk/vindpiler/32/') . 'vindpil.' . $speed . '.' . $deg . '.png';
$windtext = $wind['dirname'] . ', ' . $wind['speedname'] . ', ' . $wind['speed'][$unit] . ' ' . $unit;
return theme('image', array(
'path' => $url,
'alt' => $windtext,
'title' => $windtext,
));
}