-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo.js
More file actions
82 lines (79 loc) · 2.68 KB
/
Copy pathdemo.js
File metadata and controls
82 lines (79 loc) · 2.68 KB
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
/*
* LiteRadar tracker demo, MIT (c) 2019-2024 miktim@mail.ru
*/
var demo = {
isRunning: false,
interval: null,
demos: [],
// timeout in seconds!
start: function (position, timeout, demos) { //
position = position || [51.505, - 0.09];
Tracker.SourceLocation().update(); // test trackererror event
timeout = timeout || 3;
demos = demos || 30;
if (this.isRunning === true)
return;
this.isRunning = true;
for (var i = 1; i <= demos; i++) {
var d = Tracker.SourceLocation();
d.id = 'id Demo' + i;
d.name = 'Demo' + i;
d.timeout = timeout;
d.setPosition(position);
d.heading = this.randInt(0, 360);
d.iconid = 1; //
d.timestamp = Date.now();
this.demos.push(this.moveRandom(d));
}
this.updateDemos();
this.interval = setInterval(function (self) {
self.updateDemos();
}, timeout * 1000, this); //!IE9
Tracker.Message('Demo started').update();
},
stop: function () {
if (this.interval) {
clearInterval(this.interval);
this.isStarted = false;
Tracker.off('trackererror,trackeraction');
}
},
// http://stackoverflow.com/questions/1527803/generating-random-whole-numbers-in-javascript-in-a-specific-range
randInt: function (minInt, maxInt) {
if (minInt === maxInt)
return minInt;
return Math.floor((Math.random() * (maxInt - minInt + 1)) + minInt);
},
randDbl: function (minDbl, maxDbl) {
if (minDbl === maxDbl)
return minDbl;
return (Math.random() * (maxDbl - minDbl)) + minDbl;
},
moveRandom: function (d) {
d.heading = (this.randInt(d.heading - 45, d.heading + 45) + 360) % 360;
var dist = this.randDbl(10, 50); // distance in meters
d.setPosition(Tracker.geoUtil.radialPoint(d.getPosition(), d.heading, dist));
d.speed = dist / ((Date.now() - d.timestamp) / 1000); //meters per second
d.accuracy = this.randDbl(10, 25); // radius!
d.timestamp = Date.now();
return d;
},
updateDemos: function () {
for (var i in this.demos) {
try {
this.moveRandom(this.demos[i]).update();
} catch (e) {
Tracker.Message(e.message).update();
}
}
}
};
Tracker.whenReady(function (e) {
Tracker.once('trackeraction', function (e) {
console.log(e);
}).on('trackererror', function (e) {
console.log(e);
});
window.addEventListener('beforeunload', demo.stop);
demo.start(e.eventObj.mapCenter);
});