Implement forward/reverse geocoding, along with some changes to standardize
authorMichael J. Rubinsky <mrubinsk@horde.org>
Sun, 29 Nov 2009 23:29:49 +0000 (18:29 -0500)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Sun, 29 Nov 2009 23:32:00 +0000 (18:32 -0500)
return values from various methods from each hordemap driver.

When marker is moved, new textual location is filled in the Location field
(if able), if new location is typed into Location field, and "Find In Maps" is
clicked, the marker will move to that location if found.

kronolith/js/kronolith.js
kronolith/templates/index/edit.inc

index 774e26e..c62d6c0 100644 (file)
@@ -3480,7 +3480,8 @@ KronolithEventMap =
                 {
                     'elt': 'kronolithEventMap',
                     'delayed': true,
-                    'layers': layers
+                    'layers': layers,
+                    'markerDragEnd': this.onMarkerDragEnd.bind(this)
                 });
         this._map.display();
         this._marker = this._map.addMarker(
@@ -3491,8 +3492,8 @@ KronolithEventMap =
                     'dragend': this.onMarkerDragEnd
                 });
 
-                this._map.setCenter({lat:38.7115479, lon: -9.13774}, 10);
-                this._initialized = true;
+        this._map.setCenter({lat:38.7115479, lon: -9.13774}, 10);
+        this._initialized = true;
    },
 
    isInitialized: function()
@@ -3500,13 +3501,29 @@ KronolithEventMap =
        return this._initialized;
    },
 
+   /**
+    * Callback for handling marker drag end.
+    *
+    * @param object r  An object that implenents a getLonLat() method to obtain
+    *                  the new location of the marker.
+    */
    onMarkerDragEnd: function(r)
    {
+       var ll = r.getLonLat();
        var gc = new HordeMap.Geocoder[Kronolith.conf.maps.geocoder]();
-       gc.reverseGeocode(r.getLonLat(), this.onReverseGeocode.bind(this), this.onError.bind(this) );
+       gc.reverseGeocode(ll, this.onReverseGeocode.bind(this), this.onError.bind(this) );
    },
 
-   onReverseGeocode: function(r) { $('kronolithEventLocation').value = r; },
+   /**
+    * Callback for handling a reverse geocode request.
+    *
+    * @param array r  An array of objects containing the results. Each object in
+    *                 the array is {lat:, lon:, address}
+    */
+   onReverseGeocode: function(r) {
+       $('kronolithEventLocation').value = r[0].address;
+       // Do something else with the lonlat?
+   },
 
    onError: function(r) {  },
 
@@ -3516,8 +3533,8 @@ KronolithEventMap =
        var gc = new HordeMap.Geocoder[Kronolith.conf.maps.geocoder]();
        gc.geocode(a, function(r) {
            r = r.shift();
-           ll = new OpenLayers.LonLat(r.Longitude, r.Latitude);
-           //this._marker.setLonLat(ll);
+           ll = new OpenLayers.LonLat(r.lon, r.lat);
+           this._map.moveMarker(this._marker, { lat: r.lat, lon: r.lon });
            this._map.setCenter(ll);
        }.bind(this),
        this.onError);
index a431e6a..a6bf4f4 100644 (file)
@@ -18,7 +18,7 @@
   <td>
     <label for="kronolithEventLocation"><?php echo _("Location") ?>:</label><br />
     <input type="text" name="location" id="kronolithEventLocation" size="40" />
-    &middot; <span class="kronolithEventGeo"><a href="#"><?php echo _("Find in Maps") ?></a></span>
+    &middot; <span><a class="kronolithEventGeo" href="#"><?php echo _("Find in Maps") ?></a></span>
   </td>
 </tr></tbody></table>
 </div>