2017-04-27 18:18:03 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2017-03-11 20:08:31 +00:00
|
|
|
#ifdef __clang__
|
2016-03-09 18:20:07 +00:00
|
|
|
// Clang has a bug on zero-initialization of C structs.
|
|
|
|
#pragma clang diagnostic ignored "-Wmissing-field-initializers"
|
2017-03-11 20:08:31 +00:00
|
|
|
#endif
|
2016-03-09 18:20:07 +00:00
|
|
|
|
2014-03-30 20:14:56 +00:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
2014-05-23 18:49:49 +00:00
|
|
|
|
2020-05-01 11:43:52 +00:00
|
|
|
#include "dive.h"
|
2014-03-30 20:14:56 +00:00
|
|
|
#include "membuffer.h"
|
2019-03-04 22:20:29 +00:00
|
|
|
#include "divesite.h"
|
2019-08-05 17:41:15 +00:00
|
|
|
#include "errorhelper.h"
|
2019-08-05 18:07:10 +00:00
|
|
|
#include "file.h"
|
2014-05-23 18:49:49 +00:00
|
|
|
#include "save-html.h"
|
2024-03-13 08:41:11 +00:00
|
|
|
#include "format.h"
|
2014-03-30 20:14:56 +00:00
|
|
|
#include "worldmap-save.h"
|
|
|
|
#include "worldmap-options.h"
|
2014-05-25 06:11:34 +00:00
|
|
|
#include "gettext.h"
|
2014-03-30 20:14:56 +00:00
|
|
|
|
2024-03-08 16:09:02 +00:00
|
|
|
static const char *getGoogleApi()
|
2014-03-30 20:14:56 +00:00
|
|
|
{
|
|
|
|
/* google maps api auth*/
|
2017-07-30 23:17:34 +00:00
|
|
|
return "https://maps.googleapis.com/maps/api/js?";
|
2014-03-30 20:14:56 +00:00
|
|
|
}
|
|
|
|
|
2024-03-08 16:09:02 +00:00
|
|
|
static void writeMarkers(struct membuffer *b, bool selected_only)
|
2014-03-30 20:14:56 +00:00
|
|
|
{
|
2014-04-04 14:39:39 +00:00
|
|
|
int i, dive_no = 0;
|
2014-03-30 20:14:56 +00:00
|
|
|
struct dive *dive;
|
2024-03-08 16:09:02 +00:00
|
|
|
std::string pre, post;
|
2014-03-30 20:14:56 +00:00
|
|
|
|
2014-05-29 14:30:33 +00:00
|
|
|
for_each_dive (i, dive) {
|
2014-05-21 12:23:05 +00:00
|
|
|
if (selected_only) {
|
|
|
|
if (!dive->selected)
|
|
|
|
continue;
|
|
|
|
}
|
2015-02-13 03:01:27 +00:00
|
|
|
struct dive_site *ds = get_dive_site_for_dive(dive);
|
2019-04-01 20:46:07 +00:00
|
|
|
if (!dive_site_has_gps_location(ds))
|
2014-03-30 20:14:56 +00:00
|
|
|
continue;
|
2018-10-20 18:12:15 +00:00
|
|
|
put_degrees(b, ds->location.lat, "temp = new google.maps.Marker({position: new google.maps.LatLng(", "");
|
|
|
|
put_degrees(b, ds->location.lon, ",", ")});\n");
|
2014-04-03 19:00:13 +00:00
|
|
|
put_string(b, "markers.push(temp);\ntempinfowindow = new google.maps.InfoWindow({content: '<div id=\"content\">'+'<div id=\"siteNotice\">'+'</div>'+'<div id=\"bodyContent\">");
|
2024-03-08 16:09:02 +00:00
|
|
|
pre = format_string_std("<p>%s ", translate("gettextFromC", "Date:"));
|
|
|
|
put_HTML_date(b, dive, pre.c_str(), "</p>");
|
|
|
|
pre = format_string_std("<p>%s ", translate("gettextFromC", "Time:"));
|
|
|
|
put_HTML_time(b, dive, pre.c_str(), "</p>");
|
|
|
|
pre = format_string_std("<p>%s ", translate("gettextFromC", "Duration:"));
|
|
|
|
post = format_string_std(" %s</p>", translate("gettextFromC", "min"));
|
|
|
|
put_duration(b, dive->duration, pre.c_str(), post.c_str());
|
2016-01-10 10:12:39 +00:00
|
|
|
put_string(b, "<p> ");
|
|
|
|
put_HTML_quoted(b, translate("gettextFromC", "Max. depth:"));
|
|
|
|
put_HTML_depth(b, dive, " ", "</p>");
|
2015-02-12 18:46:14 +00:00
|
|
|
put_string(b, "<p> ");
|
|
|
|
put_HTML_quoted(b, translate("gettextFromC", "Air temp.:"));
|
|
|
|
put_HTML_airtemp(b, dive, " ", "</p>");
|
|
|
|
put_string(b, "<p> ");
|
|
|
|
put_HTML_quoted(b, translate("gettextFromC", "Water temp.:"));
|
|
|
|
put_HTML_watertemp(b, dive, " ", "</p>");
|
2024-03-08 16:09:02 +00:00
|
|
|
pre = format_string_std("<p>%s <b>", translate("gettextFromC", "Location:"));
|
|
|
|
put_string(b, pre.c_str());
|
2024-05-04 15:18:08 +00:00
|
|
|
put_HTML_quoted(b, get_dive_location(dive).c_str());
|
2014-06-02 17:10:54 +00:00
|
|
|
put_string(b, "</b></p>");
|
2024-03-08 16:09:02 +00:00
|
|
|
pre = format_string_std("<p> %s ", translate("gettextFromC", "Notes:"));
|
|
|
|
put_HTML_notes(b, dive, pre.c_str(), " </p>");
|
2014-04-03 19:00:13 +00:00
|
|
|
put_string(b, "</p>'+'</div>'+'</div>'});\ninfowindows.push(tempinfowindow);\n");
|
2014-04-04 14:39:39 +00:00
|
|
|
put_format(b, "google.maps.event.addListener(markers[%d], 'mouseover', function() {\ninfowindows[%d].open(map,markers[%d]);}", dive_no, dive_no, dive_no);
|
|
|
|
put_format(b, ");google.maps.event.addListener(markers[%d], 'mouseout', function() {\ninfowindows[%d].close();});\n", dive_no, dive_no);
|
|
|
|
dive_no++;
|
2014-03-30 20:14:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-08 16:09:02 +00:00
|
|
|
static void insert_html_header(struct membuffer *b)
|
2014-03-30 20:14:56 +00:00
|
|
|
{
|
2014-04-03 19:52:05 +00:00
|
|
|
put_string(b, "<!DOCTYPE html>\n<html>\n<head>\n");
|
|
|
|
put_string(b, "<meta name=\"viewport\" content=\"initial-scale=1.0, user-scalable=no\" />\n<title>World Map</title>\n");
|
2014-04-05 10:34:10 +00:00
|
|
|
put_string(b, "<meta charset=\"UTF-8\">");
|
2014-03-30 20:14:56 +00:00
|
|
|
}
|
|
|
|
|
2024-03-08 16:09:02 +00:00
|
|
|
static void insert_css(struct membuffer *b)
|
2014-03-30 20:14:56 +00:00
|
|
|
{
|
2014-04-03 19:00:13 +00:00
|
|
|
put_format(b, "<style type=\"text/css\">%s</style>\n", css);
|
2014-03-30 20:14:56 +00:00
|
|
|
}
|
|
|
|
|
2024-03-08 16:09:02 +00:00
|
|
|
static void insert_javascript(struct membuffer *b, const bool selected_only)
|
2014-03-30 20:14:56 +00:00
|
|
|
{
|
2014-04-06 05:14:40 +00:00
|
|
|
put_string(b, "<script type=\"text/javascript\" src=\"");
|
2014-04-03 19:00:13 +00:00
|
|
|
put_string(b, getGoogleApi());
|
2014-04-06 05:14:40 +00:00
|
|
|
put_string(b, "&sensor=false\">\n</script>\n<script type=\"text/javascript\">\nvar map;\n");
|
2014-04-03 19:00:13 +00:00
|
|
|
put_format(b, "function initialize() {\nvar mapOptions = {\n\t%s,", map_options);
|
|
|
|
put_string(b, "rotateControl: false,\n\tstreetViewControl: false,\n\tmapTypeControl: false\n};\n");
|
|
|
|
put_string(b, "map = new google.maps.Map(document.getElementById(\"map-canvas\"),mapOptions);\nvar markers = new Array();");
|
|
|
|
put_string(b, "\nvar infowindows = new Array();\nvar temp;\nvar tempinfowindow;\n");
|
2014-05-21 12:23:05 +00:00
|
|
|
writeMarkers(b, selected_only);
|
2014-04-03 19:00:13 +00:00
|
|
|
put_string(b, "\nfor(var i=0;i<markers.length;i++)\n\tmarkers[i].setMap(map);\n}\n");
|
|
|
|
put_string(b, "google.maps.event.addDomListener(window, 'load', initialize);</script>\n");
|
2014-03-30 20:14:56 +00:00
|
|
|
}
|
|
|
|
|
2024-03-08 16:09:02 +00:00
|
|
|
static void export_doit(struct membuffer *b, const bool selected_only)
|
2014-03-30 20:14:56 +00:00
|
|
|
{
|
|
|
|
insert_html_header(b);
|
|
|
|
insert_css(b);
|
2014-05-21 12:23:05 +00:00
|
|
|
insert_javascript(b, selected_only);
|
2014-04-06 05:14:40 +00:00
|
|
|
put_string(b, "\t</head>\n<body>\n<div id=\"map-canvas\"></div>\n</body>\n</html>");
|
2014-03-30 20:14:56 +00:00
|
|
|
}
|
|
|
|
|
2024-03-08 16:09:02 +00:00
|
|
|
extern "C" void export_worldmap_HTML(const char *file_name, const bool selected_only)
|
2014-03-30 20:14:56 +00:00
|
|
|
{
|
|
|
|
FILE *f;
|
|
|
|
|
2024-03-08 16:09:02 +00:00
|
|
|
struct membufferpp buf;
|
|
|
|
export_doit(&buf, selected_only);
|
2014-03-30 20:14:56 +00:00
|
|
|
|
2014-06-08 04:35:20 +00:00
|
|
|
f = subsurface_fopen(file_name, "w+");
|
2014-07-15 12:45:21 +00:00
|
|
|
if (!f) {
|
2014-06-08 04:35:20 +00:00
|
|
|
report_error(translate("gettextFromC", "Can't open file %s"), file_name);
|
2014-07-15 12:45:21 +00:00
|
|
|
} else {
|
|
|
|
flush_buffer(&buf, f); /*check for writing errors? */
|
|
|
|
fclose(f);
|
|
|
|
}
|
2014-03-30 20:14:56 +00:00
|
|
|
}
|