-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
669 lines (524 loc) · 20.3 KB
/
main.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
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
name = 'Chargement'
// 📝 Fetch all DOM nodes in jQuery and Snap SVG
var container = $('.container');
var card = $('#card');
var innerSVG = Snap('#inner');
var outerSVG = Snap('#outer');
var backSVG = Snap('#back');
var summary = $('#summary');
var date = $('#date');
var weatherContainer1 = Snap.select('#layer1');
var weatherContainer2 = Snap.select('#layer2');
var weatherContainer3 = Snap.select('#layer3');
var innerRainHolder1 = weatherContainer1.group();
var innerRainHolder2 = weatherContainer2.group();
var innerRainHolder3 = weatherContainer3.group();
var innerLeafHolder = weatherContainer1.group();
var innerSnowHolder = weatherContainer1.group();
var innerLightningHolder = weatherContainer1.group();
var leafMask = outerSVG.rect();
var leaf = Snap.select('#leaf');
var sun = Snap.select('#sun');
var sunburst = Snap.select('#sunburst');
var outerSplashHolder = outerSVG.group();
var outerLeafHolder = outerSVG.group();
var outerSnowHolder = outerSVG.group();
var lightningTimeout;
// Set mask for leaf holder
outerLeafHolder.attr({
'clip-path': leafMask
});
// create sizes object, we update this later
var sizes = {
container: {width: 0, height: 0},
card: {width: 0, height: 0}
}
// grab cloud groups
var clouds = [
{group: Snap.select('#cloud1')},
{group: Snap.select('#cloud2')},
{group: Snap.select('#cloud3')}
]
// set weather types ☁️ 🌬 🌧 ⛈ ☀️
var weather = [
{ type: 'snow'},
{ type: 'wind'},
{ type: 'rain'},
{ type: 'thunder'},
{ type: 'sun'}
];
// 🛠 app settings
// in an object so the values can be animated in tweenmax
var settings = {
windSpeed: 2,
rainCount: 0,
leafCount: 0,
snowCount: 0,
cloudHeight: 100,
cloudSpace: 30,
cloudArch: 50,
renewCheck: 10,
splashBounce: 80
};
var tickCount = 0;
var rain = [];
var leafs = [];
var snow = [];
// ⚙ initialize app
init();
// 👁 watch for window resize
$(window).resize(onResize);
// 🏃 start animations
requestAnimationFrame(tick);
function init()
{
onResize();
// 🖱 bind weather menu buttons
for(var i = 0; i < weather.length; i++)
{
var w = weather[i];
var b = $('#button-' + w.type);
w.button = b;
b.bind('click', w, changeWeather);
}
// ☁️ draw clouds
for(var i = 0; i < clouds.length; i++)
{
clouds[i].offset = Math.random() * sizes.card.width;
drawCloud(clouds[i], i);
}
// ☀️ set initial weather
TweenMax.set(sunburst.node, {opacity: 0})
changeWeather(weather[0]);
}
function onResize()
{
// 📏 grab window and card sizes
sizes.container.width = container.width();
sizes.container.height = container.height();
sizes.card.width = card.width();
sizes.card.height = card.height();
sizes.card.offset = card.offset();
// 📐 update svg sizes
innerSVG.attr({
width: sizes.card.width,
height: sizes.card.height
})
outerSVG.attr({
width: sizes.container.width,
height: sizes.container.height
})
backSVG.attr({
width: sizes.container.width,
height: sizes.container.height
})
TweenMax.set(sunburst.node, {transformOrigin:"50% 50%", x: sizes.container.width / 2, y: (sizes.card.height/2) + sizes.card.offset.top});
TweenMax.fromTo(sunburst.node, 20, {rotation: 0}, {rotation: 360, repeat: -1, ease: Power0.easeInOut})
// 🍃 The leaf mask is for the leafs that float out of the
// container, it is full window height and starts on the left
// inline with the card
leafMask.attr({x: sizes.card.offset.left, y: 0, width: sizes.container.width - sizes.card.offset.left, height: sizes.container.height});
}
function drawCloud(cloud, i)
{
/*
☁️ We want to create a shape thats loopable but that can also
be animated in and out. So we use Snap SVG to draw a shape
with 4 sections. The 2 ends and 2 arches the same width as
the card. So the final shape is about 4 x the width of the
card.
*/
var space = settings.cloudSpace * i;
var height = space + settings.cloudHeight;
var arch = height + settings.cloudArch + (Math.random() * settings.cloudArch);
var width = sizes.card.width;
var points = [];
points.push('M' + [-(width), 0].join(','));
points.push([width, 0].join(','));
points.push('Q' + [width * 2, height / 2].join(','));
points.push([width, height].join(','));
points.push('Q' + [width * 0.5, arch].join(','));
points.push([0, height].join(','));
points.push('Q' + [width * -0.5, arch].join(','));
points.push([-width, height].join(','));
points.push('Q' + [- (width * 2), height/2].join(','));
points.push([-(width), 0].join(','));
var path = points.join(' ');
if(!cloud.path) cloud.path = cloud.group.path();
cloud.path.animate({
d: path
}, 0)
}
function makeRain()
{
// 💧 This is where we draw one drop of rain
// first we set the line width of the line, we use this
// to dictate which svg group it'll be added to and
// whether it'll generate a splash
var lineWidth = Math.random() * 3;
// ⛈ line length is made longer for stormy weather
var lineLength = currentWeather.type == 'thunder' ? 35 : 14;
// Start the drop at a random point at the top but leaving
// a 20px margin
var x = Math.random() * (sizes.card.width - 40) + 20;
// Draw the line
var line = this['innerRainHolder' + (3 - Math.floor(lineWidth))].path('M0,0 0,' + lineLength).attr({
fill: 'none',
stroke: currentWeather.type == 'thunder' ? '#777' : '#0000ff',
strokeWidth: lineWidth
});
// add the line to an array to we can keep track of how
// many there are.
rain.push(line);
// Start the falling animation, calls onRainEnd when the
// animation finishes.
TweenMax.fromTo(line.node, 1, {x: x, y: 0- lineLength}, {delay: Math.random(), y: sizes.card.height, ease: Power2.easeIn, onComplete: onRainEnd, onCompleteParams: [line, lineWidth, x, currentWeather.type]});
}
function onRainEnd(line, width, x, type)
{
// first lets get rid of the drop of rain 💧
line.remove();
line = null;
// We also remove it from the array
for(var i in rain)
{
if(!rain[i].paper) rain.splice(i, 1);
}
// If there is less rain than the rainCount we should
// make more.
if(rain.length < settings.rainCount)
{
makeRain();
// 💦 If the line width was more than 2 we also create a
// splash. This way it looks like the closer (bigger)
// drops hit the the edge of the card
if(width > 2) makeSplash(x, type);
}
}
function makeSplash(x, type)
{
// 💦 The splash is a single line added to the outer svg.
// The splashLength is how long the animated line will be
var splashLength = type == 'thunder' ? 30 : 20;
// splashBounce is the max height the line will curve up
// before falling
var splashBounce = type == 'thunder' ? 120 : 100;
// this sets how far down the line can fall
var splashDistance = 80;
// because the storm rain is longer we want the animation
// to last slighly longer so the overall speed is roughly
// the same for both
var speed = type == 'thunder' ? 0.7 : 0.5;
// Set a random splash up amount based on the max splash bounce
var splashUp = 0 - (Math.random() * splashBounce);
// Sets the end x position, and in turn defines the splash direction
var randomX = ((Math.random() * splashDistance) - (splashDistance / 2));
// Now we put the 3 line coordinates into an array.
var points = [];
points.push('M' + 0 + ',' + 0);
points.push('Q' + randomX + ',' + splashUp);
points.push((randomX * 2) + ',' + splashDistance);
// Draw the line with Snap SVG
var splash = outerSplashHolder.path(points.join(' ')).attr({
fill: "none",
stroke: type == 'thunder' ? '#777' : '#0000ff',
strokeWidth: 1
});
// We animate the dasharray to have the line travel along the path
var pathLength = Snap.path.getTotalLength(splash);
var xOffset = sizes.card.offset.left;//(sizes.container.width - sizes.card.width) / 2
var yOffset = sizes.card.offset.top + sizes.card.height;
splash.node.style.strokeDasharray = splashLength + ' ' + pathLength;
// Start the splash animation, calling onSplashComplete when finished
TweenMax.fromTo(splash.node, speed, {strokeWidth: 2, y: yOffset, x: xOffset + 20 + x, opacity: 1, strokeDashoffset: splashLength}, {strokeWidth: 0, strokeDashoffset: - pathLength, opacity: 1, onComplete: onSplashComplete, onCompleteParams: [splash], ease: SlowMo.ease.config(0.4, 0.1, false)})
}
function onSplashComplete(splash)
{
// 💦 The splash has finished animating, we need to get rid of it
splash.remove();
splash = null;
}
function makeLeaf()
{
var scale = 0.5 + (Math.random() * 0.5);
var newLeaf;
var areaY = sizes.card.height/2;
var y = areaY + (Math.random() * areaY);
var endY = y - ((Math.random() * (areaY * 2)) - areaY)
var x;
var endX;
var colors = ['#76993E', '#4A5E23', '#6D632F'];
var color = colors[Math.floor(Math.random() * colors.length)];
var xBezier;
if(scale > 0.8)
{
newLeaf = leaf.clone().appendTo(outerLeafHolder)
.attr({
fill: color
})
y = y + sizes.card.offset.top / 2;
endY = endY + sizes.card.offset.top / 2;
x = sizes.card.offset.left - 100;
xBezier = x + (sizes.container.width - sizes.card.offset.left) / 2;
endX = sizes.container.width + 50;
}
else
{
newLeaf = leaf.clone().appendTo(innerLeafHolder)
.attr({
fill: color
})
x = -100;
xBezier = sizes.card.width / 2;
endX = sizes.card.width + 50;
}
leafs.push(newLeaf);
var bezier = [{x:x, y:y}, {x: xBezier, y:(Math.random() * endY) + (endY / 3)}, {x: endX, y:endY}]
TweenMax.fromTo(newLeaf.node, 2, {rotation: Math.random()* 180, x: x, y: y, scale:scale}, {rotation: Math.random()* 360, bezier: bezier, onComplete: onLeafEnd, onCompleteParams: [newLeaf], ease: Power0.easeIn})
}
function onLeafEnd(leaf)
{
leaf.remove();
leaf = null;
for(var i in leafs)
{
if(!leafs[i].paper) leafs.splice(i, 1);
}
if(leafs.length < settings.leafCount)
{
makeLeaf();
}
}
function makeSnow()
{
var scale = 0.5 + (Math.random() * 0.5);
var newSnow;
var x = 20 + (Math.random() * (sizes.card.width - 40));
var endX; // = x - ((Math.random() * (areaX * 2)) - areaX)
var y = -10;
var endY;
if(scale > 0.8)
{
newSnow = outerSnowHolder.circle(0, 0, 5)
.attr({
fill: 'white'
})
endY = sizes.container.height + 10;
y = sizes.card.offset.top + settings.cloudHeight;
x = x + sizes.card.offset.left;
//xBezier = x + (sizes.container.width - sizes.card.offset.left) / 2;
//endX = sizes.container.width + 50;
}
else
{
newSnow = innerSnowHolder.circle(0, 0 ,5)
.attr({
fill: 'white'
})
endY = sizes.card.height + 10;
//x = -100;
//xBezier = sizes.card.width / 2;
//endX = sizes.card.width + 50;
}
snow.push(newSnow);
TweenMax.fromTo(newSnow.node, 3 + (Math.random() * 5), {x: x, y: y}, {y: endY, onComplete: onSnowEnd, onCompleteParams: [newSnow], ease: Power0.easeIn})
TweenMax.fromTo(newSnow.node, 1,{scale: 0}, {scale: scale, ease: Power1.easeInOut})
TweenMax.to(newSnow.node, 3, {x: x+((Math.random() * 150)-75), repeat: -1, yoyo: true, ease: Power1.easeInOut})
}
function onSnowEnd(flake)
{
flake.remove();
flake = null;
for(var i in snow)
{
if(!snow[i].paper) snow.splice(i, 1);
}
if(snow.length < settings.snowCount)
{
makeSnow();
}
}
function tick()
{
tickCount++;
var check = tickCount % settings.renewCheck;
if(check)
{
if(rain.length < settings.rainCount) makeRain();
if(leafs.length < settings.leafCount) makeLeaf();
if(snow.length < settings.snowCount) makeSnow();
}
for(var i = 0; i < clouds.length; i++)
{
if(currentWeather.type == 'sun')
{
if(clouds[i].offset > -(sizes.card.width * 1.5)) clouds[i].offset += settings.windSpeed / (i + 1);
if(clouds[i].offset > sizes.card.width * 2.5) clouds[i].offset = -(sizes.card.width * 1.5);
clouds[i].group.transform('t' + clouds[i].offset + ',' + 0);
}
else
{
clouds[i].offset += settings.windSpeed / (i + 1);
if(clouds[i].offset > sizes.card.width) clouds[i].offset = 0 + (clouds[i].offset - sizes.card.width);
clouds[i].group.transform('t' + clouds[i].offset + ',' + 0);
}
}
requestAnimationFrame(tick);
}
function reset()
{
for(var i = 0; i < weather.length; i++)
{
container.removeClass(weather[i].type);
weather[i].button.removeClass('active');
}
}
function updateSummaryText()
{
summary.html(name);
TweenMax.fromTo(summary, 1.5, {x: 30}, {opacity: 1, x: 0, ease: Power4.easeOut});
}
function startLightningTimer()
{
if(lightningTimeout) clearTimeout(lightningTimeout);
if(currentWeather.type == 'thunder')
{
lightningTimeout = setTimeout(lightning, Math.random()*6000);
}
}
function lightning()
{
startLightningTimer();
TweenMax.fromTo(card, 0.75, {y: -30}, {y:0, ease:Elastic.easeOut});
var pathX = 30 + Math.random() * (sizes.card.width - 60);
var yOffset = 20;
var steps = 20;
var points = [pathX + ',0'];
for(var i = 0; i < steps; i++)
{
var x = pathX + (Math.random() * yOffset - (yOffset / 2));
var y = (sizes.card.height / steps) * (i + 1)
points.push(x + ',' + y);
}
var strike = weatherContainer1.path('M' + points.join(' '))
.attr({
fill: 'none',
stroke: 'white',
strokeWidth: 2 + Math.random()
})
TweenMax.to(strike.node, 1, {opacity: 0, ease:Power4.easeOut, onComplete: function(){ strike.remove(); strike = null}})
}
function changeWeather(weather)
{
if(weather.data) weather = weather.data;
reset();
currentWeather = weather;
TweenMax.killTweensOf(summary);
TweenMax.to(summary, 1, {opacity: 0, x: -30, onComplete: updateSummaryText, ease: Power4.easeIn})
container.addClass(weather.type);
weather.button.addClass('active');
// windSpeed
switch(weather.type)
{
case 'wind':
TweenMax.to(settings, 3, {windSpeed: 3, ease: Power2.easeInOut});
break;
case 'sun':
TweenMax.to(settings, 3, {windSpeed: 20, ease: Power2.easeInOut});
break;
default:
TweenMax.to(settings, 3, {windSpeed: 0.5, ease: Power2.easeOut});
break;
}
// rainCount
switch(weather.type)
{
case 'rain':
TweenMax.to(settings, 3, {rainCount: 10, ease: Power2.easeInOut});
break;
case 'thunder':
TweenMax.to(settings, 3, {rainCount: 60, ease: Power2.easeInOut});
break;
default:
TweenMax.to(settings, 1, {rainCount: 0, ease: Power2.easeOut});
break;
}
// leafCount
switch(weather.type)
{
case 'wind':
//TweenMax.to(settings, 3, {leafCount: 5, ease: Power2.easeInOut});
break;
default:
TweenMax.to(settings, 1, {leafCount: 0, ease: Power2.easeOut});
break;
}
// snowCount
switch(weather.type)
{
case 'snow':
TweenMax.to(settings, 3, {snowCount: 40, ease: Power2.easeInOut});
break;
default:
TweenMax.to(settings, 1, {snowCount: 0, ease: Power2.easeOut});
break;
}
// sun position
switch(weather.type)
{
case 'sun':
TweenMax.to(sun.node, 4, {x: sizes.card.width / 2, y: sizes.card.height / 2, ease: Power2.easeInOut});
TweenMax.to(sunburst.node, 4, {scale: 1, opacity: 0.8, y: (sizes.card.height/2) + (sizes.card.offset.top), ease: Power2.easeInOut});
break;
default:
TweenMax.to(sun.node, 2, {x: sizes.card.width / 2, y: -100, leafCount: 0, ease: Power2.easeInOut});
TweenMax.to(sunburst.node, 2, {scale: 0.4, opacity: 0, y: (sizes.container.height/2)-50, ease: Power2.easeInOut});
break;
}
// lightning
startLightningTimer();
}
const lib = [[0, 'Soleil', 4],[1, 'Peu nuageux', 4],[2, 'Ciel voilé', 1],[3, 'Nuageux', 1],[4, 'Très nuageux', 1],[5, 'Couvert', 1],[6, 'Brouillard', 1],[7, 'Brouillard givrant', 1],[10, 'Pluie faible', 2],[11, 'Pluie modérée', 2],[12, 'Pluie forte', 2],[13, 'Pluie faible verglaçante', 2],[14, 'Pluie modérée verglaçante', 2],[15, 'Pluie forte verglaçante', 2],[16, 'Bruine', 2],[20, 'Neige faible', 0],[21, 'Neige modérée', 0],[22, 'Neige forte', 0],[30, 'Pluie et neige mêlées faibles', 0],[31, 'Pluie et neige mêlées modérées', 0],[32, 'Pluie et neige mêlées fortes', 0],[40, 'Averses de pluie locales et faibles', 2],[41, 'Averses de pluie locales', 2],[42, 'Averses locales et fortes', 2],[43, 'Averses de pluie faibles', 2],[44, 'Averses de pluie', 2],[45, 'Averses de pluie fortes', 2],[46, 'Averses de pluie faibles et fréquentes', 2],[47, 'Averses de pluie fréquentes', 2],[48, 'Averses de pluie fortes et fréquentes', 2],[60, 'Averses de neige localisées et faibles', 0],[61, 'Averses de neige localisées', 0],[62, 'Averses de neige localisées et fortes', 0],[63, 'Averses de neige faibles', 0],[64, 'Averses de neige', 0],[65, 'Averses de neige fortes', 0],[66, 'Averses de neige faibles et fréquentes', 0],[67, 'Averses de neige fréquentes', 0],[68, 'Averses de neige fortes et fréquentes', 0],[70, 'Averses de pluie et neige mêlées localisées et faibles', 2],[71, 'Averses de pluie et neige mêlées localisées', 2],[72, 'Averses de pluie et neige mêlées localisées et fortes', 2],[73, 'Averses de pluie et neige mêlées faibles', 2],[74, 'Averses de pluie et neige mêlées', 2],[75, 'Averses de pluie et neige mêlées fortes', 2],[76, 'Averses de pluie et neige mêlées faibles et nombreuses', 2],[77, 'Averses de pluie et neige mêlées fréquentes', 2],[78, 'Averses de pluie et neige mêlées fortes et fréquentes', 2],[100, 'Orages faibles et locaux', 3],[101, 'Orages locaux', 3],[102, 'Orages fort et locaux', 3],[103, 'Orages faibles', 3],[104, 'Orages', 3],[105, 'Orages forts', 3],[106, 'Orages faibles et fréquents', 3],[107, 'Orages fréquents', 3],[108, 'Orages forts et fréquents', 3],[120, 'Orages faibles et locaux de neige ou grésil', 3],[121, 'Orages locaux de neige ou grésil', 3],[122, 'Orages locaux de neige ou grésil', 3],[123, 'Orages faibles de neige ou grésil', 3],[124, 'Orages de neige ou grésil', 3],[125, 'Orages de neige ou grésil', 3],[126, 'Orages faibles et fréquents de neige ou grésil', 3],[127, 'Orages fréquents de neige ou grésil', 3],[128, 'Orages fréquents de neige ou grésil', 3],[130, 'Orages faibles et locaux de pluie et neige mêlées ou grésil', 3],[131, 'Orages locaux de pluie et neige mêlées ou grésil', 3],[132, 'Orages fort et locaux de pluie et neige mêlées ou grésil', 3],[133, 'Orages faibles de pluie et neige mêlées ou grésil', 3],[134, 'Orages de pluie et neige mêlées ou grésil', 3],[135, 'Orages forts de pluie et neige mêlées ou grésil', 3],[136, 'Orages faibles et fréquents de pluie et neige mêlées ou grésil', 3],[137, 'Orages fréquents de pluie et neige mêlées ou grésil', 3],[138, 'Orages forts et fréquents de pluie et neige mêlées ou grésil', 3],[140, 'Pluies orageuses', 3],[141, 'Pluie et neige mêlées à caractère orageux', 3],[142, 'Neige à caractère orageux', 3],[210, 'Pluie faible intermittente', 2],[211, 'Pluie modérée intermittente', 2],[212, 'Pluie forte intermittente', 2],[220, 'Neige faible intermittente', 0],[221, 'Neige modérée intermittente', 0],[222, 'Neige forte intermittente', 0],[230, 'Pluie et neige mêlées', 0],[231, 'Pluie et neige mêlées', 0],[232, 'Pluie et neige mêlées', 0],[235, 'Averses de grêle']];
const Month = ["Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre"];
const Days = ["Dimanche", "Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi"];
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(setPos);
} else {
document.getElementById('summary').innerHTML = 'Accès à la position imposible';
}
}
async function setPos(position){
POS = position.coords.latitude + ',' + position.coords.longitude;
document.getElementById('summary').innerHTML = '';
await Update();
}
async function Update(){
url = 'https://api.meteo-concept.com/api/forecast/nextHours?token=86e36b5541fae0c4940f74c0962ae6b08137bb416bcaf06cfb98d1bfc7945a02&latlng=' + POS;
const myHeaders = new Headers();
myHeaders.append('Accept', 'application/json');
let response = await fetch(url, {
method: 'GET',
headers: myHeaders,
});
if (response.status === 200) {
datas = await response.json();
console.log(datas)
var temp = datas.forecast[0].temp2m + '<span>c</span>';
for (libele in lib){
if (lib[libele][0] == datas.forecast[0].weather){
name = lib[libele][1]
type = lib[libele][2]
}
}
changeWeather(weather[type]);
document.getElementsByClassName('temp')[0].innerHTML = temp;
var container = document.getElementById('container');
container.style.display = '';
setTimeout("Update()", 60000);
}
}
getLocation();
function clearWebCam(){
window.frames['webcam'].document.getElementByClassName('top-main')[0].outerHtml = '';
}