mirror of
https://github.com/subsurface/subsurface.git
synced 2024-12-02 23:20:20 +00:00
Exporting a World-Map
This patch adds the world map exporter. - add worldmap-save.c that writes the html to the file - use Google maps v3 API to put the place marks on the map - add worldmap-options.h to contain some settings for the JS which will make it easier for those to be changed - add save HTML action in the mainwindow user interface Signed-off-by: Gehad elrobey <gehadelrobey@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
7696fbf9cd
commit
0cd9d09410
7 changed files with 152 additions and 0 deletions
|
@ -36,6 +36,7 @@
|
||||||
#include "simplewidgets.h"
|
#include "simplewidgets.h"
|
||||||
#include "diveplanner.h"
|
#include "diveplanner.h"
|
||||||
#include "about.h"
|
#include "about.h"
|
||||||
|
#include "worldmap-save.h"
|
||||||
#ifndef NO_PRINTING
|
#ifndef NO_PRINTING
|
||||||
#include "printdialog.h"
|
#include "printdialog.h"
|
||||||
#endif
|
#endif
|
||||||
|
@ -277,6 +278,15 @@ void MainWindow::on_actionExportUDDF_triggered()
|
||||||
export_dives_uddf(filename.toUtf8(), false);
|
export_dives_uddf(filename.toUtf8(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::on_actionExportHTMLworldmap_triggered()
|
||||||
|
{
|
||||||
|
QFileInfo fi(system_default_filename());
|
||||||
|
QString filename = QFileDialog::getSaveFileName(this, tr("Export World Map"), fi.absolutePath(),
|
||||||
|
tr("HTML files (*.html)"));
|
||||||
|
if (!filename.isNull() && !filename.isEmpty())
|
||||||
|
export_worldmap_HTML(filename.toUtf8().data());
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::on_actionPrint_triggered()
|
void MainWindow::on_actionPrint_triggered()
|
||||||
{
|
{
|
||||||
#ifndef NO_PRINTING
|
#ifndef NO_PRINTING
|
||||||
|
|
|
@ -90,6 +90,7 @@ slots:
|
||||||
void on_actionSaveAs_triggered();
|
void on_actionSaveAs_triggered();
|
||||||
void on_actionClose_triggered();
|
void on_actionClose_triggered();
|
||||||
void on_actionExportUDDF_triggered();
|
void on_actionExportUDDF_triggered();
|
||||||
|
void on_actionExportHTMLworldmap_triggered();
|
||||||
void on_actionPrint_triggered();
|
void on_actionPrint_triggered();
|
||||||
void on_actionPreferences_triggered();
|
void on_actionPreferences_triggered();
|
||||||
void on_actionQuit_triggered();
|
void on_actionQuit_triggered();
|
||||||
|
|
|
@ -551,6 +551,7 @@
|
||||||
<addaction name="separator"/>
|
<addaction name="separator"/>
|
||||||
<addaction name="actionClose"/>
|
<addaction name="actionClose"/>
|
||||||
<addaction name="actionExportUDDF"/>
|
<addaction name="actionExportUDDF"/>
|
||||||
|
<addaction name="actionExportHTMLworldmap"/>
|
||||||
<addaction name="actionPrint"/>
|
<addaction name="actionPrint"/>
|
||||||
<addaction name="actionPreferences"/>
|
<addaction name="actionPreferences"/>
|
||||||
<addaction name="separator"/>
|
<addaction name="separator"/>
|
||||||
|
@ -680,6 +681,11 @@
|
||||||
<property name="shortcut">
|
<property name="shortcut">
|
||||||
<string>Ctrl+U</string>
|
<string>Ctrl+U</string>
|
||||||
</property>
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionExportHTMLworldmap">
|
||||||
|
<property name="text">
|
||||||
|
<string>Export HTML World Map</string>
|
||||||
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="actionPrint">
|
<action name="actionPrint">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
|
|
|
@ -28,6 +28,8 @@ HEADERS = \
|
||||||
helpers.h \
|
helpers.h \
|
||||||
libdivecomputer.h \
|
libdivecomputer.h \
|
||||||
planner.h \
|
planner.h \
|
||||||
|
worldmap-save.h \
|
||||||
|
worldmap-options.h \
|
||||||
pref.h \
|
pref.h \
|
||||||
profile.h \
|
profile.h \
|
||||||
qt-gui.h \
|
qt-gui.h \
|
||||||
|
@ -97,6 +99,7 @@ SOURCES = \
|
||||||
parse-xml.c \
|
parse-xml.c \
|
||||||
planner.c \
|
planner.c \
|
||||||
profile.c \
|
profile.c \
|
||||||
|
worldmap-save.c \
|
||||||
qt-gui.cpp \
|
qt-gui.cpp \
|
||||||
qthelper.cpp \
|
qthelper.cpp \
|
||||||
qt-ui/about.cpp \
|
qt-ui/about.cpp \
|
||||||
|
|
7
worldmap-options.h
Normal file
7
worldmap-options.h
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
#ifndef WORLDMAP_OPTIONS_H
|
||||||
|
#define WORLDMAP_OPTIONS_H
|
||||||
|
|
||||||
|
const char* map_options = "center: new google.maps.LatLng(0,0),\n\tzoom: 3,\n\tminZoom: 2,\n\tmapTypeId: google.maps.MapTypeId.SATELLITE\n\t";
|
||||||
|
const char* css = "\n\thtml { height: 100% }\n\tbody { height: 100%; margin: 0; padding: 0 }\n\t#map-canvas { height: 100% }\n";
|
||||||
|
|
||||||
|
#endif// WORLDMAP-OPTIONS_H
|
110
worldmap-save.c
Normal file
110
worldmap-save.c
Normal file
|
@ -0,0 +1,110 @@
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "dive.h"
|
||||||
|
#include "membuffer.h"
|
||||||
|
#include "worldmap-save.h"
|
||||||
|
#include "worldmap-options.h"
|
||||||
|
|
||||||
|
char* getGoogleApi()
|
||||||
|
{
|
||||||
|
/* google maps api auth*/
|
||||||
|
return "https://maps.googleapis.com/maps/api/js?key=AIzaSyDzo9PWsqYDDSddVswg_13rpD9oH_dLuoQ";
|
||||||
|
}
|
||||||
|
|
||||||
|
void put_HTML_date(struct membuffer *b,struct dive *dive)
|
||||||
|
{
|
||||||
|
struct tm tm;
|
||||||
|
utc_mkdate(dive->when, &tm);
|
||||||
|
put_format(b, "<p>date=%04u-%02u-%02u</p>",tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday);
|
||||||
|
put_format(b, "<p>time=%02u:%02u:%02u</p>",tm.tm_hour, tm.tm_min, tm.tm_sec);
|
||||||
|
}
|
||||||
|
|
||||||
|
void put_HTML_temp(struct membuffer *b,struct dive *dive)
|
||||||
|
{
|
||||||
|
put_temperature(b, dive->airtemp, "<p>Air Temp: ", " C\\'</p>");
|
||||||
|
put_temperature(b, dive->watertemp, "<p>Water Temp: ", " C\\'</p>");
|
||||||
|
}
|
||||||
|
|
||||||
|
void put_HTML_notes(struct membuffer *b,struct dive *dive)
|
||||||
|
{
|
||||||
|
if (dive->notes) {
|
||||||
|
put_format(b,"<p>Notes : %s </p>",dive->notes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void writeMarkers(struct membuffer *b)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
struct dive *dive;
|
||||||
|
|
||||||
|
for_each_dive(i, dive) {
|
||||||
|
/*export selected dives only ?*/
|
||||||
|
|
||||||
|
if (dive->latitude.udeg==0 && dive->longitude.udeg==0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
put_format(b,"temp = new google.maps.Marker({position: new google.maps.LatLng(%f,%f)});\n",
|
||||||
|
dive->latitude.udeg/1000000.0,dive->longitude.udeg/1000000.0);
|
||||||
|
put_string(b,"markers.push(temp);\ntempinfowindow = new google.maps.InfoWindow({content: '<div id=\"content\">'+'<div id=\"siteNotice\">'+'</div>'+'<div id=\"bodyContent\">");
|
||||||
|
put_HTML_date(b,dive);
|
||||||
|
put_duration(b, dive->duration, "<p>duration=", " min</p>");
|
||||||
|
put_HTML_temp(b,dive);
|
||||||
|
put_HTML_notes(b,dive);
|
||||||
|
put_string(b,"</p>'+'</div>'+'</div>'});\ninfowindows.push(tempinfowindow);\n");
|
||||||
|
put_format(b,"google.maps.event.addListener(markers[%d], 'mouseover', function() {\ninfowindows[%d].open(map,markers[%d]);}",i,i,i);
|
||||||
|
put_format(b,");google.maps.event.addListener(markers[%d], 'mouseout', function() {\ninfowindows[%d].close();});\n",i,i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void insert_html_header(struct membuffer *b)
|
||||||
|
{
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
|
||||||
|
void insert_css(struct membuffer *b)
|
||||||
|
{
|
||||||
|
put_format(b,"<style type=\"text/css\">%s</style>\n",css);
|
||||||
|
}
|
||||||
|
|
||||||
|
void insert_javascript(struct membuffer *b)
|
||||||
|
{
|
||||||
|
put_string(b,"<script type=\"text/javascript\"src=\"");
|
||||||
|
put_string(b,getGoogleApi());
|
||||||
|
put_string(b,"&sensor=false\">\n</script>\n<script type=\"text/javascript\">\nvar map;\n");
|
||||||
|
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");
|
||||||
|
writeMarkers(b);
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
|
||||||
|
void export(struct membuffer *b)
|
||||||
|
{
|
||||||
|
insert_html_header(b);
|
||||||
|
insert_css(b);
|
||||||
|
insert_javascript(b);
|
||||||
|
put_string(b,"\t</head>\n<body>\n<div id=\"map-canvas\"/>\n</body>\n</html>");
|
||||||
|
}
|
||||||
|
|
||||||
|
void export_worldmap_HTML(const char* file_name)
|
||||||
|
{
|
||||||
|
FILE *f;
|
||||||
|
|
||||||
|
struct membuffer buf = { 0 };
|
||||||
|
export(&buf);
|
||||||
|
|
||||||
|
f = fopen(file_name,"w+");
|
||||||
|
if (!f) {
|
||||||
|
printf("error"); /*report error*/
|
||||||
|
}
|
||||||
|
|
||||||
|
flush_buffer(&buf,f); /*check for writing errors? */
|
||||||
|
free_buffer(&buf);
|
||||||
|
fclose(f);
|
||||||
|
}
|
15
worldmap-save.h
Normal file
15
worldmap-save.h
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
#ifndef WORLDMAP_SAVE_H
|
||||||
|
#define WORLDMAP_SAVE_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
extern void export_worldmap_HTML(const char* x);
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in a new issue