You are here

function yr_verdata_radar in Yr Weatherdata 7

Same name and namespace in other branches
  1. 6.2 yr_verdata.module \yr_verdata_radar()

Function for generating the necessary stuff for a radarimage.

Parameters

$data: The loaded xml for this location.

Return value

Returns an array with 'url' for the image url at api.yr.no, 'link' for the link to the radarpage at the location's page at yr.no and 'text' for the text used as alt and title for the image.

1 call to yr_verdata_radar()
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…

File

./yr_verdata.module, line 601
yr_verdata.module This file contains the code for getting the forecast from yr.no and displaying it on a Drupal site.

Code

function yr_verdata_radar($data) {
  $lat = (int) $data->location->location['latitude'];
  $long = (int) $data->location->location['longitude'];
  $radarsite = FALSE;

  // Figure out which radarimage to use. Start narrow in the south and expand if lat/long is outside range.
  // Finally set $showradar = FALSE; if no compatible lat/long range is found.
  if ($lat >= 57 && $lat < 61 && $long >= 4 && $long < 7) {
    $radarsite = 'southwest_norway';
    $radartext = t('Southwest-Norway');
  }
  elseif ($lat >= 57 && $lat < 61 && $long >= 7 && $long <= 13) {
    $radarsite = 'southeast_norway';
    $radartext = t('Southeast-Norway');
  }
  elseif ($lat >= 60 && $lat < 62 && $long >= 4 && $long < 8) {
    $radarsite = 'western_norway';
    $radartext = t('Western Norway');
  }
  elseif ($lat >= 62 && $lat < 66 && $long >= 4 && $long <= 14) {
    $radarsite = 'central_norway';
    $radartext = t('Central Norway');
  }
  elseif ($lat >= 57 && $lat < 66 && $long >= 4 && $long <= 14) {
    $radarsite = 'south_norway';
    $radartext = t('Southern Norway');
  }
  elseif ($lat >= 65 && $lat < 69 && $long > 10 && $long <= 18) {
    $radarsite = 'nordland_troms';
    $radartext = t('Northern Norway');
  }
  elseif ($lat >= 68 && $lat < 72 && $long > 17 && $long <= 30) {
    $radarsite = 'troms_finnmark';
    $radartext = t('Northernmost Norway');
  }
  else {
    $radarsite = FALSE;
  }
  if ($radarsite == TRUE) {
    $radar['url'] = 'http://api.yr.no/weatherapi/radar/1.2/?radarsite=' . $radarsite . ';width=460;type=animation';
    $radar['link'] = !empty($data->links->link[5]['url']) ? check_url($data->links->link[5]['url']) : check_url($data->links->link[1]['url']);
    $radar['text'] = t('Radarimage for !location', array(
      '!location' => $radartext,
    ));
  }
  else {
    $radar = FALSE;
  }
  return $radar;
}