From e8d522b1b10237f85155e0cb10167f558095a325 Mon Sep 17 00:00:00 2001 From: "Michael J. Rubinsky" Date: Sat, 28 Nov 2009 16:29:11 -0500 Subject: [PATCH] First round of commits for the Kronolith Event Map. Displaying the map is working for all drivers, SAPO also has minimal reverse geocoding implemented. Still need to hook forward geocoding into changing the Location box, and the Horde map driver still needs draggable markers to be implemented, but the SAPO driver has them already. Also, still need to tie in the location data storage --- kronolith/config/conf.xml | 28 +++++++++++++++ kronolith/index.php | 1 + kronolith/js/kronolith.js | 71 ++++++++++++++++++++++++++++++++++++++ kronolith/lib/Kronolith.php | 52 ++++++++++++++++++++++++++++ kronolith/templates/index/edit.inc | 7 +++- kronolith/themes/screen.css | 17 +++++++++ 6 files changed, 175 insertions(+), 1 deletion(-) diff --git a/kronolith/config/conf.xml b/kronolith/config/conf.xml index 5f339f51b..8b5262307 100644 --- a/kronolith/config/conf.xml +++ b/kronolith/config/conf.xml @@ -90,4 +90,32 @@ + + + Maps + + + + + + Google + Yahoo + Ve + Public + + + + + + + + + false + Google + Yahoo + SAPO + + + diff --git a/kronolith/index.php b/kronolith/index.php index 706985b8f..cd074bbb4 100644 --- a/kronolith/index.php +++ b/kronolith/index.php @@ -31,6 +31,7 @@ echo "\n"; require KRONOLITH_TEMPLATES . '/index/index.inc'; Horde::includeScriptFiles(); Horde::outputInlineScript(); +Kronolith::initEventMap($conf['maps']); $notification->notify(array('listeners' => array('javascript'))); $tac = Horde_Ajax_Imple::factory(array('kronolith', 'TagAutoCompleter'), array('triggerId' => 'kronolithEventTags', 'box' => 'kronolithEventACBox', 'pretty' => true)); $tac->attach(); diff --git a/kronolith/js/kronolith.js b/kronolith/js/kronolith.js index 70d69cbb4..5b7eeee4d 100644 --- a/kronolith/js/kronolith.js +++ b/kronolith/js/kronolith.js @@ -2799,6 +2799,12 @@ KronolithCore = { dialog.select('.tabset li').invoke('removeClassName', 'activeTab'); $(id.replace(/Link/, 'Tab')).show(); elt.parentNode.addClassName('activeTab'); + if (id == 'kronolithEventLinkMap') { + /* Maps */ + if (!Object.isUndefined(KronolithEventMap) && !KronolithEventMap.isInitialized()) { + KronolithEventMap.initialize(); + } + } e.stop(); return; @@ -3446,6 +3452,71 @@ KronolithCore = { }; +KronolithEventMap = +{ + _marker: null, + _map: null, + _initialized: false, + + initialize: function() + { + var layers = []; + if (Kronolith.conf.maps.providers) { + Kronolith.conf.maps.providers.each(function(l) + { + var p = new HordeMap[l](); + $H(p.getLayers()).values().each(function(e) { layers.push(e); }); + }); + } + + this._map = new HordeMap.Map[Kronolith.conf.maps.driver]( + { + 'elt': 'kronolithEventMap', + 'delayed': true, + 'layers': layers + }); + this._map.display(); + this._marker = this._map.addMarker( + {lat:38.7115479, lon: -9.13774}, + {'draggable': true}, + { + 'context': this, + 'dragend': this.onMarkerDragEnd + }); + + this._map.setCenter({lat:38.7115479, lon: -9.13774}, 10); + this._initialized = true; + }, + + isInitialized: function() + { + return this._initialized; + }, + + onMarkerDragEnd: function(r) + { + var gc = new HordeMap.Geocoder[Kronolith.conf.maps.geocoder](); + gc.reverseGeocode(r.getLonLat(), this.onReverseGeocode.bind(this), this.onError.bind(this) ); + }, + + onReverseGeocode: function(r) { $('kronolithEventLocation').value = r; }, + + onError: function(r) { }, + + onGeocode: function(r) { }, + + geocode: function(a) { + var gc = new HordeMap.Geocoder[Kronolith.geocoderType](); + gc.geocode(a, function(r) { + r = r.shift(); + ll = new OpenLayers.LonLat(r.Longitude, r.Latitude); + //this._marker.setLonLat(ll); + this._map.setCenter(ll); + }.bind(this), + this.onError); + } +}; + /* Initialize global event handlers. */ document.observe('dom:loaded', KronolithCore.onDomLoad.bind(KronolithCore)); Event.observe(window, 'resize', KronolithCore.onResize.bind(KronolithCore)); diff --git a/kronolith/lib/Kronolith.php b/kronolith/lib/Kronolith.php index 5a3583551..3c76e6ae3 100644 --- a/kronolith/lib/Kronolith.php +++ b/kronolith/lib/Kronolith.php @@ -105,6 +105,55 @@ class Kronolith } /** + * Initialize the event map. + * + * @param array $params Parameters to pass the the map + * + * @return void + */ + public static function initEventMap($params) + { + // Add the apikeys + if (!empty($params['layers'])) { + foreach ($params['layers'] as $layer) { + switch ($layer) { + case 'Google': + $params['apikeys']['google'] = $GLOBALS['conf']['api']['googlemaps']; + break; + case 'Yahoo': + $params['apikeys']['yahoo'] = $GLOBALS['conf']['api']['yahoomaps']; + break; + //case 'Ve': + // none needed. + case 'Cloudmade': + $params['apikeys']['cloudemade'] = $GLOBALS['conf']['api']['cloudemade']; + break; + } + } + } + + if (!empty($params['geocoder'])) { + switch ($params['geocoder']) { + case 'Google': + $params['apikeys']['google'] = $GLOBALS['conf']['api']['googlemaps']; + break; + case 'Yahoo': + $params['apikeys']['yahoo'] = $GLOBALS['conf']['api']['yahoomaps']; + break; + //case 'Ve': + // none needed. + case 'Cloudmade': + $params['apikeys']['cloudemade'] = $GLOBALS['conf']['api']['cloudemade']; + break; + } + } + + Horde::addScriptFile('hordemap/map.js', 'horde'); + $js = 'HordeMap.initialize(' . Horde_Serialize::serialize($params, HORDE_SERIALIZE::JSON) . ');'; + Horde::addinlineScript($js); + } + + /** * Outputs the javascript code which defines all javascript variables * that are dependent on the local user's account. * @@ -269,6 +318,9 @@ class Kronolith $code['text']['recur'][$recurType] = self::recurToString($recurType); } + // Maps + $code['conf']['maps'] = $GLOBALS['conf']['maps']; + return array('var Kronolith = ' . Horde_Serialize::serialize($code, Horde_Serialize::JSON, Horde_Nls::getCharset()) . ';'); } diff --git a/kronolith/templates/index/edit.inc b/kronolith/templates/index/edit.inc index 9ce11f756..a431e6a71 100644 --- a/kronolith/templates/index/edit.inc +++ b/kronolith/templates/index/edit.inc @@ -51,7 +51,8 @@
  • -
  • +
  • +

  • @@ -165,6 +166,10 @@
    + +
    " class="button ok" /> " class="button ko" /> diff --git a/kronolith/themes/screen.css b/kronolith/themes/screen.css index 99be71770..dd25caf19 100644 --- a/kronolith/themes/screen.css +++ b/kronolith/themes/screen.css @@ -728,11 +728,28 @@ div.kronolithFormActions { #kronolithEventTabAttendees th.night { background-color: #ccc; } + #kronolithEventTabAttendees td div { margin: 0; height: 100%; } +/* Map */ +#kronolithEventMap { + height: 400px; + width: 700px; +} +#kronolithEventMap_OpenLayers_ViewPort div { + margin-bottom: 0; +} +.olMapViewPort div { + margin-bottom: 0; +} +.olControlLayerSwitcher div { + line-height: 100%; + margin-bottom: 0px; +} + /* Mini calendar */ .kronolithMinical { position: relative; -- 2.11.0