From 9015160199506f271f8758c9b284b1d56bae860b Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Thu, 14 Aug 2014 06:32:47 +0300 Subject: [PATCH] HTML: Add coordinates to the HTML exports - Export dive coordinates (if exist) to JSON file. - Add dive coordinates to list view and detailed dive view. - Add hyperlink that opens the dive location in a new tab viewed in Google maps. Signed-off-by: Gehad elrobey Signed-off-by: Miika Turkia Signed-off-by: Dirk Hohndel --- save-html.c | 18 +++++++++++++++++- theme/list_lib.js | 31 +++++++++++++++++++++++++++---- 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/save-html.c b/save-html.c index 1efc6b96a..0288d447c 100644 --- a/save-html.c +++ b/save-html.c @@ -122,6 +122,21 @@ void put_HTML_samples(struct membuffer *b, struct dive *dive) put_string(b, "],"); } +void put_HTML_coordinates(struct membuffer *b, struct dive *dive) +{ + degrees_t latitude = dive->latitude; + degrees_t longitude = dive->longitude; + + //don't put coordinates if in (0,0) + if (!latitude.udeg && !longitude.udeg) + return; + + put_string(b, "\"coordinates\":{"); + put_degrees(b, latitude, "\"lat\":\"", "\","); + put_degrees(b, longitude, "\"lon\":\"", "\","); + put_string(b, "},"); +} + void put_HTML_date(struct membuffer *b, struct dive *dive, const char *pre, const char *post) { struct tm tm; @@ -207,6 +222,7 @@ void write_one_dive(struct membuffer *b, struct dive *dive, const char *photos_d put_HTML_date(b, dive, "\"date\":\"", "\","); put_HTML_time(b, dive, "\"time\":\"", "\","); write_attribute(b, "location", dive->location); + put_HTML_coordinates(b, dive); put_format(b, "\"rating\":%d,", dive->rating); put_format(b, "\"visibility\":%d,", dive->visibility); put_format(b, "\"dive_duration\":\"%u:%02u min\",", @@ -390,7 +406,7 @@ void export_translation(const char *file_name) write_attribute(b, "Events", translate("gettextFromC", "Events")); write_attribute(b, "Name", translate("gettextFromC", "Name")); write_attribute(b, "Value", translate("gettextFromC", "Value")); - + write_attribute(b, "Coordinates", translate("gettextFromC", "Coordinates")); write_attribute(b, "Dive_Status", translate("gettextFromC", "Dive Status")); put_format(b, "}"); diff --git a/theme/list_lib.js b/theme/list_lib.js index abd790178..c5171ce11 100644 --- a/theme/list_lib.js +++ b/theme/list_lib.js @@ -208,7 +208,7 @@ function getExpanded(dive) { var res = '
' + translate.Date + ': ' + dive.date + '     ' + translate.Time + ': ' + dive.time + - '     ' + translate.Location + ': ' + '' + dive.location + '' + + '     ' + translate.Locaiton + ': ' + '' + dive.location + '' + getDiveCoor(dive) + '
' + translate.Rating + ':' + putRating(dive.rating) + '   ' + translate.Visibility + ':' + putRating(dive.visibility) + '
' + @@ -499,7 +499,7 @@ Set.prototype.intersect = function(another_set) } var result = new Array(); for (var i = 0; i < another_set.keys.length; i++) { - if(this.contains(another_set.keys[i])) { + if (this.contains(another_set.keys[i])) { result.push(another_set.keys[i]); } }; @@ -896,6 +896,21 @@ function get_bookmarks_HTML(dive) return result; } +function getDiveCoorString(coordinates){ + res = ""; + lat = coordinates.lat; + lon = coordinates.lon; + res += float_to_deg(lat) + ' , ' + float_to_deg(lon); + return res; +} + +function getDiveCoor(dive) +{ + if (!dive.coordinates) + return ""; + return '     ' + translate.Coordinates + ': ' + '' + getDiveCoorString(dive.coordinates) + ''; +} + /** *Return HTML main data of a dive */ @@ -903,8 +918,8 @@ function get_dive_HTML(dive) { var res = '

' + translate.Dive_information + '

' + translate.Date + ': ' + dive.date + '     ' + translate.Time + ': ' + dive.time + - '     ' + translate.Location + ': ' + '' + dive.location + '' + - '
' + getDiveCoor(dive) + + '
' + translate.Rating + ':' + putRating(dive.rating) + + '     ' + translate.Locaiton + ': ' + '' + dive.location + '
' + translate.Rating + ':' + putRating(dive.rating) + '   ' + translate.Visibility + ':' + putRating(dive.visibility) + '
' + '
' + translate.Air_Temp + ': ' + dive.temperature.air + @@ -1000,6 +1015,14 @@ function int_to_time(n) return Math.floor((n) / 60) + ":" + format_two_digit((n) % (60)) + " min"; } +function float_to_deg(flt){ + var deg = 0 | flt; + flt = (flt < 0 ? flt =- flt : flt); + var min = 0 | flt % 1 * 60; + var sec = (0 | flt * 60 % 1 * 6000) / 100; + return deg + "° " + min + "' " + sec + "\""; +} + /** *Main canvas draw function *this calls the axis and grid initialization functions.