this.eventTagAc.shutdown();
$('kronolithEventSave').disable();
$('kronolithEventSaveAsNew').disable();
+ if (this.mapInitialized) {
+ $('kronolithEventMapZoom').value = this.map.getZoom();
+ }
this.startLoading(target, start + end);
this.doAction('saveEvent',
$H($('kronolithEventForm').serialize({ hash: true }))
if (ev.gl) {
$('kronolithEventLocationLat').value = ev.gl.lat;
$('kronolithEventLocationLon').value = ev.gl.lon;
+ $('kronolithEventMapZoom').value = ev.gl.zoom;
}
if (!ev.pe) {
if ($('kronolithEventLocationLat').value) {
var ll = { lat:$('kronolithEventLocationLat').value, lon: $('kronolithEventLocationLon').value };
-
- // @TODO: a default/configurable default zoom level?
- this.placeMapMarker(ll, true, 8);
+ // Note that we need to cast the value of zoom to an integer here,
+ // otherwise the map display breaks.
+ this.placeMapMarker(ll, true, $('kronolithEventMapZoom').value - 0);
}
//@TODO: check for Location field - and if present, but no lat/lon value, attempt to
// geocode it.
this.mapInitialized = false;
$('kronolithEventLocationLat').value = null;
$('kronolithEventLocationLon').value = null;
+ $('kronolithEventMapZoom').value = null;
if (this.mapMarker) {
this.map.removeMarker(this.mapMarker);
this.mapMarker = null;
/**
* Callback for geocoding calls.
- * @TODO: Figure out the proper zoom level based on the detail of the
- * provided address.
*/
onGeocode: function(r)
{
r = r.shift();
- this.placeMapMarker({ lat: r.lat, lon: r.lon }, true);
+ if (r.precision) {
+ zoom = r.precision * 2;
+ } else {
+ zoom = null;
+ }
+ this.placeMapMarker({ lat: r.lat, lon: r.lon }, true, zoom);
},
geocode: function(a) {
},
/**
- * Place the event marker on the map, ensuring it exists.
- * See note in onGeocode about zoomlevel
+ * Place the event marker on the map, at point ll, ensuring it exists.
+ * Optionally center the map on the marker and zoom. Zoom only honored if
+ * center is set, and if center is set, but zoom is null, we zoomToFit().
+ *
*/
placeMapMarker: function(ll, center, zoom)
{
$('kronolithEventLocationLat').value = ll.lat;
if (center) {
this.map.setCenter(ll, zoom);
+ if (!zoom) {
+ this.map.zoomToFit();
+ }
}
},
this.mapMarker = false;
},
+ /**
+ * Ensures the map tab is visible and sets UI elements accordingly.
+ */
ensureMap: function()
{
if (!this.mapInitialized) {
return;
}
+ if (empty($point['zoom'])) {
+ $point['zoom'] = 0;
+ }
+
/* INSERT or UPDATE */
if ($count) {
- $sql = sprintf('UPDATE kronolith_events_geo SET event_coordinates = GeomFromText(\'POINT(%F %F)\') WHERE event_id = ?', $point['lat'], $point['lon']);
+ $sql = sprintf('UPDATE kronolith_events_geo SET event_coordinates = GeomFromText(\'POINT(%F %F)\'), event_zoom = ? WHERE event_id = ?', $point['lat'], $point['lon']);
} else {
- $sql = sprintf('INSERT into kronolith_events_geo (event_id, event_coordinates) VALUES(?, GeomFromText(\'POINT(%F %F)\'))', $point['lat'], $point['lon']);
+ $sql = sprintf('INSERT into kronolith_events_geo (event_id, event_coordinates, event_zoom) VALUES(?, GeomFromText(\'POINT(%F %F)\'), ?)', $point['lat'], $point['lon']);
}
Horde::logMessage(sprintf('Kronolith_Geo_Mysql::setLocation(): user = "%s"; query = "%s"; values = "%s"',
$GLOBALS['registry']->getAuth(), $sql, $event_id), 'DEBUG');
- $result = $this->_write_db->query($sql, array($event_id));
+ $result = $this->_write_db->query($sql, array($event_id, $point['zoom']));
if ($result instanceof PEAR_Error) {
Horde::logMessage($result, 'ERR');
throw new Horde_Exception($result);
*/
public function getLocation($event_id)
{
- $sql = 'SELECT x(event_coordinates) as lat, y(event_coordinates) as lon FROM kronolith_events_geo WHERE event_id = ?';
+ $sql = 'SELECT x(event_coordinates) as lat, y(event_coordinates) as lon, event_zoom as zoom FROM kronolith_events_geo WHERE event_id = ?';
Horde::logMessage(sprintf('Kronolith_Geo_Mysql::getLocation(): user = "%s"; query = "%s"; values = "%s"',
$GLOBALS['registry']->getAuth(), $sql, $event_id), 'DEBUG');
$result = $this->_db->getRow($sql, array($event_id), DB_FETCHMODE_ASSOC);
}
/* Do we actually have data? If not, see if we are deleting an
- * existing entry.
- */
+ * existing entry. */
if ((empty($point['lat']) || empty($point['lon'])) && $count) {
// Delete the record.
$this->deleteLocation($event_id);
return;
}
+ if (empty($point['zoom'])) {
+ $point['zoom'] = 0;
+ }
+
/* INSERT or UPDATE */
- $params = array($point['lat'], $point['lon'], $event_id);
+ $params = array($point['lat'], $point['lon'], $point['zoom'], $event_id);
if ($count) {
- $sql = 'UPDATE kronolith_events_geo SET event_lat = ?, event_lon = ? WHERE event_id = ?';
+ $sql = 'UPDATE kronolith_events_geo SET event_lat = ?, event_lon = ?, event_zoom = ? WHERE event_id = ?';
} else {
- $sql = 'INSERT into kronolith_events_geo (event_lat, event_lon, event_id) VALUES(?, ?, ?)';
+ $sql = 'INSERT into kronolith_events_geo (event_lat, event_lon, event_zoom, event_id) VALUES(?, ?, ?, ?)';
}
Horde::logMessage(sprintf('Kronolith_Geo_Sql::setLocation(): user = "%s"; query = "%s"; values = "%s"',
$GLOBALS['registry']->getAuth(), $sql, print_r($params, true)), 'DEBUG');
*/
public function getLocation($event_id)
{
- $sql = 'SELECT event_lat as lat, event_lon as lon FROM kronolith_events_geo WHERE event_id = ?';
+ $sql = 'SELECT event_lat as lat, event_lon as lon, event_zoom as zoom FROM kronolith_events_geo WHERE event_id = ?';
Horde::logMessage(sprintf('Kronolith_Geo_Sql::getLocation(): user = "%s"; query = "%s"; values = "%s"',
$GLOBALS['registry']->getAuth(), $sql, $event_id), 'DEBUG');
$result = $this->_db->getRow($sql, array($event_id), DB_FETCHMODE_ASSOC);
--- /dev/null
+ALTER TABLE kronolith_events_geo ADD COLUMN event_zoom INTEGER DEFAULT 0 NOT NULL;
<input id="kronolithEventCalendar" type="hidden" name="cal" />
<input id="kronolithEventLocationLon" type="hidden" name="lon" />
<input id="kronolithEventLocationLat" type="hidden" name="lat" />
+<input id="kronolithEventMapZoom" type="hidden" name="zoom" />
<div>
<label for="kronolithEventTitle">