First round of commits for the Kronolith Event Map.
authorMichael J. Rubinsky <mrubinsk@horde.org>
Sat, 28 Nov 2009 21:29:11 +0000 (16:29 -0500)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Sat, 28 Nov 2009 21:29:11 +0000 (16:29 -0500)
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
kronolith/index.php
kronolith/js/kronolith.js
kronolith/lib/Kronolith.php
kronolith/templates/index/edit.inc
kronolith/themes/screen.css

index 5f339f5..8b52623 100644 (file)
    </values>
   </configmultienum>
  </configsection>
+
+ <configsection name="maps">
+  <configheader>Maps</configheader>
+  <configswitch name="driver" desc="Which driver should we use for inline maps?">
+   <case name="false" desc="No inline map support" />
+   <case name="Horde" desc="Horde driver (support for various map providers)">
+    <configmultienum name="providers" desc="Which layers should we add to the map?">
+     <values>
+      <value desc="Google">Google</value>
+      <value desc="Yahoo">Yahoo</value>
+      <value desc="Virtual Earth/Bing">Ve</value>
+      <value desc="Various Open Sources">Public</value>
+     </values>
+    </configmultienum>
+   </case>
+   <case name="SAPO" desc="Driver for SAPO Mapas API">
+   </case>
+  </configswitch>
+  <configenum default="false" name="geocoder" desc="Which Geocoder service
+  should we use?">
+    <values>
+     <value desc="None" default="true">false</value>
+     <value desc="Google">Google</value>
+     <value desc="Yahoo">Yahoo</value>
+     <value desc="SAPO">SAPO</value>
+    </values> 
+  </configenum>
+ </configsection>
 </configuration>
index 706985b..cd074bb 100644 (file)
@@ -31,6 +31,7 @@ echo "<body class=\"kronolithAjax\">\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();
index 70d69cb..5b7eeee 100644 (file)
@@ -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));
index 5a35835..3c76e6a 100644 (file)
@@ -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()) . ';');
     }
 
index 9ce11f7..a431e6a 100644 (file)
@@ -51,7 +51,8 @@
     <li><a href="#" class="kronolithTabLink" id="kronolithEventLinkRecur"><?php echo _("Repeat") ?></a></li>
     <li><a href="#" class="kronolithTabLink" id="kronolithEventLinkUrl"><?php echo _("URL") ?></a></li>
     <li><a href="#" class="kronolithTabLink" id="kronolithEventLinkAttendees"><?php echo _("Attendees") ?></a></li>
-     <li><a href="#" class="kronolithTabLink" id="kronolithEventLinkTags"><?php echo _("Tags") ?></a></li>
+    <li><a href="#" class="kronolithTabLink" id="kronolithEventLinkTags"><?php echo _("Tags") ?></a></li>
+    <li><a href="#" class="kronolithTabLink" id="kronolithEventLinkMap"><?php echo _("Map") ?></a></li>
   </ul>
 </div>
 <br class="clear" />
   <div class="kronolithTopTags" id="kronolithEventTopTags"></div>
 </div>
 
+<div id="kronolithEventTabMap" class="kronolithTabsOption" style="display:none;">
+  <div id="kronolithEventMap"></div>
+</div>
+
 <div class="kronolithFormActions">
   <input id="kronolithEventSave" type="button" value="<?php echo _("Save") ?>" class="button ok" />
   <input id="kronolithEventDelete" type="button" value="<?php echo _("Delete") ?>" class="button ko" />
index 99be717..dd25caf 100644 (file)
@@ -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;