// SPDX-License-Identifier: GPL-2.0 #ifdef __clang__ // Clang has a bug on zero-initialization of C structs. #pragma clang diagnostic ignored "-Wmissing-field-initializers" #endif #include #include #include #include #include "dive.h" #include "divelist.h" #include "divelog.h" #include "divesite.h" #include "errorhelper.h" #include "file.h" #include "membuffer.h" #include "save-html.h" #include "format.h" #include "worldmap-save.h" #include "worldmap-options.h" #include "gettext.h" static const char *getGoogleApi() { /* google maps api auth*/ return "https://maps.googleapis.com/maps/api/js?"; } static void writeMarkers(struct membuffer *b, bool selected_only) { int dive_no = 0; for (auto &dive: divelog.dives) { if (selected_only && !dive->selected) continue; struct dive_site *ds = dive->dive_site; if (!ds || !ds->has_gps_location()) continue; put_degrees(b, ds->location.lat, "temp = new google.maps.Marker({position: new google.maps.LatLng(", ""); put_degrees(b, ds->location.lon, ",", ")});\n"); put_string(b, "markers.push(temp);\ntempinfowindow = new google.maps.InfoWindow({content: '
'+'
'+'
'+'
"); std::string pre = format_string_std("

%s ", translate("gettextFromC", "Date:")); put_HTML_date(b, *dive, pre.c_str(), "

"); pre = format_string_std("

%s ", translate("gettextFromC", "Time:")); put_HTML_time(b, *dive, pre.c_str(), "

"); pre = format_string_std("

%s ", translate("gettextFromC", "Duration:")); std::string post = format_string_std(" %s

", translate("gettextFromC", "min")); put_duration(b, dive->duration, pre.c_str(), post.c_str()); put_string(b, "

"); put_HTML_quoted(b, translate("gettextFromC", "Max. depth:")); put_HTML_depth(b, *dive, " ", "

"); put_string(b, "

"); put_HTML_quoted(b, translate("gettextFromC", "Air temp.:")); put_HTML_airtemp(b, *dive, " ", "

"); put_string(b, "

"); put_HTML_quoted(b, translate("gettextFromC", "Water temp.:")); put_HTML_watertemp(b, *dive, " ", "

"); pre = format_string_std("

%s ", translate("gettextFromC", "Location:")); put_string(b, pre.c_str()); put_HTML_quoted(b, dive->get_location().c_str()); put_string(b, "

"); pre = format_string_std("

%s ", translate("gettextFromC", "Notes:")); put_HTML_notes(b, *dive, pre.c_str(), "

"); put_string(b, "

'+'
'+'
'});\ninfowindows.push(tempinfowindow);\n"); 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++; } } static void insert_html_header(struct membuffer *b) { put_string(b, "\n\n\n"); put_string(b, "\nWorld Map\n"); put_string(b, ""); } static void insert_css(struct membuffer *b) { put_format(b, "\n", css); } static void insert_javascript(struct membuffer *b, const bool selected_only) { put_string(b, "\n\n"); } static void export_doit(struct membuffer *b, const bool selected_only) { insert_html_header(b); insert_css(b); insert_javascript(b, selected_only); put_string(b, "\t\n\n
\n\n"); } void export_worldmap_HTML(const char *file_name, const bool selected_only) { FILE *f; membuffer buf; export_doit(&buf, selected_only); f = subsurface_fopen(file_name, "w+"); if (!f) { report_error(translate("gettextFromC", "Can't open file %s"), file_name); } else { flush_buffer(&buf, f); /*check for writing errors? */ fclose(f); } }