? weather/cvs
? weather/images/cvs
? weather/images/svg/cvs
? weather/po/cvs
? weather/weather-4-3-0/cvs
Index: weather/weather.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/weather/weather.module,v
retrieving revision 1.151
diff -r1.151 weather.module
2c2
< /*
---
> /* $Id$
109a110
>      $block[3]['info'] = t('Weather: node location');
142a144,218
>     else if ($delta == 3 and user_access('access content')) {
>       // show the local weather block
>       if (arg(0)=='node' && is_numeric(arg(1))) {
>         return weather_location_block_view(arg(1));
>       }
>       return NULL;
>     }
> 
>   }
> }
> 
> /**
>  * Return a block displaying current weather for the location assigned to this
>  * node (via location.module)
>  * 
>  * @param Node ID
>  * @return A Block definition, or NULL
>  */
> function weather_location_block_view($nid) {
>   $block = array();
>   $node = node_load($nid);
>   if (isset($node->location['latitude']) && isset($node->location['longitude'])) {
>     $block['subject'] = t('Current Weather Nearby');
>     $nearest_station = weather_get_icao_from_lat_lon($node->location['latitude'], $node->location['longitude']);
> 
>     // TODO Allow settings configs for this type of block?
>     $config = _weather_get_config(0, 1);
>     $config = array_merge($config, $nearest_station);
>     $config['real_name'] = $config['name'];
> 
>     $metar = weather_get_metar($nearest_station['icao']);
>     $block['content'] .= theme('weather', $config, $metar);
>     return $block;
>   }
>   // else no lat/lon
>   return NULL;
> }
> 
> /**
>  * Given a latitude and longitude, return the details of the nearest known
>  * weather station. It's distance and direction away from the request (in km) is
>  * returned in the result array.
>  */
> function weather_get_icao_from_lat_lon($latitude, $longitude) {
>   // This (pythagorean) proximity search here is inaccurate - it draws a circle around the base
>   // and target point ASSUMING A FLAT MAP GRID. The real maths (below) are probably
>   // too heavy for a DB query.
>   // So we take the top 5 near guesses, and then do the real calcs on just them.
>   // It's pretty extreme cases (like >6 stations within miles of each other at the pole)
>   // where that estimate won't be good enough.
>   
>   $sql = "SELECT *, ((%d-latitude) * (%d-latitude) + (%d-longitude)*(%d-longitude)) as square_dist_away FROM {weather_icao} ORDER BY square_dist_away LIMIT 5";
>   $result = db_query($sql, $latitude, $latitude, $longitude, $longitude);
> 
>   $nearest = NULL;
>   while ( $row = db_fetch_array($result) ) {
>     $d = earth_distance($longitude, $latitude, $row['longitude'], $row['latitude']);
>     // I believe that returned metres :-/
>     
>     if (! isset($nearest) || $d < $nearest) {
>       // Make a note of the true nearest result.
>       $nearest = $d;
>       $row['distance'] = $d/1000;
>       
>       // Calculate bearing
>       $lat1 = deg2rad($latitude);
>       $lat2 = deg2rad($row['latitude']);
>       $dlon = deg2rad($row['longitude']-$longitude);
>       $y = sin($dlon) * cos($lat2);
>       $x = cos($lat1)*sin($lat2) -
>           sin($lat1)*cos($lat2)*cos($dlon);
>       $row['bearing'] = rad2deg( atan2($y, $x) );
>       
>       $station = $row;
>     }
143a220
>   return $station;
145a223,246
> /**
>  * Given a compass bearing (0' = North, 90' = East ...) return the text labels,
>  * North, North-Northeast, Northeast etc.
>  * 
>  * @param direction in degrees, 0 to 360 (or -180 also OK)
>  * @param $abbrev if set, return the shorthand label of the direction
>  * 
>  * @todo translate these? Is there a tidy way? Has someone else already done it
>  * in a library?
>  */
> function weather_degress_to_compass_points($deg, $abbrev = FALSE) {
>   while ($deg < 0) {$deg = $deg + 360;} 
>   while ($deg > 360) {$deg = $deg - 360;} 
>   $sector = floor(($deg+11.25)/22.5);
> 
>   if ($abbrev) {
>     $abbrev_points = array('N', 'NNE', 'NE', 'ENE', 'E', 'ESE', 'SE', 'SSE', 'S', 'SSW', 'SW', 'WSW', 'W', 'WNW', 'NW', 'NNW');
>     return $abbrev_points[$sector];
>   }
>   else {
>     $points = array('North', 'North-NorthEast', 'NorthEast', 'East-NorthEast', 'East', 'East-SouthEast', 'SouthEast', 'South-SouthEast', 'South', 'South-SouthWest', 'SouthWest', 'West-SouthWest', 'West', 'West-NorthWest', 'NorthWest', 'North-NorthWest');
>     return $points[$sector];
>   }
> }
151a253,255
>   if ($config['distance']) {
>     $content .= t("Closest weather station %distance away %direction", array('%distance' => floor($config['distance']) ." km", '%direction' => weather_degress_to_compass_points( $config['bearing'] )) ) ;
>   }
