-
Notifications
You must be signed in to change notification settings - Fork 0
/
map.js
623 lines (586 loc) · 27.2 KB
/
map.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
/*
(!) All variables that start with VALUE_ or UPPERCASE are declared in <values.js>
*/
var map;
var currentPosition;
var currentRegion; /* The current region where the user is located */
var currentPositionMarker = null;
var idLocationChangeListener;
var markers = []; /* All markers displayed on map */
var markersArea = []; /* All polygons (markers area) on map */
var hide_markers = false; /* Boolean variable for hiding markers and polygons */
var infoWindowContent; /* Custom InfoWindow for marker */
var isValidData = true; /* The data received from database is valid? */
var isLocationTrackingEnabled = false; /* Is location tracking enabled or not */
var welcomeRegionMessage; /* The welcome box - when the user enters a region */
var welcomeMessageIsActive = false;
var welcomeMessageList = [];
var currentRegionWeather; /* The weather icon of the current zoomed region */
var locationTrackingIcon; /* Location tracking icon */
/* Buttons over map */
var hideMarkersBtn;
var enableLocationBtn;
/* Initialize and add the map */
function initMap() {
/* The map, centered at VALUES_mapStartCoordinates, with variables from <values.js> */
map = new google.maps.Map(document.getElementById("map"), {
zoom: VALUES_mapStartZoom,
center: VALUES_mapStartCoordinates,
mapTypeId: VALUES_mapStartType
});
currentPosition = new google.maps.LatLng(VALUES_NOT_UPDATED_LOCATION.lat, VALUES_NOT_UPDATED_LOCATION.lng);
currentRegion = null; /* There is no region on map yet */
}
/* Initialize all elements from HTML file */
function initElements() {
currentRegionWeather = document.getElementById("currentRegionWeather");
hideMarkersBtn = document.getElementById("btnHideMarkers");
locationTrackingIcon = document.getElementById("btnEnableLocationTracking");
enableLocationBtn = document.getElementById("btnEnableLocation");
welcomeRegionMessage = document.getElementById("welcomeRegion");
/* Set icon for buttons */
hideMarkersBtn.src = VALUES_hide_map_markers;
locationTrackingIcon.src = VALUES_enable_location_tracking;
enableLocationBtn.src = VALUES_enable_location;
/* Hide the current region weather icon */
currentRegionWeather.style.visibility = "hidden";
/* Set a welcome message when the map is ready */
setWelcome(true, undefined);
/* Add listeners for map */
/* When zoom is changed, draged or tilesloaded
check if the minimum zoom is big enough to display region weather
*/
map.addListener("zoom_changed", onMapEvent, false);
map.addListener("dragend", onMapEvent, false);
map.addListener("tilesloaded", onMapEvent, false);
/* Set currentPosition to a default coordinates - to detect if the location was moved or updated */
}
/* Initialize location tracking */
function enableLocation() {
/* Check if location is already enabled */
if (enableLocationBtn.src == VALUES_disabling_location) {
/* Change the button text for enabling location */
enableLocationBtn.src = VALUES_enable_location;
/* Disable location tracking too - location can not be tracked without new coordinates */
enableLocationTracking();
/* Clear listener (location moving) */
navigator.geolocation.clearWatch(idLocationChangeListener);
/* Remove the location tracking marker */
if (currentPositionMarker == null) return;
currentPositionMarker.setMap(null);
currentPositionMarker = null;
return;
}
/* Set location tracking when user activate location */
enableLocationTracking();
/* Check if GEOlocation is available */
if (navigator.geolocation) {
/* GEOlocation is available and now get location */
navigator.geolocation.getCurrentPosition(
(position) => {
/* Set listener for location change */
idLocationChangeListener = navigator.geolocation.watchPosition(onLocationChange);
onLocationChange(position);
/* Change the button text for disabling command */
enableLocationBtn.src = VALUES_disabling_location;
},
showError /* This function catches the errors */
);
} else {
/* Browser doesn't support Geolocation */
alert(STRING_CATCH_GEOLOCATION_NOT_SUPPORTED);
}
}
/* Enable or disable location tracking - move or not the map acording to new position */
function enableLocationTracking() {
/* Check if the location tracking is already enabled */
if (isLocationTrackingEnabled) { /* Location tracking is enabled */
isLocationTrackingEnabled = false; /* Disable location tracking */
/* Set icon for enabling location tracking - now is disabled */
locationTrackingIcon.src = VALUES_enable_location_tracking;
} else { /* Location tracking is disabled */
isLocationTrackingEnabled = true; /* Enabled location tracking */
if (isLocationUpdated(currentPosition)) { /* If there is updated position (not the default one) */
map.panTo(currentPosition); /* Start location tracking - pan to current location */
}
/* Set icon for disabling location tracking - now is enabled */
locationTrackingIcon.src = VALUES_disabling_location_tracking;
}
}
/*
Called when received data from database
<weatherRegions> and <weatherData> are assigned in <init-firebase.js>
*/
function readyToGetDataBaseData() {
/* Every region must have data - the list must have same number of elements */
if (weatherRegions.length != weatherData.length) return;
/* For each new data, old markers and polygons are removed and replaced */
clearMarkers();
markers = [];
markersArea = [];
/* Add a marker for each region in database */
for (let i = 0; i < weatherRegions.length; i++) {
addMarker(weatherRegions[i], weatherData[i]);
}
}
function onLocationChange(position) {
/* Check if the device is moving */
//if (currentPosition == null || position == null || position.coords == null) return;
let moving = false;
/* Check if is first location reading */
if (currentPosition.lat() != VALUES_NOT_UPDATED_LOCATION.lat &&
currentPosition.lng() != VALUES_NOT_UPDATED_LOCATION.lng) {
/* Check if speed is defined */
if (position.coords.speed != null ||
position.coords.speed != undefined ||
position.coords.speed != "undefined") {
/* Check if current coordinates are modified - the device is moving */
if (currentPosition.lat() != position.coords.latitude ||
currentPosition.lng() != position.coords.longitude) {
/* Device is moving */
moving = true;
}
}
}
/* Update current position variable */
currentPosition = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
checkDangerRegion(moving); /* Check if the user entered a danger region */
if (moving) {
/* Set the moving marker icon */
addLocationMarker(currentPosition, VALUES_moving_location_icon);
} else {
/* Set the stationary marker icon */
addLocationMarker(currentPosition, null);
}
if (isLocationTrackingEnabled) {
/* Set map center to current location */
map.setCenter(currentPosition);
/* Move map to current location */
map.panTo(currentPosition);
}
}
/* Add markers on map */
function addMarker(region, regionData) {
var coords = getLatLon(region); /* Convert string coordinates to LatLng class */
if (coords == null) return; /* Conversion string-LatLng failed */
/* Create the marker */
const marker = new google.maps.Marker({
position: coords,
icon: getMarkerIcon(VALUES_weather_icons[regionData["weather"]]),
title: region,
map: map,
});
/* If the user won't see the markers */
if (hide_markers) marker.setVisible(false);
/* Create the custom InfoWindow for marker */
const infowindow = new google.maps.InfoWindow({
content: getInfoWindow(region, regionData),
maxWidth: 1000
});
/* Set listener on marker to open the InfoWindow when is clicked */
marker.addListener("click", () => {
/* If the InfoWindow is opened already, close it */
if (isInfoWindowOpened(infowindow)) infowindow.close();
/* Open InfoWindow for the clicked marker */
else {
infowindow.open(map, marker);
}
});
/* Store the marker in list */
markers.push(marker);
/* Call the function for creating polygon for each marker (whici is the region area) */
addRegionArea(coords, regionData);
}
/* Add polygons around each marker on map - these polygons are the region area */
function addRegionArea(position, regionData) {
/*
Define the LatLng coordinates for the polygon's path
<VALUES_mapRegionAreaDimension> is defined in <values.js>
and reprezents the region area radius
*/
const areaCoords = [
{ lat: position.lat() - VALUES_mapRegionAreaDimension, lng: position.lng() - VALUES_mapRegionAreaDimension },
{ lat: position.lat() + VALUES_mapRegionAreaDimension, lng: position.lng() - VALUES_mapRegionAreaDimension },
{ lat: position.lat() + VALUES_mapRegionAreaDimension, lng: position.lng() + VALUES_mapRegionAreaDimension },
{ lat: position.lat() - VALUES_mapRegionAreaDimension, lng: position.lng() + VALUES_mapRegionAreaDimension },
];
/* Get weather string from list (ex: "Moderate rain") */
let weather = regionData["weather"];
let color = getWeatherAreaColor(weather);
/* Construct the polygon */
const poly = new google.maps.Polygon({
paths: areaCoords,
strokeColor: "#000",
/* Black border */
strokeOpacity: 0.3,
/* Opacity border */
strokeWeight: 1,
/* Thickness border */
fillColor: color,
/* Inside area color */
fillOpacity: 0.3,
/* Inside area color opacity */
});
/* Store polygon in list */
markersArea.push(poly);
/* If the user won't see markers and polygons, hide it */
if (hide_markers) poly.setVisible(false);
/* Display polygon on map */
poly.setMap(map);
}
function addLocationMarker(position, icon) {
/* Remove previous location marker */
if (currentPositionMarker != null) currentPositionMarker.setMap(null);
/* Create the marker */
currentPositionMarker = new google.maps.Marker({
/* If the position is not updated, take the default location */
position: isLocationUpdated(position) ?
position : new google.maps.LatLng(VALUES_mapStartCoordinates.lat, VALUES_mapStartCoordinates.lng),
map: map,
});
// alert(isLocationUpdated(position) + " " + position);
if (icon == null) return;
currentPositionMarker.setIcon(getMarkerIcon(icon));
}
/*
Hide/Show the current region weather icon when the zoom is bigger than <VALUES_MIN_ZOOM_IN>
This is usefull when the zoom is too higher to see the region weather icon
*/
function onMapEvent() {
/* Check if the current zoom is grater or equal to <VALUES_MIN_ZOOM_IN> */
if (map.getZoom() >= VALUES_MIN_ZOOM_IN) {
let weather; /* Store here the current region weather - where the user zoom in */
try {
/* If the region is found in markers list, get its weather data */
weather = weatherData[markers.indexOf(getRegionMarker(true))]["weather"];
currentRegionWeather.style.visibility = "visible";
/* Set the region icon for its weather */
currentRegionWeather.src = VALUES_weather_icons[weather];
} catch (err) { /* The region wasn't found or other error - usually TypeError */
/* Hide the icon - because the region wasn't found in markers list - can be: map draged outsite the region */
currentRegionWeather.style.visibility = "hidden";
return;
}
} else { /* The user zoom out the map - the region weather icon can be seen on map */
/* Hide the static region weather icon and remove the image icon */
currentRegionWeather.style.visibility = "hidden";
currentRegionWeather.src = "//:0";
}
}
/* Sets the map on all markers in the array */
function setMapOnAll(Map) {
if (markers.length == 0) return; /* No markers */
/* Diplay all markers and polygons */
for (let i = 0; i < markers.length; i++) {
markers[i].setMap(Map);
markers[i].setVisible(true);
markersArea[i].setMap(Map);
markersArea[i].setVisible(true);
}
}
/* Shows any markers currently in the array */
function showMarkers() {
setMapOnAll(map);
}
/* Called by HTML button to hide/show markers and polygons */
function hideMarkers() {
/* Invert boolean variable */
hide_markers = !hide_markers;
if (hide_markers == true) {
/* Change the button text */
hideMarkersBtn.src = VALUES_show_map_markers;
/* Hide all markers and polygons */
clearMarkers();
} else {
hideMarkersBtn.src = VALUES_hide_map_markers;
/* Show all markers and polygons */
showMarkers();
}
}
/* Removes the markers from the map, but keeps them in the array */
function clearMarkers() {
setMapOnAll(null);
}
/* Deletes all markers in the array by removing references to them */
function deleteMarkers() {
clearMarkers();
markers = [];
markersArea = [];
}
/* Construct custom InfoWindow for markers */
function getInfoWindow(region, regionData) {
/* Get the InfoWindow template */
infoWindowContent = VALUES_contentInfoWindows;
/* Get weather color depending on weather danger level */
let weather_color = getWeatherColor(regionData["weather"]);
/* Get gradient for air quality bar depending on percent */
let gradient_for_air_bar = getGradientForAirBar(regionData["air"]);
/* Store the predictions for region */
let predictions = [];
/* Replace placeholders with the region data */
try {
infoWindowContent = infoWindowContent
.replace(STRING_PLACEHOLDER_REGION, region)
.replace(STRING_PLACEHOLDER_WEATHER, regionData["weather"])
.replace(STRING_PLACEHOLDER_WEATHER_COLOR, weather_color)
.replace(STRING_PLACEHOLDER_TEMPERATURE, regionData["temperature"])
.replace(STRING_PLACEHOLDER_HUMIDITY, regionData["humidity"])
.replace(STRING_PLACEHOLDER_AIR, regionData["air"])
.replace(STRING_PLACEHOLDER_AIR_DATA, regionData["air"] + "%")
.replace(STRING_PLACEHOLDER_AIR_DATA_MIDDLE_GRADIENT_BAR, gradient_for_air_bar["MIDDLE"])
.replace(STRING_PLACEHOLDER_AIR_DATA_STOP_GRADIENT_BAR, gradient_for_air_bar["STOP"]);
/* Check if prediction lists are valid and have data */
if (predictionData != null && predictionData != undefined && predictionRegions != null && predictionRegions != undefined) {
let index = isRegionRegistered(predictionRegions, region); // calculate the region index in list
/* Check if the index is valid and the prediction for the current region exists and are valid */
if (index >= 0 && index <= 11 && predictionData[index] != undefined && predictionData[index] != null) {
let i = 0; // index of the prediction (there are 3 predictions)
/* Get through all 3 predictions */
for (const [k, val] of Object.entries(predictionData[index])) {
let time = k.split(":"); // split the time to get only the hour and minute
/* Replace the placeholder with the prediction data */
predictions[i++] = VALUES_contentInfoWindowsPrediction
.replace(STRING_PLACEHOLDER_PREDICTION_TIME, time[3] + ":" + time[4])
.replace(STRING_PLACEHOLDER_PREDICTION_IMAGE, VALUES_weather_icons[VALUES_weather_string[getRegionIndex(val['code'])]])
.replace(STRING_PLACEHOLDER_PREDICTION_PERCENT, val['code_p'])
.replace(STRING_PLACEHOLDER_PREDICTION_WEATHER, VALUES_weather_string[getRegionIndex(val['code'])])
.replace(STRING_PLACEHOLDER_PREDICTION_TEMPERATURE, val['temperature'])
.replace(STRING_PLACEHOLDER_PREDICTION_TEMPERATURE_PERCENT, val['temperature_p'])
.replace(STRING_PLACEHOLDER_PREDICTION_HUMIDITY, val['humidity'])
.replace(STRING_PLACEHOLDER_PREDICTION_HUMIDITY_PERCENT, val['humidity_p']);
}
/* Replace all placeholders for prediction with the prediction data builded above */
infoWindowContent = infoWindowContent
.replace(STRING_PLACEHOLDER_PREDICTION1, predictions[0])
.replace(STRING_PLACEHOLDER_PREDICTION2, predictions[1])
.replace(STRING_PLACEHOLDER_PREDICTION3, predictions[2])
}
}
} catch (err) { /* Catch errors */
if (isValidData == true) {
if (err instanceof ReferenceError) {
alert(STRING_CATCH_CORRUPTED_RECEIVED_DATA);
} else {
alert(STRING_CATCH_INVALID_RECEIVED_DATA + "\n" + err);
}
isValidData = false;
}
}
if (!isValidData) {
return VALUES_contentInfoWindowCorrupted;
}
isValidData = true;
return infoWindowContent;
}
/* Get the region focused by user with a zoom of minimum <VALUES_MIN_ZOOM_IN> */
function getRegionMarker(focused) {
let center;
/* Get focused region - where the user zoom in */
if (focused == true) center = map.getCenter();
/* Get region of the current position - using location coordinates */
else center = currentPosition;
for (marker of markers) {
let lat = marker.getPosition().lat();
let lng = marker.getPosition().lng();
let area = VALUES_mapRegionAreaDimension;
if (
/* Left-top point */
center.lat() <= lat + area &&
center.lng() >= lng - area &&
/* Right-top point */
center.lat() <= lat + area &&
center.lng() <= lng + area &&
/* Left-top point */
center.lat() >= lat - area &&
center.lng() >= lng - area &&
/* Right-bottom point */
center.lat() >= lat - area &&
center.lng() <= lng + area
) {
return marker;
}
}
return null;
}
/* Regions in database are stored as coordinates, but without comma or point
this function get coordinates without comma or point and return LatLon */
function getLatLon(region) {
/*
Regions stored in data base have 4 values separated with spaces
Example: 47 60 26 23 is the region that includes all coordinates between:
[47.6000, 26.2300] - [47.6999, 26.2399]
*/
let split = region.split(" ");
if (split.length != 4 || !isNumber(split)) return null;
/* Rebuild region coordinates - string to LatLng class */
let lat = parseFloat(split[0] + "." + split[1]);
let lon = parseFloat(split[2] + "." + split[3]);
return new google.maps.LatLng(lat, lon);
}
/* Check if a string can be converted to a number */
function isNumber(string) {
for (let i = 0; i < string.length; i++) {
if (parseInt(string[i]) == NaN) return false;
}
return true;
}
/* Check if a marker InfoWindow is opened */
function isInfoWindowOpened(infoWindow) {
var infoWindowsMap = infoWindow.getMap();
return (infoWindowsMap !== null && typeof infoWindowsMap !== "undefined");
}
/* Check if location is updated at least one time */
function isLocationUpdated(coords) {
try {
return (coords.lat() >= VALUES_NOT_UPDATED_LOCATION.lat && coords.lat() <= VALUES_NOT_UPDATED_LOCATION.lat + 1) ? false : true;
} catch (err) {
return true;
}
}
/* Check if the user is approaching a danger region */
function checkDangerRegion(moving) {
/* <dangerRegions> is updated in <init-firebase.js> */
if (isLocationUpdated() == false || moving == false) {
/* The location is not updated (or enabled) or the user is not moving */
return false;
}
let marker = getRegionMarker(false); /* Get the current region marker */
if (marker != currentPositionMarker && marker != undefined) {
setWelcome(true, marker);
} else {
setWelcome(false, null);
}
}
/* Restrict marker icon to a fixed resolution and fix its center for uniform zoom */
function getMarkerIcon(icon) {
if (icon == null) return null;
return new google.maps.MarkerImage(
icon,
new google.maps.Size(VALUES_marker_icon_width, VALUES_marker_icon_lenght),
new google.maps.Point(0, 0),
new google.maps.Point(VALUES_marker_icon_width / 2, VALUES_marker_icon_width / 2));
}
/* Construct gradient for air quality bar */
function getGradientForAirBar(air) {
/*
The return value will be a dictionary with 2 keys
There will be 3 colors for air quality bar
The first color will be always green - because low values means no pollution
The middle color will be red - medium danger of pollution
The end color will be violet - high danger of pollution
*/
var gradient = {
"MIDDLE": "",
/* How much red */
"STOP": "" /* How much violet */
};
/* The 3 color for RGB */
let green, red, blue;
/* Convert air percent to float */
let percent = air / 100;
/* Calculate middle color */
red = percent * 255; /* The highest air percent is, there will be more red in the bar */
green = 255 - red - (percent * 64); /* The highest air percent is, the green color will be removed in the bar */
blue = 0; /* The blue color will create violet, but only after air quality percent is bigger than 75% */
gradient["MIDDLE"] = red + ", " + green + ", " + blue; /* Assign the middle color */
blue = red / 2;
gradient["STOP"] = red + ", " + green + ", " + blue;
return gradient;
}
function getWeatherColor(weather) {
if (
weather.includes("Sun") ||
weather.includes("Moderate")
)
return VALUES_weather_color_medium_danger;
else if (
weather.includes("Heat") ||
weather.includes("Torrential") ||
weather.includes("Massive")
)
return VALUES_weather_color_high_danger;
else return VALUES_weather_color_low_danger;
}
/* Get area color depending on weather condition */
function getWeatherAreaColor(weather) {
let color = VALUES_weather_area_color_low_danger; /* Green area - no danger */
if (VALUES_weather_key_medium_danger.includes(weather)) /* Orange area - small-medium danger */
color = VALUES_weather_area_color_medium_danger;
else if (VALUES_weather_key_high_danger.includes(weather)) /* Red area - high danger */
color = VALUES_weather_area_color_high_danger;
return color;
}
/* Show and hide the welcome region */
function setWelcome(start, marker) {
/* If another message must be displayed but there is already and active one */
if (start == true && welcomeMessageIsActive) {
/* Store the marker in list to display it after current one is finished */
if (marker instanceof google.maps.Marker) {
welcomeMessageList.push(marker);
}
return;
}
if (start == true && !welcomeMessageIsActive) { /* Show the welcome message */
if (marker == undefined) { /* First welcome message - after map initialization */
welcomeRegionMessage.style.backgroundColor = VALUES_welcome_message_map_init_background_color;
welcomeRegionMessage.innerHTML = VALUES_welcome_message_map_init;
} else {
let weather = weatherData[markers.indexOf(marker)];
let danger;
welcomeRegionMessage.style.backgroundColor = getWeatherAreaColor(weather["weather"]);
/* Check if prediction lists are valid and have data */
if (dangerData != null && dangerData != undefined && dangerRegions != null && dangerRegions != undefined) {
let index = isRegionRegistered(dangerRegions, marker.getTitle()); // calculate the region index in list
/* Check if the index is valid and the prediction for the current region exists and are valid */
if (index >= 0 && index <= 11 && dangerData[index] != undefined && dangerData[index] != null) {
danger = dangerData[index];
}
}
welcomeRegionMessage.innerHTML =
VALUES_welcome_message_content
.replace(STRING_PLACEHOLDER_WEATHER, weather["weather"])
.replace(STRING_PLACEHOLDER_TEMPERATURE, weather["temperature"])
.replace(STRING_PLACEHOLDER_HUMIDITY, weather["humidity"])
.replace(STRING_PLACEHOLDER_AIR, weather["air"])
.replace(STRING_PLACEHOLDER_DANGER, danger);
}
setWelcomeMessageAnimation(true);
/* Set timeout for closing the message after a time */
setTimeout(function() { setWelcome(false, null); }, VALUES_welcome_message_duration);
} else if (start == false && welcomeMessageIsActive) { /* Hide the welcome message */
setWelcomeMessageAnimation(false);
/* The current message is closed - check if another message wanted to be displayed */
if (welcomeMessageList.length > 0) {
setTimeout(function() { setWelcome(true, welcomeMessageList.shift()); }, VALUES_welcome_message_delay_between);
}
/* welcomeRegionMessage.innerHTML = ""; */
}
}
function setWelcomeMessageAnimation(starting) {
if (starting == true && welcomeMessageIsActive == false) {
welcomeMessageIsActive = true;
welcomeRegionMessage.classList.remove('welcomeMessageEnd'); /* Remove welcome end animation */
welcomeRegionMessage.classList.add('welcomeMessageStart'); /* Add welcome start animation */
} else if (starting == false && welcomeMessageIsActive == true) {
welcomeMessageIsActive = false;
welcomeRegionMessage.classList.remove('welcomeMessageStart'); /* Remove welcome start animation */
welcomeRegionMessage.classList.add('welcomeMessageEnd'); /* Add welcome end animation */
}
}
/* Handle location error when location tracking enabling was unsuccessfull */
function showError(error) {
switch (error.code) {
case error.PERMISSION_DENIED:
alert(STRING_CATCH_GEOLOCATION_DENIED);
break;
case error.POSITION_UNAVAILABLE:
alert(STRING_CATCH_POSITION_UNAVAILABLE);
break;
case error.TIMEOUT:
alert(STRING_CATCH_GEOLOCATION_TIMEOUT);
break;
case error.UNKNOWN_ERROR:
alert(STRING_CATCH_GEOLOCATION_UNKNOWN_ERROR);
break;
}
}