-
Notifications
You must be signed in to change notification settings - Fork 0
/
myScript_present1.js
316 lines (263 loc) · 8.49 KB
/
myScript_present1.js
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
// original URL: https://maps.googleapis.com/maps/api/js?
// Chinese URL: http://ditu.google.cn/maps/api/js?
var myLat = 0;
var myLng = 0;
var request = new XMLHttpRequest();
var me = new google.maps.LatLng(myLat, myLng);
var myOptions = {
zoom: 13,
center: me,
// mapTypeId: google.maps.MapTypeId.ROADMAP
styles: [
// {elementType: 'geometry', stylers: [{color: '#242f3e'}]},
{elementType: 'geometry', stylers: [{color: '#F1BDD6'}]},
// {elementType: 'labels.text.stroke', stylers: [{color: '#242f3e'}]},
{elementType: 'labels.text.stroke', stylers: [{color: '#FBF5F5'}]},
// {elementType: 'labels.text.fill', stylers: [{color: '#746855'}]},
{elementType: 'labels.text.fill', stylers: [{color: 'F70606'}]},
{
featureType: 'administrative.locality',
elementType: 'labels.text.fill',
// stylers: [{color: '#d59563'}]
stylers: [{color: '#F04545'}]
},
{
featureType: 'poi',
elementType: 'labels.text.fill',
// stylers: [{color: '#d59563'}]
stylers: [{color: '#F72879'}]
},
{
featureType: 'poi.park',
elementType: 'geometry',
// stylers: [{color: '#263c3f'}]
stylers: [{color: '#F8D1E0'}]
},
{
featureType: 'poi.park',
elementType: 'labels.text.fill',
stylers: [{color: '#6b9a76'}]
},
{
featureType: 'road',
elementType: 'geometry',
// stylers: [{color: '#38414e'}]
stylers: [{color: '#E0075C'}]
},
{
featureType: 'road',
elementType: 'geometry.stroke',
// stylers: [{color: '#212a37'}]
stylers: [{color: '#F93309'}]
},
{
featureType: 'road',
elementType: 'labels.text.fill',
// stylers: [{color: '#9ca5b3'}]
stylers: [{color: '#F90909'}]
},
{
featureType: 'road.highway',
elementType: 'geometry',
// stylers: [{color: '#746855'}]
stylers: [{color: '#F72879'}]
},
{
featureType: 'road.highway',
elementType: 'geometry.stroke',
// stylers: [{color: '#1f2835'}]
stylers: [{color: '#FA00A3'}]
},
{
featureType: 'road.highway',
elementType: 'labels.text.fill',
stylers: [{color: '#f3d19c'}]
},
{
featureType: 'transit',
elementType: 'geometry',
// stylers: [{color: '#2f3948'}]
stylers: [{color: '#FA0063'}]
},
{
featureType: 'transit.station',
elementType: 'labels.text.fill',
stylers: [{color: '#d59563'}]
},
{
featureType: 'water',
elementType: 'geometry',
// stylers: [{color: '#17263c'}]
stylers: [{color: '#FFFCFB'}]
},
{
featureType: 'water',
elementType: 'labels.text.fill',
stylers: [{color: '#515c6d'}]
},
{
featureType: 'water',
elementType: 'labels.text.stroke',
stylers: [{color: '#17263c'}]
}
]
};
//
// Put one of these locations into a Tyler Series solution
// Put the specific location in Jiali into a word scrambler
// that can be reconstructed by a Tyler Series
var station_list = [
{station_name: "嘉里中心", message: "not shown yet", message2: "Welcome to the game for presents! When you get there,",
message3:"message me and more instructions will", message4:"follow. Happy Hunting!!!", lat:31.224423, lng: 121.450200, location: new google.maps.LatLng(31.224423, 121.450200)}
]
var map;
var present_icon = "present2.png";
var me_photo = "me.png";
var marker_me;
var infowindow = new google.maps.InfoWindow();
function init() {
map = new google.maps.Map(document.getElementById("map"), myOptions);
getMyLocation();
}
function getMyLocation() {
if (navigator.geolocation) { // the navigator.geolocation object is supported on your browser
navigator.geolocation.getCurrentPosition(function(position) {
this.myLat = position.coords.latitude;
this.myLng = position.coords.longitude;
renderMap();
});
}
else {
alert("Geolocation is not supported by your web browser. What a shame!");
}
}
var nearest_index;
var nearest_distance;
function renderMap()
{
me = new google.maps.LatLng(myLat, myLng);
map.panTo(me);
update_nearest_station();
var contentString = '<p>closest station: '
+ station_list[nearest_index].station_name + '</p>'
+ '<p>which is </p>' + nearest_distance
+ '<p> miles from you</p>' ;
var infowindow = new google.maps.InfoWindow({
content: contentString
});
marker_me = new google.maps.Marker({
position: me,
title: "Here you are!",
map: map,
icon: me_photo,
animation: google.maps.Animation.BOUNCE
});
google.maps.event.addListener(marker_me, 'click', function() {
show_nearest_station(); // nearest_index is now updated
infowindow.open(map, marker_me);
});
// marker_me.setMap(map);
var infowindow_stations = {};
for (let i = 0; i < 1; i++){
var contentStrings = '<p>General Location: </p>'
+ station_list[i].station_name
+ '<p>Exact Location: </p>'
+ station_list[i].message
+ '<p></p>'
+ station_list[i].message2
+ '<p></p>'
+ station_list[i].message3
+ '<p></p>'
+ station_list[i].message4;
infowindow_stations[i] = new google.maps.InfoWindow({
content: contentStrings
});
var Marker = new google.maps.Marker({
position: station_list[i].location,
title: station_list[i].station_name,
time_remaining: station_list[i].time_remain,
map: map,
icon: present_icon,
animation: google.maps.Animation.DROP
});
google.maps.event.addListener(Marker, 'click', function() {
infowindow_stations[i].open(map, this);
for (j = 0; j < 1; j++){
if (j!=i){
infowindow_stations[j].close(map, this);
}
}
});
}
}
function update_nearest_station(){
var index_received = get_cloest_station(station_list);
var lat_nearest = station_list[index_received].lat;
var lng_nearest = station_list[index_received].lng;
var Coordinates_me_to_closest_station = [
{lat: lat_nearest, lng: lng_nearest},
{lat: myLat, lng: myLng}
]
nearest_index = index_received;
}
function show_nearest_station(){
var index_received = get_cloest_station(station_list);
var lat_nearest = station_list[index_received].lat;
var lng_nearest = station_list[index_received].lng;
var Coordinates_me_to_closest_station = [
{lat: lat_nearest, lng: lng_nearest},
{lat: myLat, lng: myLng}
]
var lineSymbol = {
path: 'M 0,-1 0,1',
strokeOpacity: 1,
scale: 4
}
var nearest_path = new google.maps.Polyline({
path: Coordinates_me_to_closest_station,
strokeColor: 'blue',
strokeOpacity: 0,
icons: [{
icon: lineSymbol,
offset: '0',
repeat: '15px'
}],
})
nearest_path.setMap(map);
nearest_index = index_received;
}
function get_cloest_station(station_list){
var index = 0;
var lat_station = station_list[0].lat;
var lng_station = station_list[0].lng;
var smallest_distance = get_distance(lat_station, lng_station, myLat, myLng);
for (i = 0; i < 1; i++){
lat_station = station_list[i].lat;
lng_station = station_list[i].lng;
var potential_smallest_distance = get_distance(lat_station, lng_station, myLat, myLng);
if (potential_smallest_distance < smallest_distance){
smallest_distance = potential_smallest_distance;
index = i;
}
}
nearest_distance = smallest_distance;
return index;
}
function get_distance(lat1, lon1, lat2, lon2){
if (typeof(Number.prototype.toRad) === "undefined") {
Number.prototype.toRad = function() {
return this * Math.PI / 180;
}
}
var R = 6371;
var φ1 = lat1.toRad();
var φ2 = lat2.toRad();
var Δφ = (lat2-lat1).toRad();
var Δλ = (lon2-lon1).toRad();
var a = Math.sin(Δφ/2) * Math.sin(Δφ/2) +
Math.cos(φ1) * Math.cos(φ2) *
Math.sin(Δλ/2) * Math.sin(Δλ/2);
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
var d = R * c;
return d;
}