-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhome.html
186 lines (138 loc) · 4.21 KB
/
home.html
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<!doctype html>
<html>
<head>
<title>TCLocationDemo</title>
<style type="text/css">
html, body, #map-canvas { height: 100%; margin: 0; padding: 0;}
</style>
<script type="text/javascript"
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyB6-ay_rKPDExzkspgsl_wEUCR3_N0Ldc8">
</script>
<script type="text/javascript">
var map;
function initialize() {
var mapOptions = {
center: { lat: -34.397, lng: 150.644},
zoom: 14,
mapTypeId: 'roadmap'
};
map = new google.maps.Map(document.getElementById('map-canvas'),
mapOptions);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<script src="/socket.io/socket.io.js"></script>
<script type="text/javascript" src="jquery-2.1.1.min.js"></script>
<!--<script type="text/javascript" src="evernote-sdk-minified.js"></script>-->
<!--<script type="text/javascript" src="jsOAuth-1.3.7.js"></script>-->
<script>
var socket = io();
var user;
var notebooks = new Array();
var notesByNotebook = new Array();
var notes = new Array();
var markers = new Array();
socket.on('user', function(data){
console.log("user");
console.log(data);
user = data;
});
socket.on('notebooks', function(data){
console.log("notebooks");
console.log(data);
for(var i=0; i<data.length; i++) {
var n = data[i];
console.log(n.guid);
notebooks[n.guid] = n;
$("#trips").append("<div id=\'"+ n.guid+"\'><h3" +
" onclick=\"selectTrip(\'"+ n.guid+"\')\">"+ n.name+"</h3><p style='' class='notes'></p></div>");
}
notebooks = data;
});
socket.on('notes', function(guid, data){
console.log("notes");
console.log(guid);
console.log(data);
notesByNotebook[guid] = data;
notebook = getNotebook(guid);
$("#"+guid+" .notes").append("<ol>");
for(var i=0; i<data.length; i++) {
note = data[i];
$("#"+guid+" .notes ol").append("<li onclick=\"selectNote(\'"+note.guid+"\')\">"+note.title+"</li>");
}
});
socket.on('note', function(data){
console.log("note detail");
console.log(data);
notes[data.guid] = data;
});
function getNotebook(guid) {
for(i in notebooks) {
if(notebooks[i].guid == guid) return notebooks[i];
}
}
function getNote(guid) {
for(i in notes) {
if(notes[i].guid == guid) return notes[i];
}
}
function getNodesFromNotebook(guid) {
var nn = new Array();
for(i in notes) {
if(notes[i].notebookGuid == guid) {nn.push(notes[i])};
}
return nn;
}
function selectTrip(guid) {
console.log("selected " + guid);
removeMarkers();
var nn = getNodesFromNotebook(guid);
var bounds = new google.maps.LatLngBounds();
for(var i=0; i<nn.length; i++) {
var note = nn[i];
console.log(note.title);
console.log("ADD MARKER " + note.attributes.latitude + " -- " + note.attributes.longitude);
var myLatlng = new google.maps.LatLng(note.attributes.latitude, note.attributes.longitude);
console.log(myLatlng);
bounds.extend(myLatlng);
var mapOptions = {
zoom: 12,
center: myLatlng
};
// To add the marker to the map, use the 'map' property
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: note.title,
animation: google.maps.Animation.DROP
});
markers.push(marker);
}
map.fitBounds(bounds);
var boundsListener = google.maps.event.addListener((map), 'bounds_changed', function(event) {
this.setZoom(14);
google.maps.event.removeListener(boundsListener);
});
}
function removeMarkers() {
for(var i=0; i<markers.length; i++) {
markers[i].setMap(null);
}
markers = new Array();
}
function selectNote(guid) {
console.log("selected " + guid);
}
jQuery(function($) {
// Asynchronously Load the map API
var script = document.createElement('script');
script.src = "http://maps.googleapis.com/maps/api/js?sensor=false&callback=initialize";
document.body.appendChild(script);
});
</script>
<div id="trips"></div>
<div id="map-canvas"></div>
</body>
</html>