1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
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);
}
|