Skip to content

Commit

Permalink
First pass at adding a OpenWeatherMap based weather map.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrubinsk committed Sep 21, 2015
1 parent 42e347a commit 8b92c00
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 10 deletions.
77 changes: 77 additions & 0 deletions framework/Core/js/map/owm.js
@@ -0,0 +1,77 @@
/**
* OpenWeatherMap layer (See http://openweathermap.org/tile_map#list)
*
* Copyright 2015 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (GPL). If you
* did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
*
* @author Michael J. Rubinsky <mrubinsk@horde.org>
*
*/
HordeMap.Owm = Class.create(
{
initialize: function(opts)
{
},

getLayers: function(layer)
{
return {
'clouds': new OpenLayers.Layer.XYZ(
'OpenWeatherMap Cloud Map',
['http://${s}.tile.openweathermap.org/map/clouds/${z}/${x}/${y}.png'],
{
'isBaseLayer': false,
'sphericalMercator': true,
'opacity': 0.7
}
),
'precipitation': new OpenLayers.Layer.XYZ(
'OpenWeatherMap Precipitation Map',
['http://${s}.tile.openweathermap.org/map/precipitation/${z}/${x}/${y}.png'],
{
'isBaseLayer': false,
'sphericalMercator': true,
'opacity': 0.7
}
),
'rain': new OpenLayers.Layer.XYZ(
'OpenWeatherMap Rain Map',
['http://${s}.tile.openweathermap.org/map/rain/${z}/${x}/${y}.png'],
{
'isBaseLayer': false,
'sphericalMercator': true,
'opacity': 0.7
}
),
'snow': new OpenLayers.Layer.XYZ(
'OpenWeatherMap Snow Map',
['http://${s}.tile.openweathermap.org/map/snow/${z}/${x}/${y}.png'],
{
'isBaseLayer': false,
'sphericalMercator': true,
'opacity': 0.7
}
),
'pressure_cntr': new OpenLayers.Layer.XYZ(
'OpenWeatherMap Sea-Level Pressure Map',
['http://${s}.tile.openweathermap.org/map/pressure_cntr/${z}/${x}/${y}.png'],
{
'isBaseLayer': false,
'sphericalMercator': true,
'opacity': 0.7
}
),
'wind': new OpenLayers.Layer.XYZ(
'OpenWeatherMap Wind Map',
['http://${s}.tile.openweathermap.org/map/wind/${z}/${x}/${y}.png'],
{
'isBaseLayer': false,
'sphericalMercator': true,
'opacity': 0.7
}
)
};
}
});
6 changes: 4 additions & 2 deletions framework/Core/package.xml
Expand Up @@ -28,7 +28,7 @@
<email>mrubinsk@horde.org</email>
<active>yes</active>
</developer>
<date>2015-09-07</date>
<date>2015-09-21</date>
<version>
<release>2.21.1</release>
<api>2.21.0</api>
Expand Down Expand Up @@ -238,6 +238,7 @@
<file name="OpenLayers-debug.js" role="horde" />
<file name="OpenLayers.js" role="horde" />
<file name="osm.js" role="horde" />
<file name="owm.js" role="horde" />
</dir> <!-- /js/map -->
<dir name="scriptaculous">
<file name="builder.js" role="horde" />
Expand Down Expand Up @@ -1626,6 +1627,7 @@
<install as="js/map/OpenLayers-debug.js" name="js/map/OpenLayers-debug.js" />
<install as="js/map/OpenLayers.js" name="js/map/OpenLayers.js" />
<install as="js/map/osm.js" name="js/map/osm.js" />
<install as="js/map/owm.js" name="js/map/owm.js" />
<install as="js/map/img/blank.gif" name="js/map/img/blank.gif" />
<install as="js/map/img/cloud-popup-relative.png" name="js/map/img/cloud-popup-relative.png" />
<install as="js/map/img/drag-rectangle-off.png" name="js/map/img/drag-rectangle-off.png" />
Expand Down Expand Up @@ -4027,7 +4029,7 @@
<stability>
<release>stable</release>
<api>stable</api></stability>
<date>2015-09-07</date>
<date>2015-09-21</date>
<license uri="http://www.horde.org/licenses/lgpl21">LGPL-2.1</license>
<notes>
* [mjr] Fix edge-case issue with ActiveSync folder list generation when installed application contains no user writable sources.
Expand Down
32 changes: 32 additions & 0 deletions horde/js/weatherblockmap.js
@@ -0,0 +1,32 @@
var WeatherBlockMap = {

// Map
initializeMap: function(instance, point)
{
if (this.mapInitialized) {
return;
}
var layers = [];
var p = new HordeMap.Owm();
$H(p.getLayers()).values().each(function(e) {
if (e.name == 'OpenWeatherMap Wind Map') {
e.visibility = false;
}
console.log(e);
layers.push(e);
});
p = new HordeMap.Osm();
$H(p.getLayers()).values().each(function(e) {
e.displayInLayerSwitcher = false;
layers.push(e);
});

var map = new HordeMap.Map['Horde']({
elt: 'weathermaplayer_' + instance,
layers: layers
});

map.display();
map.setCenter(point, 7);
}
}
19 changes: 16 additions & 3 deletions horde/lib/Block/Weather.php
Expand Up @@ -95,15 +95,19 @@ protected function _params()
),
'days' => array(
'type' => 'enum',
'name' => _("Forecast Days (note that the returned forecast returns both day and night; a large number here could result in a wide block)"),
'name' => _("Forecast Days (note that the returned forecast returns both day and night; a large number here could result in a wide block.)"),
'default' => 3,
'values' => $lengths
),
'detailedForecast' => array(
'type' => 'checkbox',
'name' => _("Display detailed forecast"),
'name' => _("Display detailed forecast?"),
'default' => 0
)
),
'showMap' => array(
'type' => 'checkbox',
'name' => _("Display the OpenWeatherMap map?"),
'default' => 0)
);
}

Expand Down Expand Up @@ -156,6 +160,15 @@ protected function _content()
return $e->getMessage();
}

if ($this->_params['showMap']) {
$view->map = true;
$GLOBALS['page_output']->addScriptFile('weatherblockmap.js', 'horde');
Horde_Core_HordeMap::init(array('providers' => array('owm', 'osm')));
$GLOBALS['page_output']->addInlineScript(array(
'WeatherBlockMap.initializeMap("' . $view->instance . '", { lat: "' . $view->location->lat . '", lon: "' . $view->location->lon . '"});$("weathermaplayer_' . $view->instance . '").show();'
), true);
}

return $view->render('block/weather');
}

Expand Down
6 changes: 4 additions & 2 deletions horde/package.xml
Expand Up @@ -28,7 +28,7 @@
<email>chuck@horde.org</email>
<active>no</active>
</lead>
<date>2015-09-08</date>
<date>2015-09-21</date>
<version>
<release>5.3.0</release>
<api>5.2.0</api>
Expand Down Expand Up @@ -253,6 +253,7 @@
<file name="twitterclient.js" role="horde" />
<file name="userupdate.js" role="horde" />
<file name="vatid.js" role="horde" />
<file name="weatherblockmap.js" role="horde" />
</dir> <!-- /js -->
<dir name="lib">
<dir name="Ajax">
Expand Down Expand Up @@ -2079,6 +2080,7 @@
<install as="js/twitterclient.js" name="js/twitterclient.js" />
<install as="js/userupdate.js" name="js/userupdate.js" />
<install as="js/vatid.js" name="js/vatid.js" />
<install as="Horde/js/weatherblockmap.js" name="js/weatherblockmap.js" />
<install as="js/plupload/plupload.browserplus.js" name="js/plupload/plupload.browserplus.js" />
<install as="js/plupload/plupload.flash.js" name="js/plupload/plupload.flash.js" />
<install as="js/plupload/plupload.flash.swf" name="js/plupload/plupload.flash.swf" />
Expand Down Expand Up @@ -4129,7 +4131,7 @@
<stability>
<release>beta</release>
<api>beta</api></stability>
<date>2015-09-08</date>
<date>2015-09-21</date>
<license uri="http://www.horde.org/licenses/lgpl">LGPL-2</license>
<notes>
* [mjr] Add configuration switch for disabling maillog synchronization with EAS clients (Bug #13747).
Expand Down
8 changes: 5 additions & 3 deletions horde/templates/block/weather.html.php
Expand Up @@ -89,7 +89,7 @@
<!-- Forecast -->
<?php if ($this->params['days'] > 0):?>
<div class="control"><strong><?php echo sprintf(_("%d-day forecast"), $this->params['days'])?></strong></div>
<?php if ($this->radar): ?>
<?php if ($this->radar || $this->map): ?>
<table class="horde-block-weather"><tr><td>
<?php endif;?>
<?php $futureDays = 0; ?>
Expand Down Expand Up @@ -139,12 +139,14 @@
<?php $futureDays++;?>
<?php endforeach;?>
</table>
<?php if ($this->radar):?>
<?php if ($this->radar || $this->map):?>
</td><td>
<div style="display:none;width:500px;height:300px;" id="weathermaplayer_<?php echo $this->instance?>">&nbsp;</div>
<?php echo $this->tag('img', array('src' => $this->radar));?></td></tr></table>

<?php endif;?>
<?php endif; ?>

<div style="display:none;width:500px;height:300px;" id="weathermaplayer_<?php echo $this->instance?>">&nbsp;</div>
<!-- Logo -->
<?php if ($this->logo):?>
<div class="rightAlign"><?php echo _("Weather data provided by") . ' ' . Horde::link(Horde::externalUrl($this->link), $this->title, '', '_blank', '', $this->title) . Horde_Themes_Image::tag($this->logo)?></a></div>
Expand Down

0 comments on commit 8b92c00

Please sign in to comment.