@maptalks/traffic 0.87.0 → 0.87.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/maptalks.traffic.es.js +174 -170
- package/dist/maptalks.traffic.js +2 -2
- package/package.json +53 -53
|
@@ -1,41 +1,43 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @maptalks/traffic v0.87.
|
|
2
|
+
* @maptalks/traffic v0.87.2
|
|
3
3
|
* LICENSE : UNLICENSED
|
|
4
4
|
* (c) 2016-2023 maptalks.org
|
|
5
5
|
*/
|
|
6
6
|
import * as t from "maptalks";
|
|
7
7
|
|
|
8
|
-
import
|
|
8
|
+
import { GLTFLayer as i, MultiGLTFMarker as s } from "@maptalks/gl-layers";
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
import * as n from "turf";
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
let e = 0;
|
|
13
|
+
|
|
14
|
+
function r(t, i, s) {
|
|
13
15
|
return null == i || s ? (t.length !== +t.length && (t = function(t) {
|
|
14
16
|
const i = function(t) {
|
|
15
17
|
if (!function(t) {
|
|
16
18
|
return t === Object(t);
|
|
17
19
|
}(t)) return [];
|
|
18
20
|
const i = [];
|
|
19
|
-
for (const s in t)
|
|
21
|
+
for (const s in t) a(t, s) && i.push(s);
|
|
20
22
|
return i;
|
|
21
23
|
}(t), s = i.length, n = new Array(s);
|
|
22
24
|
for (let e = 0; e < s; e++) n[e] = t[i[e]];
|
|
23
25
|
return n;
|
|
24
|
-
}(t)), t[
|
|
26
|
+
}(t)), t[u(t.length - 1)]) : function(t) {
|
|
25
27
|
let i, s = 0;
|
|
26
28
|
const n = [];
|
|
27
|
-
return
|
|
29
|
+
return c(t, t => {
|
|
28
30
|
i = i(s++), n[s - 1] = n[i], n[i] = t;
|
|
29
31
|
}), n;
|
|
30
32
|
}(t).slice(0, Math.max(0, i));
|
|
31
33
|
}
|
|
32
34
|
|
|
33
|
-
function
|
|
34
|
-
const i = ++
|
|
35
|
+
function h(t) {
|
|
36
|
+
const i = ++e + "";
|
|
35
37
|
return t ? t + i : i;
|
|
36
38
|
}
|
|
37
39
|
|
|
38
|
-
function
|
|
40
|
+
function o(t, i) {
|
|
39
41
|
let s;
|
|
40
42
|
if (nativeBind && t.bind === nativeBind) return nativeBind.apply(t, slice.call(arguments, 1));
|
|
41
43
|
const n = slice.call(arguments, 2);
|
|
@@ -44,37 +46,37 @@ function h(t, i) {
|
|
|
44
46
|
ctor.prototype = t.prototype;
|
|
45
47
|
const e = new ctor;
|
|
46
48
|
ctor.prototype = null;
|
|
47
|
-
const
|
|
48
|
-
return Object(
|
|
49
|
+
const r = t.apply(e, n.concat(slice.call(arguments)));
|
|
50
|
+
return Object(r) === r ? r : e;
|
|
49
51
|
};
|
|
50
52
|
}
|
|
51
53
|
|
|
52
|
-
function
|
|
54
|
+
function u(t, i) {
|
|
53
55
|
return i || (i = t, t = 0), t + Math.floor(Math.random() * (i - t + 1));
|
|
54
56
|
}
|
|
55
57
|
|
|
56
|
-
function
|
|
57
|
-
return
|
|
58
|
+
function l(t) {
|
|
59
|
+
return c(slice.call(arguments, 1), (function(i) {
|
|
58
60
|
if (i) for (const s in i) t[s] = i[s];
|
|
59
61
|
})), t;
|
|
60
62
|
}
|
|
61
63
|
|
|
62
|
-
function
|
|
64
|
+
function c(t, i, s) {
|
|
63
65
|
if (null == t) return t;
|
|
64
66
|
if (nativeForEach && t.forEach === nativeForEach) t.forEach(i, s); else if (t.length === +t.length) {
|
|
65
67
|
for (let n = 0, e = t.length; n < e; n++) if (i.call(s, t[n], n, t) === breaker) return null;
|
|
66
68
|
} else {
|
|
67
69
|
const n = n(t);
|
|
68
|
-
for (let e = 0,
|
|
70
|
+
for (let e = 0, r = n.length; e < r; e++) if (i.call(s, t[n[e]], n[e], t) === breaker) return null;
|
|
69
71
|
}
|
|
70
72
|
return t;
|
|
71
73
|
}
|
|
72
74
|
|
|
73
|
-
function
|
|
75
|
+
function a(t, i) {
|
|
74
76
|
return hasOwnProperty.call(t, i);
|
|
75
77
|
}
|
|
76
78
|
|
|
77
|
-
class
|
|
79
|
+
class f {
|
|
78
80
|
constructor(t, i) {
|
|
79
81
|
let s, n, e;
|
|
80
82
|
if (this.factory = t, this.objects = {}, null != i && null != i.objects) for (s in e = i.objects,
|
|
@@ -105,7 +107,7 @@ class c {
|
|
|
105
107
|
}
|
|
106
108
|
}
|
|
107
109
|
|
|
108
|
-
class
|
|
110
|
+
class d {
|
|
109
111
|
constructor(t, i) {
|
|
110
112
|
this.x = t || 0, this.y = i || 0;
|
|
111
113
|
}
|
|
@@ -116,23 +118,23 @@ class a {
|
|
|
116
118
|
return Math.atan2(this.y, this.x);
|
|
117
119
|
}
|
|
118
120
|
get normalized() {
|
|
119
|
-
return new
|
|
121
|
+
return new d(this.x / this.length, this.y / this.length);
|
|
120
122
|
}
|
|
121
123
|
add(t) {
|
|
122
|
-
return new
|
|
124
|
+
return new d(this.x + t.x, this.y + t.y);
|
|
123
125
|
}
|
|
124
126
|
subtract(t) {
|
|
125
|
-
return new
|
|
127
|
+
return new d(this.x - t.x, this.y - t.y);
|
|
126
128
|
}
|
|
127
129
|
mult(t) {
|
|
128
|
-
return new
|
|
130
|
+
return new d(this.x * t, this.y * t);
|
|
129
131
|
}
|
|
130
132
|
divide(t) {
|
|
131
|
-
return new
|
|
133
|
+
return new d(this.x / t, this.y / t);
|
|
132
134
|
}
|
|
133
135
|
}
|
|
134
136
|
|
|
135
|
-
class
|
|
137
|
+
class g {
|
|
136
138
|
constructor(t, i) {
|
|
137
139
|
this.source = t, this.target = i;
|
|
138
140
|
}
|
|
@@ -149,11 +151,11 @@ class f {
|
|
|
149
151
|
return this.getPoint(.5);
|
|
150
152
|
}
|
|
151
153
|
split(t, i) {
|
|
152
|
-
let s, n, e,
|
|
154
|
+
let s, n, e, r, h, o;
|
|
153
155
|
const u = i ? function() {
|
|
154
|
-
|
|
155
|
-
for (let i =
|
|
156
|
-
return
|
|
156
|
+
h = [];
|
|
157
|
+
for (let i = r = t - 1; r <= 0 ? i <= 0 : i >= 0; r <= 0 ? i++ : i--) h.push(i);
|
|
158
|
+
return h;
|
|
157
159
|
}.apply(this) : function() {
|
|
158
160
|
o = [];
|
|
159
161
|
for (let i = 0, s = t - 1; 0 <= s ? i <= s : i >= s; 0 <= s ? i++ : i--) o.push(i);
|
|
@@ -167,19 +169,19 @@ class f {
|
|
|
167
169
|
}
|
|
168
170
|
subsegment(t, i) {
|
|
169
171
|
const s = this.vector, n = this.source.add(s.mult(t)), e = this.source.add(s.mult(i));
|
|
170
|
-
return new
|
|
172
|
+
return new g(n, e);
|
|
171
173
|
}
|
|
172
174
|
}
|
|
173
175
|
|
|
174
|
-
class
|
|
176
|
+
class w {
|
|
175
177
|
constructor(t, i, s, n) {
|
|
176
178
|
this.x = t || 0, this.y = i || 0, this.width = s || 0, this.height = n || 0;
|
|
177
179
|
}
|
|
178
180
|
copy(t) {
|
|
179
|
-
return new
|
|
181
|
+
return new w(t.x, t.y, t.width, t.height);
|
|
180
182
|
}
|
|
181
183
|
toJSON() {
|
|
182
|
-
return
|
|
184
|
+
return l({}, this);
|
|
183
185
|
}
|
|
184
186
|
area() {
|
|
185
187
|
return this.width * this.height;
|
|
@@ -198,7 +200,7 @@ class d {
|
|
|
198
200
|
}
|
|
199
201
|
center(t) {
|
|
200
202
|
return null != t && (this.x = t.x - this.width / 2, this.y = t.y - this.height / 2),
|
|
201
|
-
new
|
|
203
|
+
new d(this.x + this.width / 2, this.y + this.heigh / 2);
|
|
202
204
|
}
|
|
203
205
|
containsPoint(t) {
|
|
204
206
|
let i, s;
|
|
@@ -208,11 +210,11 @@ class d {
|
|
|
208
210
|
return this.left() <= t.left() && t.right() <= this.right() && this.top() <= t.top() && t.bottom() <= this.bottom();
|
|
209
211
|
}
|
|
210
212
|
getVertices() {
|
|
211
|
-
return [ new
|
|
213
|
+
return [ new d(this.left(), this.top()), new d(this.right(), this.top()), new d(this.right(), this.bottom()), new d(this.left(), this.bottom()) ];
|
|
212
214
|
}
|
|
213
215
|
getSide(t) {
|
|
214
216
|
const i = this.getVertices();
|
|
215
|
-
return new
|
|
217
|
+
return new g(i[t], i[(t + 1) % 4]);
|
|
216
218
|
}
|
|
217
219
|
getSectorId(t) {
|
|
218
220
|
const i = t.subtract(this.center());
|
|
@@ -227,7 +229,7 @@ class d {
|
|
|
227
229
|
}
|
|
228
230
|
}
|
|
229
231
|
|
|
230
|
-
class
|
|
232
|
+
class p {
|
|
231
233
|
constructor(t) {
|
|
232
234
|
this.intersection = t, this.time = 0, this.flipMultiplier = .4 * Math.random() - .2 + 1,
|
|
233
235
|
this.stateNum = 0, this.lightsFlipInterval = 20, this.states = [ [ "L", "", "L", "" ], [ "FR", "", "FR", "" ], [ "", "L", "", "L" ], [ "", "FR", "", "FR" ] ];
|
|
@@ -261,15 +263,15 @@ class g {
|
|
|
261
263
|
}
|
|
262
264
|
}
|
|
263
265
|
|
|
264
|
-
class
|
|
266
|
+
class m {
|
|
265
267
|
constructor(t) {
|
|
266
|
-
this.rect = t, this.id =
|
|
267
|
-
this.controlSignals = new
|
|
268
|
+
this.rect = t, this.id = h("intersection"), this.roads = [], this.inRoads = [],
|
|
269
|
+
this.controlSignals = new p(this);
|
|
268
270
|
}
|
|
269
271
|
copy(t) {
|
|
270
|
-
t.rect =
|
|
271
|
-
const i = Object.create(
|
|
272
|
-
return
|
|
272
|
+
t.rect = w.copy(t.rect);
|
|
273
|
+
const i = Object.create(m.prototype);
|
|
274
|
+
return l(i, t), i.roads = [], i.inRoads = [], i.controlSignals = new p(i), i;
|
|
273
275
|
}
|
|
274
276
|
toJSON() {
|
|
275
277
|
return {
|
|
@@ -279,17 +281,17 @@ class w {
|
|
|
279
281
|
}
|
|
280
282
|
update() {
|
|
281
283
|
let t, i, s, n, e;
|
|
282
|
-
const
|
|
283
|
-
for (i = 0, n =
|
|
284
|
-
const
|
|
285
|
-
for (s = 0, e =
|
|
284
|
+
const r = this.roads;
|
|
285
|
+
for (i = 0, n = r.length; i < n; i++) t = r[i], t.update();
|
|
286
|
+
const h = this.inRoads, o = [];
|
|
287
|
+
for (s = 0, e = h.length; s < e; s++) t = h[s], o.push(t.update());
|
|
286
288
|
return o;
|
|
287
289
|
}
|
|
288
290
|
}
|
|
289
291
|
|
|
290
|
-
class
|
|
292
|
+
class v {
|
|
291
293
|
constructor(t, i, s) {
|
|
292
|
-
this.car = t, this.position = s, this.id =
|
|
294
|
+
this.car = t, this.position = s, this.id = h("laneposition"), this.free = !0, this.tmpLane = i;
|
|
293
295
|
}
|
|
294
296
|
get lane() {
|
|
295
297
|
return this.tmpLane;
|
|
@@ -327,10 +329,10 @@ class p {
|
|
|
327
329
|
}
|
|
328
330
|
}
|
|
329
331
|
|
|
330
|
-
class
|
|
332
|
+
class M {
|
|
331
333
|
constructor(t, i, s, n) {
|
|
332
|
-
this.A = t, this.B = i, this.O = s, this.Q = n, this.AB = new
|
|
333
|
-
this.AO = new
|
|
334
|
+
this.A = t, this.B = i, this.O = s, this.Q = n, this.AB = new g(this.A, this.B),
|
|
335
|
+
this.AO = new g(this.A, this.O), this.OQ = new g(this.O, this.Q), this.QB = new g(this.Q, this.B),
|
|
334
336
|
this.len = null;
|
|
335
337
|
}
|
|
336
338
|
get length() {
|
|
@@ -340,19 +342,19 @@ class m {
|
|
|
340
342
|
return this.len;
|
|
341
343
|
}
|
|
342
344
|
getPoint(t) {
|
|
343
|
-
const i = this.AO.getPoint(t), s = this.OQ.getPoint(t), n = this.QB.getPoint(t), e = new
|
|
344
|
-
return new
|
|
345
|
+
const i = this.AO.getPoint(t), s = this.OQ.getPoint(t), n = this.QB.getPoint(t), e = new g(i, s).getPoint(t), r = new g(s, n).getPoint(t);
|
|
346
|
+
return new g(e, r).getPoint(t);
|
|
345
347
|
}
|
|
346
348
|
getDirection(t) {
|
|
347
|
-
const i = this.AO.getPoint(t), s = this.OQ.getPoint(t), n = this.QB.getPoint(t), e = new
|
|
348
|
-
return new
|
|
349
|
+
const i = this.AO.getPoint(t), s = this.OQ.getPoint(t), n = this.QB.getPoint(t), e = new g(i, s).getPoint(t), r = new g(s, n).getPoint(t);
|
|
350
|
+
return new g(e, r).direction;
|
|
349
351
|
}
|
|
350
352
|
}
|
|
351
353
|
|
|
352
|
-
class
|
|
354
|
+
class y {
|
|
353
355
|
constructor(t, i, s) {
|
|
354
|
-
this.car = t, this.current = new
|
|
355
|
-
this.next = new
|
|
356
|
+
this.car = t, this.current = new v(this.car, i, s || 0), this.current.acquire(),
|
|
357
|
+
this.next = new v(this.car), this.temp = new v(this.car), this.isChangingLanes = !1;
|
|
356
358
|
}
|
|
357
359
|
get lane() {
|
|
358
360
|
return this.temp.lane || this.current.lane;
|
|
@@ -420,8 +422,8 @@ class v {
|
|
|
420
422
|
return this.t(t, i);
|
|
421
423
|
}
|
|
422
424
|
s() {
|
|
423
|
-
const t = this.current.lane.getPoint(this.current.relativePosition), i = this.next.lane.getPoint(this.next.relativePosition), s = i.subtract(t).length, n = this.current.lane.middleLine.vector.normalized.mult(.3 * s), e = t.add(n),
|
|
424
|
-
return new
|
|
425
|
+
const t = this.current.lane.getPoint(this.current.relativePosition), i = this.next.lane.getPoint(this.next.relativePosition), s = i.subtract(t).length, n = this.current.lane.middleLine.vector.normalized.mult(.3 * s), e = t.add(n), r = this.next.lane.middleLine.vector.normalized.mult(.3 * s), h = i.subtract(r);
|
|
426
|
+
return new M(t, i, e, h);
|
|
425
427
|
}
|
|
426
428
|
h() {
|
|
427
429
|
return this.s();
|
|
@@ -446,13 +448,13 @@ class v {
|
|
|
446
448
|
}
|
|
447
449
|
}
|
|
448
450
|
|
|
449
|
-
const
|
|
451
|
+
const L = [];
|
|
450
452
|
|
|
451
|
-
class
|
|
453
|
+
class C {
|
|
452
454
|
constructor(t, i) {
|
|
453
|
-
this.type =
|
|
455
|
+
this.type = u(L.length - 1), this.id = h("car"), this.color = (300 + 240 * Math.random() | 0) % 360,
|
|
454
456
|
this.tmpSpeed = 0, this.width = 2, this.length = 2, this.maxSpeed = 30, this.s0 = 2,
|
|
455
|
-
this.timeHeadway = 1.5, this.maxAcceleration = 1, this.maxDeceleration = 3, this.trajectory = new
|
|
457
|
+
this.timeHeadway = 1.5, this.maxAcceleration = 1, this.maxDeceleration = 3, this.trajectory = new y(this, t, i),
|
|
456
458
|
this.alive = !0, this.preferedLane = null;
|
|
457
459
|
}
|
|
458
460
|
get coords() {
|
|
@@ -472,7 +474,7 @@ class y {
|
|
|
472
474
|
}
|
|
473
475
|
getAcceleration() {
|
|
474
476
|
let t;
|
|
475
|
-
const i = this.trajectory.nextCarDistance, s = Math.max(i.distance, 0), n = this.maxAcceleration, e = this.maxDeceleration,
|
|
477
|
+
const i = this.trajectory.nextCarDistance, s = Math.max(i.distance, 0), n = this.maxAcceleration, e = this.maxDeceleration, r = this.speed - (null != (t = i.car) ? t.speed : void 0) || 0, h = Math.pow(this.speed / this.maxSpeed, 4), o = this.s0, u = this.speed * this.timeHeadway, l = o + u + this.speed * r / (2 * Math.sqrt(n * e)), c = Math.pow(l / s, 2), a = 1 + u + Math.pow(this.speed, 2) / (2 * e), f = 1 - h - c - Math.pow(a / this.trajectory.distanceToStopLine, 2);
|
|
476
478
|
return this.maxAcceleration * f;
|
|
477
479
|
}
|
|
478
480
|
move(t) {
|
|
@@ -501,7 +503,7 @@ class y {
|
|
|
501
503
|
return t.target !== i.road.source;
|
|
502
504
|
}));
|
|
503
505
|
if (0 === s.length) return null;
|
|
504
|
-
return
|
|
506
|
+
return r(s);
|
|
505
507
|
}
|
|
506
508
|
pickNextLane() {
|
|
507
509
|
if (this.nextLane) throw Error("next lane is already chosen");
|
|
@@ -514,7 +516,7 @@ class y {
|
|
|
514
516
|
return t.lanesNumber - 1;
|
|
515
517
|
|
|
516
518
|
case 1:
|
|
517
|
-
return
|
|
519
|
+
return u(0, t.lanesNumber - 1);
|
|
518
520
|
|
|
519
521
|
case 2:
|
|
520
522
|
return 0;
|
|
@@ -529,7 +531,7 @@ class y {
|
|
|
529
531
|
}
|
|
530
532
|
}
|
|
531
533
|
|
|
532
|
-
class
|
|
534
|
+
class E {
|
|
533
535
|
constructor(t, i, s) {
|
|
534
536
|
this.sourceSegment = t, this.targetSegment = i, this.road = s, this.leftAdjacent = null,
|
|
535
537
|
this.rightAdjacent = null, this.leftmostAdjacent = null, this.rightmostAdjacent = null,
|
|
@@ -548,17 +550,17 @@ class C {
|
|
|
548
550
|
return this === this.leftmostAdjacent;
|
|
549
551
|
}
|
|
550
552
|
get leftBorder() {
|
|
551
|
-
return new
|
|
553
|
+
return new g(this.sourceSegment.source, this.targetSegment.target);
|
|
552
554
|
}
|
|
553
555
|
get rightBorder() {
|
|
554
|
-
return new
|
|
556
|
+
return new g(this.sourceSegment.target, this.targetSegment.source);
|
|
555
557
|
}
|
|
556
558
|
toJSON() {
|
|
557
|
-
const t =
|
|
559
|
+
const t = l({}, this);
|
|
558
560
|
return delete t.carsPositions, t;
|
|
559
561
|
}
|
|
560
562
|
update() {
|
|
561
|
-
return this.middleLine = new
|
|
563
|
+
return this.middleLine = new g(this.sourceSegment.center, this.targetSegment.center),
|
|
562
564
|
this.length = this.middleLine.length, this.direction = this.middleLine.direction;
|
|
563
565
|
}
|
|
564
566
|
getTurnDirection(t) {
|
|
@@ -583,16 +585,16 @@ class C {
|
|
|
583
585
|
let i = null, s = 1 / 0;
|
|
584
586
|
const n = this.carsPositions;
|
|
585
587
|
for (const e in n) {
|
|
586
|
-
const
|
|
587
|
-
!
|
|
588
|
+
const r = n[e], h = r.position - t.position;
|
|
589
|
+
!r.free && 0 < h && h < s && (s = h, i = r);
|
|
588
590
|
}
|
|
589
591
|
return i;
|
|
590
592
|
}
|
|
591
593
|
}
|
|
592
594
|
|
|
593
|
-
class
|
|
595
|
+
class R {
|
|
594
596
|
constructor(t, i, s) {
|
|
595
|
-
this.source = t, this.target = i, this.id =
|
|
597
|
+
this.source = t, this.target = i, this.id = h("road"), this.lanes = [], this.gridSize = s || 32,
|
|
596
598
|
this.lanesNumber = null, this.update();
|
|
597
599
|
}
|
|
598
600
|
get length() {
|
|
@@ -605,8 +607,8 @@ class L {
|
|
|
605
607
|
return this.lanes[0];
|
|
606
608
|
}
|
|
607
609
|
copy(t) {
|
|
608
|
-
const i = Object.create(
|
|
609
|
-
return
|
|
610
|
+
const i = Object.create(R.prototype);
|
|
611
|
+
return l.extend(i, t), null == i.lanes && (i.lanes = []), i;
|
|
610
612
|
}
|
|
611
613
|
toJSON() {
|
|
612
614
|
return {
|
|
@@ -621,17 +623,17 @@ class L {
|
|
|
621
623
|
return (t.sourceSideId - i - 1 + 8) % 4;
|
|
622
624
|
}
|
|
623
625
|
update() {
|
|
624
|
-
let t, i, s, n, e,
|
|
626
|
+
let t, i, s, n, e, r;
|
|
625
627
|
if (!this.source || !this.target) throw Error("incomplete road");
|
|
626
628
|
this.sourceSideId = this.source.rect.getSectorId(this.target.rect.center()), this.sourceSide = this.source.rect.getSide(this.sourceSideId).subsegment(.5, 1),
|
|
627
629
|
this.targetSideId = this.target.rect.getSectorId(this.source.rect.center()), this.targetSide = this.target.rect.getSide(this.targetSideId).subsegment(0, .5),
|
|
628
630
|
this.lanesNumber = 0 | Math.min(this.sourceSide.length, this.targetSide.length),
|
|
629
631
|
this.lanesNumber = Math.max(2, this.lanesNumber / this.gridSize | 0);
|
|
630
|
-
const
|
|
632
|
+
const h = this.sourceSide.split(this.lanesNumber, !0), o = this.targetSide.split(this.lanesNumber);
|
|
631
633
|
if (null == this.lanes || this.lanes.length < this.lanesNumber) for (null == this.lanes && (this.lanes = []),
|
|
632
|
-
t = s = 0, e = this.lanesNumber - 1; 0 <= e ? s <= e : s >= e; t = 0 <= e ? ++s : --s) null == (i = this.lanes)[t] && (i[t] = new
|
|
634
|
+
t = s = 0, e = this.lanesNumber - 1; 0 <= e ? s <= e : s >= e; t = 0 <= e ? ++s : --s) null == (i = this.lanes)[t] && (i[t] = new E(h[t], o[t], this));
|
|
633
635
|
const u = [];
|
|
634
|
-
for (t = n = 0,
|
|
636
|
+
for (t = n = 0, r = this.lanesNumber - 1; 0 <= r ? n <= r : n >= r; t = 0 <= r ? ++n : --n) this.lanes[t].sourceSegment = h[t],
|
|
635
637
|
this.lanes[t].targetSegment = o[t], this.lanes[t].leftAdjacent = this.lanes[t + 1],
|
|
636
638
|
this.lanes[t].rightAdjacent = this.lanes[t - 1], this.lanes[t].leftmostAdjacent = this.lanes[this.lanesNumber - 1],
|
|
637
639
|
this.lanes[t].rightmostAdjacent = this.lanes[0], u.push(this.lanes[t].update());
|
|
@@ -639,13 +641,12 @@ class L {
|
|
|
639
641
|
}
|
|
640
642
|
}
|
|
641
643
|
|
|
642
|
-
class
|
|
643
|
-
constructor(
|
|
644
|
-
this.toRemove = [], this.options =
|
|
644
|
+
class b {
|
|
645
|
+
constructor(t) {
|
|
646
|
+
this.toRemove = [], this.options = t || {}, this.carsNumber = this.options.carsNumber || 10,
|
|
645
647
|
this.gridSize = this.options.gridSize || 32, this.o = 0, this.u = 0, this.l = 5,
|
|
646
|
-
this.carsList = {}, this.g = new
|
|
647
|
-
|
|
648
|
-
}), this.p = "stop", this.m = [], this.v = {}, this.set();
|
|
648
|
+
this.carsList = {}, this.g = new i("traffic"), this.p = "stop", this.m = [], this.v = {},
|
|
649
|
+
this.set();
|
|
649
650
|
}
|
|
650
651
|
run() {
|
|
651
652
|
this.p = "running", this.M();
|
|
@@ -654,14 +655,14 @@ class E {
|
|
|
654
655
|
this.p = "stop";
|
|
655
656
|
}
|
|
656
657
|
remove() {
|
|
657
|
-
this.
|
|
658
|
-
}
|
|
659
|
-
setSymbols(
|
|
660
|
-
this.m =
|
|
661
|
-
for (let
|
|
662
|
-
const
|
|
663
|
-
this.v[
|
|
664
|
-
symbol:
|
|
658
|
+
this.L && cancelAnimationFrame(this.L), this.g.remove(), delete this.map;
|
|
659
|
+
}
|
|
660
|
+
setSymbols(t) {
|
|
661
|
+
this.m = t;
|
|
662
|
+
for (let t = 0; t < this.m.length; t++) {
|
|
663
|
+
const i = this.m[t];
|
|
664
|
+
this.v[i.url] = new s([], {
|
|
665
|
+
symbol: i
|
|
665
666
|
}).addTo(this.g);
|
|
666
667
|
}
|
|
667
668
|
}
|
|
@@ -673,11 +674,11 @@ class E {
|
|
|
673
674
|
let s, n = i - this.o || 0;
|
|
674
675
|
n > 100 && (n = 100), this.o = i, this.onTick(this.l * n / 1e3);
|
|
675
676
|
let e = this.toRemove.length;
|
|
676
|
-
for (;e--; ) this.
|
|
677
|
+
for (;e--; ) this.C(this.toRemove[e]);
|
|
677
678
|
this.clearTmpRemove();
|
|
678
|
-
const
|
|
679
|
-
for (s in
|
|
680
|
-
this.
|
|
679
|
+
const r = this.cars.all();
|
|
680
|
+
for (s in r) this.R(r[s], s);
|
|
681
|
+
this.L = window.requestAnimationFrame(this.M.bind(this));
|
|
681
682
|
}
|
|
682
683
|
N() {
|
|
683
684
|
for (const t in this.v) this.v[t].removeData();
|
|
@@ -690,8 +691,8 @@ class E {
|
|
|
690
691
|
const s = i.id.substring(3);
|
|
691
692
|
if (this.carsList[s]) {
|
|
692
693
|
if (!i) return;
|
|
693
|
-
const n = i.coords, e = i.direction,
|
|
694
|
-
this.carsList[s].coordinates =
|
|
694
|
+
const n = i.coords, e = i.direction, r = this.map, h = r.pointAtResToCoordinate(new t.Point(n.x / this.gridSize, n.y / this.gridSize), r.getGLRes()), o = e / Math.PI * 180 + 90;
|
|
695
|
+
this.carsList[s].coordinates = h, this.carsList[s].rotation = [ 0, 0, o ];
|
|
695
696
|
const u = this.I(s), l = this.carsList[s].url;
|
|
696
697
|
u > -1 ? this.v[l].updateData(u, this.carsList[s]) : this.v[l].addData(this.carsList[s]);
|
|
697
698
|
} else {
|
|
@@ -714,9 +715,9 @@ class E {
|
|
|
714
715
|
easing: "out"
|
|
715
716
|
}, (function(t) {
|
|
716
717
|
if ("running" === t.state.playState) {
|
|
717
|
-
let
|
|
718
|
-
"show" === s ? (
|
|
719
|
-
i.color = [ 1, 1, 1,
|
|
718
|
+
let r = 0;
|
|
719
|
+
"show" === s ? (r = t.styles.symbol.transparent, i.color = [ 1, 1, 1, r ]) : "hide" === s && (r = 1 - t.styles.symbol.transparent,
|
|
720
|
+
i.color = [ 1, 1, 1, r ], r < .01 && setTimeout((function() {
|
|
720
721
|
const t = e.I(n);
|
|
721
722
|
if (!e.carsList[n]) return;
|
|
722
723
|
const i = e.carsList[n].url;
|
|
@@ -731,22 +732,22 @@ class E {
|
|
|
731
732
|
const s = i.url;
|
|
732
733
|
return this.v[s].getAllData().indexOf(this.carsList[t]);
|
|
733
734
|
}
|
|
734
|
-
|
|
735
|
+
C(t) {
|
|
735
736
|
const i = t.substring(3);
|
|
736
737
|
null != this.carsList[i] && this.showHideCar(this.carsList[i], "hide", i);
|
|
737
738
|
}
|
|
738
739
|
get instantSpeed() {
|
|
739
740
|
const t = function(t, i, s) {
|
|
740
741
|
const n = [];
|
|
741
|
-
return null == t ? n : nativeMap && t.map === nativeMap ? t.map(i, s) : (
|
|
742
|
-
n.push(i.call(s, t, e,
|
|
742
|
+
return null == t ? n : nativeMap && t.map === nativeMap ? t.map(i, s) : (c(t, (t, e, r) => {
|
|
743
|
+
n.push(i.call(s, t, e, r));
|
|
743
744
|
}), n);
|
|
744
745
|
}(this.cars.all(), t => t.speed);
|
|
745
746
|
return 0 === t.length ? 0 : function(t, i, s, n) {
|
|
746
747
|
let e = arguments.length > 2;
|
|
747
|
-
return null == t && (t = []), nativeReduce && t.reduce === nativeReduce ? (n && (i =
|
|
748
|
-
e ? t.reduce(i, s) : t.reduce(i)) : (
|
|
749
|
-
e ? s = i.call(n, s, t,
|
|
748
|
+
return null == t && (t = []), nativeReduce && t.reduce === nativeReduce ? (n && (i = o(i, n)),
|
|
749
|
+
e ? t.reduce(i, s) : t.reduce(i)) : (c(t, (t, r, h) => {
|
|
750
|
+
e ? s = i.call(n, s, t, r, h) : (s = t, e = !0);
|
|
750
751
|
}), s);
|
|
751
752
|
}(t, (function(t, i) {
|
|
752
753
|
return t + i;
|
|
@@ -760,11 +761,11 @@ class E {
|
|
|
760
761
|
this.S = t, this.g.addTo(t);
|
|
761
762
|
}
|
|
762
763
|
set(t) {
|
|
763
|
-
return null == t && (t = {}), this.intersections = new
|
|
764
|
-
this.cars = new
|
|
764
|
+
return null == t && (t = {}), this.intersections = new f(m, t.intersections), this.roads = new f(R, t.roads),
|
|
765
|
+
this.cars = new f(C, t.cars), this.carsNumber = 0;
|
|
765
766
|
}
|
|
766
767
|
save() {
|
|
767
|
-
const t =
|
|
768
|
+
const t = l({}, this);
|
|
768
769
|
return delete t.cars, window.localStorage.world = JSON.stringify(t);
|
|
769
770
|
}
|
|
770
771
|
setCarNumber(t) {
|
|
@@ -778,32 +779,32 @@ class E {
|
|
|
778
779
|
if (t = window.localStorage.world, t = t && JSON.parse(t), null == t) return null;
|
|
779
780
|
this.clear(), this.carsNumber = t.carsNumber || 0;
|
|
780
781
|
const e = t.intersections;
|
|
781
|
-
for (i in e) s = e[i], this.addIntersection(
|
|
782
|
-
const
|
|
783
|
-
for (i in
|
|
784
|
-
n.target = this.getIntersection(n.target),
|
|
785
|
-
return
|
|
786
|
-
}
|
|
787
|
-
intersectSegment(t,
|
|
788
|
-
for (let
|
|
789
|
-
const e = [ s
|
|
790
|
-
if (
|
|
791
|
-
intersectIndex:
|
|
792
|
-
coord:
|
|
782
|
+
for (i in e) s = e[i], this.addIntersection(m.copy(s));
|
|
783
|
+
const r = t.roads, h = [];
|
|
784
|
+
for (i in r) n = r[i], n = (new R).copy(n), n.source = this.getIntersection(n.source),
|
|
785
|
+
n.target = this.getIntersection(n.target), h.push(this.addRoad(n));
|
|
786
|
+
return h;
|
|
787
|
+
}
|
|
788
|
+
intersectSegment(t, i) {
|
|
789
|
+
for (let s = 0; s < i.length - 1; s++) {
|
|
790
|
+
const e = [ i[s], i[s + 1] ], r = n.lineString(e), h = n.lineIntersect(t, r);
|
|
791
|
+
if (h.features.length) return {
|
|
792
|
+
intersectIndex: s,
|
|
793
|
+
coord: h.features[0].geometry.coordinates
|
|
793
794
|
};
|
|
794
795
|
}
|
|
795
796
|
return null;
|
|
796
797
|
}
|
|
797
|
-
intersection(t,
|
|
798
|
-
const o =
|
|
799
|
-
for (let t =
|
|
800
|
-
const
|
|
798
|
+
intersection(t, i, s, e, r, h) {
|
|
799
|
+
const o = n.lineString(t);
|
|
800
|
+
for (let t = i + 1; t < e.length; t++) {
|
|
801
|
+
const n = e[t], u = this.intersectSegment(o, n);
|
|
801
802
|
if (!u) continue;
|
|
802
803
|
const l = {};
|
|
803
|
-
l[
|
|
804
|
-
pre:
|
|
804
|
+
l[i] = {
|
|
805
|
+
pre: s
|
|
805
806
|
}, l[t] = {
|
|
806
|
-
pre: u.intersectIndex +
|
|
807
|
+
pre: u.intersectIndex + h[t]
|
|
807
808
|
};
|
|
808
809
|
const c = {
|
|
809
810
|
inLines: l,
|
|
@@ -812,7 +813,7 @@ class E {
|
|
|
812
813
|
y: u.coord[1]
|
|
813
814
|
}, this.map.getGLRes())
|
|
814
815
|
};
|
|
815
|
-
|
|
816
|
+
r.push(c);
|
|
816
817
|
}
|
|
817
818
|
}
|
|
818
819
|
generateTraffic(t) {
|
|
@@ -823,15 +824,15 @@ class E {
|
|
|
823
824
|
const n = [];
|
|
824
825
|
let e = 0;
|
|
825
826
|
for (let s = 0; s < t.length; s++) {
|
|
826
|
-
const
|
|
827
|
-
for (let
|
|
828
|
-
const o = [ h
|
|
829
|
-
this.intersection(o, s, e +
|
|
827
|
+
const r = t[s];
|
|
828
|
+
for (let h = 0; h < r.length - 1; h++) {
|
|
829
|
+
const o = [ r[h], r[h + 1] ];
|
|
830
|
+
this.intersection(o, s, e + h, t, n, i);
|
|
830
831
|
}
|
|
831
|
-
e +=
|
|
832
|
+
e += r.length;
|
|
832
833
|
}
|
|
833
|
-
const
|
|
834
|
-
let
|
|
834
|
+
const r = [];
|
|
835
|
+
let h = 0;
|
|
835
836
|
const o = this.map;
|
|
836
837
|
for (let i = 0; i < t.length; i++) {
|
|
837
838
|
const s = t[i];
|
|
@@ -843,29 +844,29 @@ class E {
|
|
|
843
844
|
0 === t ? e[i] = {
|
|
844
845
|
pre: null
|
|
845
846
|
} : (s.length, e[i] = {
|
|
846
|
-
pre: t - 1 +
|
|
847
|
+
pre: t - 1 + h
|
|
847
848
|
});
|
|
848
849
|
const u = {
|
|
849
850
|
inLines: e,
|
|
850
851
|
coordinate: n
|
|
851
852
|
};
|
|
852
|
-
|
|
853
|
+
r.push(u);
|
|
853
854
|
}
|
|
854
|
-
|
|
855
|
+
h += s.length;
|
|
855
856
|
}
|
|
856
|
-
for (let t = 0; t <
|
|
857
|
-
const i =
|
|
857
|
+
for (let t = 0; t < r.length; t++) {
|
|
858
|
+
const i = r[t];
|
|
858
859
|
this.comparePrePoint(i, t, n);
|
|
859
860
|
}
|
|
860
861
|
const u = this.gridSize, l = [];
|
|
861
|
-
for (let t = 0; t <
|
|
862
|
-
const i =
|
|
863
|
-
|
|
862
|
+
for (let t = 0; t < r.length; t++) {
|
|
863
|
+
const i = r[t], s = i.coordinate.x, n = i.coordinate.y, e = new w(s * u - .5, n * u - .5, 1, 1), h = new m(e);
|
|
864
|
+
h.connectRoads = i.roads, l.push(h), this.addIntersection(h);
|
|
864
865
|
}
|
|
865
866
|
const c = [];
|
|
866
867
|
for (let t = 0; t < n.length; t++) {
|
|
867
|
-
const i = n[t], s = i.coordinate.x, e = i.coordinate.y,
|
|
868
|
-
|
|
868
|
+
const i = n[t], s = i.coordinate.x, e = i.coordinate.y, r = new w(s * u - .5, e * u - .5, 1, 1), h = new m(r);
|
|
869
|
+
h.connectRoads = i.roads, c.push(h), this.addIntersection(h);
|
|
869
870
|
}
|
|
870
871
|
for (let t = 0; t < l.length; t++) {
|
|
871
872
|
const i = l[t], s = i.connectRoads;
|
|
@@ -874,8 +875,8 @@ class E {
|
|
|
874
875
|
if (null != n.pre) {
|
|
875
876
|
let t = null;
|
|
876
877
|
const s = n.type;
|
|
877
|
-
"line" === s ? t = l[n.pre] : "line-interact" === s && (t = c[n.pre]), this.addRoad(new
|
|
878
|
-
this.addRoad(new
|
|
878
|
+
"line" === s ? t = l[n.pre] : "line-interact" === s && (t = c[n.pre]), this.addRoad(new R(i, t)),
|
|
879
|
+
this.addRoad(new R(t, i));
|
|
879
880
|
}
|
|
880
881
|
}
|
|
881
882
|
}
|
|
@@ -886,8 +887,8 @@ class E {
|
|
|
886
887
|
if (null != n.pre) {
|
|
887
888
|
let t = null;
|
|
888
889
|
const s = n.type;
|
|
889
|
-
"line" === s ? t = l[n.pre] : "line-interact" === s && (t = c[n.pre]), this.addRoad(new
|
|
890
|
-
this.addRoad(new
|
|
890
|
+
"line" === s ? t = l[n.pre] : "line-interact" === s && (t = c[n.pre]), this.addRoad(new R(i, t)),
|
|
891
|
+
this.addRoad(new R(t, i));
|
|
891
892
|
}
|
|
892
893
|
}
|
|
893
894
|
}
|
|
@@ -895,16 +896,16 @@ class E {
|
|
|
895
896
|
comparePrePoint(t, i, s) {
|
|
896
897
|
const n = this.getPre(t);
|
|
897
898
|
if (n) {
|
|
898
|
-
const {pre: e, lineIndex:
|
|
899
|
+
const {pre: e, lineIndex: r} = n;
|
|
899
900
|
for (let n = 0; n < s.length; n++) {
|
|
900
|
-
const
|
|
901
|
-
|
|
901
|
+
const h = s[n];
|
|
902
|
+
h.inLines[r] && h.inLines[r].pre === e && (t.roads = [ {
|
|
902
903
|
pre: n,
|
|
903
904
|
type: "line-interact"
|
|
904
|
-
} ],
|
|
905
|
+
} ], h.roads ? h.roads.push({
|
|
905
906
|
pre: i - 1,
|
|
906
907
|
type: "line"
|
|
907
|
-
}) :
|
|
908
|
+
}) : h.roads = [ {
|
|
908
909
|
pre: i - 1,
|
|
909
910
|
type: "line"
|
|
910
911
|
} ]);
|
|
@@ -931,9 +932,9 @@ class E {
|
|
|
931
932
|
this.refreshCars();
|
|
932
933
|
const e = this.intersections.all();
|
|
933
934
|
for (s in e) n = e[s], n.controlSignals.onTick(t);
|
|
934
|
-
const
|
|
935
|
-
for (s in
|
|
936
|
-
return
|
|
935
|
+
const r = this.cars.all(), h = [];
|
|
936
|
+
for (s in r) i = r[s], i.move(t), i.alive ? h.push(void 0) : h.push(this.removeCar(i));
|
|
937
|
+
return h;
|
|
937
938
|
}
|
|
938
939
|
refreshCars() {
|
|
939
940
|
return this.cars.length < this.carsNumber && this.addRandomCar(), this.cars.length > this.carsNumber ? this.removeRandomCar() : null;
|
|
@@ -964,14 +965,17 @@ class E {
|
|
|
964
965
|
}
|
|
965
966
|
addRandomCar() {
|
|
966
967
|
let t;
|
|
967
|
-
const i =
|
|
968
|
-
return null != i && (t =
|
|
968
|
+
const i = r(this.roads.all());
|
|
969
|
+
return null != i && (t = r(i.lanes), null != t) ? this.addCar(new C(t)) : null;
|
|
969
970
|
}
|
|
970
971
|
removeRandomCar() {
|
|
971
|
-
const t =
|
|
972
|
+
const t = r(this.cars.all());
|
|
972
973
|
return null != t ? this.removeCar(t) : null;
|
|
973
974
|
}
|
|
974
975
|
}
|
|
975
976
|
|
|
976
|
-
"undefined" != typeof window && window.maptalks && (window.maptalks.TrafficScene =
|
|
977
|
-
|
|
977
|
+
"undefined" != typeof window && window.maptalks && (window.maptalks.TrafficScene = b);
|
|
978
|
+
|
|
979
|
+
export { b as TrafficScene };
|
|
980
|
+
|
|
981
|
+
"undefined" != typeof console && console.log("@maptalks/traffic v0.87.2");
|
package/dist/maptalks.traffic.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @maptalks/traffic v0.87.
|
|
2
|
+
* @maptalks/traffic v0.87.2
|
|
3
3
|
* LICENSE : UNLICENSED
|
|
4
4
|
* (c) 2016-2023 maptalks.org
|
|
5
5
|
*/
|
|
6
|
-
!function(t,i){"object"==typeof exports&&"undefined"!=typeof module?i(require("maptalks"),require("turf")):"function"==typeof define&&define.amd?define(["maptalks","turf"],i):i((t="undefined"!=typeof globalThis?globalThis:t||self).maptalks,t.turf)}(this,(function(t,i){"use strict";function s(t){if(t&&t.t)return t;var i=Object.create(null);return t&&Object.keys(t).forEach((function(s){if("default"!==s){var n=Object.getOwnPropertyDescriptor(t,s);Object.defineProperty(i,s,n.get?n:{enumerable:!0,get:function(){return t[s]}})}})),i.default=t,Object.freeze(i)}var n=s(t),e=s(i);let r=0;function h(t,i,s){return null==i||s?(t.length!==+t.length&&(t=function(t){const i=function(t){if(!function(t){return t===Object(t)}(t))return[];const i=[];for(const s in t)f(t,s)&&i.push(s);return i}(t),s=i.length,n=new Array(s);for(let e=0;e<s;e++)n[e]=t[i[e]];return n}(t)),t[l(t.length-1)]):function(t){let i,s=0;const n=[];return a(t,t=>{i=i(s++),n[s-1]=n[i],n[i]=t}),n}(t).slice(0,Math.max(0,i))}function o(t){const i=++r+"";return t?t+i:i}function u(t,i){let s;if(nativeBind&&t.bind===nativeBind)return nativeBind.apply(t,slice.call(arguments,1));const n=slice.call(arguments,2);return s=function(){if(!(this instanceof s))return t.apply(i,n.concat(slice.call(arguments)));ctor.prototype=t.prototype;const e=new ctor;ctor.prototype=null;const r=t.apply(e,n.concat(slice.call(arguments)));return Object(r)===r?r:e}}function l(t,i){return i||(i=t,t=0),t+Math.floor(Math.random()*(i-t+1))}function c(t){return a(slice.call(arguments,1),(function(i){if(i)for(const s in i)t[s]=i[s]})),t}function a(t,i,s){if(null==t)return t;if(nativeForEach&&t.forEach===nativeForEach)t.forEach(i,s);else if(t.length===+t.length){for(let n=0,e=t.length;n<e;n++)if(i.call(s,t[n],n,t)===breaker)return null}else{const n=n(t);for(let e=0,r=n.length;e<r;e++)if(i.call(s,t[n[e]],n[e],t)===breaker)return null}return t}function f(t,i){return hasOwnProperty.call(t,i)}class d{constructor(t,i){let s,n,e;if(this.factory=t,this.objects={},null!=i&&null!=i.objects)for(s in e=i.objects,e)n=e[s],this.objects[s]=this.factory.copy(n)}get length(){return Object.keys(this.objects).length}toJSON(){return this.objects}get(t){return this.objects[t]}put(t){return this.objects[t.id]=t}pop(t){let i;const s=null!=(i=t.id)?i:t,n=this.objects[s];return"function"==typeof n.release&&n.release(),delete this.objects[s],n}all(){return this.objects}clear(){return this.objects={}}}class g{constructor(t,i){this.x=t||0,this.y=i||0}get length(){return Math.sqrt(this.x*this.x+this.y*this.y)}get direction(){return Math.atan2(this.y,this.x)}get normalized(){return new g(this.x/this.length,this.y/this.length)}add(t){return new g(this.x+t.x,this.y+t.y)}subtract(t){return new g(this.x-t.x,this.y-t.y)}mult(t){return new g(this.x*t,this.y*t)}divide(t){return new g(this.x/t,this.y/t)}}class w{constructor(t,i){this.source=t,this.target=i}get vector(){return this.target.subtract(this.source)}get length(){return this.vector.length}get direction(){return this.vector.direction}get center(){return this.getPoint(.5)}split(t,i){let s,n,e,r,h,o;const u=i?function(){h=[];for(let i=r=t-1;r<=0?i<=0:i>=0;r<=0?i++:i--)h.push(i);return h}.apply(this):function(){o=[];for(let i=0,s=t-1;0<=s?i<=s:i>=s;0<=s?i++:i--)o.push(i);return o}.apply(this),l=[];for(n=0,e=u.length;n<e;n++)s=u[n],l.push(this.subsegment(s/t,(s+1)/t));return l}getPoint(t){return this.source.add(this.vector.mult(t))}subsegment(t,i){const s=this.vector,n=this.source.add(s.mult(t)),e=this.source.add(s.mult(i));return new w(n,e)}}class p{constructor(t,i,s,n){this.x=t||0,this.y=i||0,this.width=s||0,this.height=n||0}copy(t){return new p(t.x,t.y,t.width,t.height)}toJSON(){return c({},this)}area(){return this.width*this.height}left(t){return null!=t&&(this.x=t),this.x}right(t){return null!=t&&(this.x=t-this.width),this.x+this.width}top(t){return null!=t&&(this.y=t),this.y}bottom(t){return null!=t&&(this.y=t-this.height),this.y+this.height}center(t){return null!=t&&(this.x=t.x-this.width/2,this.y=t.y-this.height/2),new g(this.x+this.width/2,this.y+this.heigh/2)}containsPoint(t){let i,s;return this.left()<=(i=t.x)&&i<=this.right()&&this.top()<=(s=t.y)&&s<=this.bottom()}containsRect(t){return this.left()<=t.left()&&t.right()<=this.right()&&this.top()<=t.top()&&t.bottom()<=this.bottom()}getVertices(){return[new g(this.left(),this.top()),new g(this.right(),this.top()),new g(this.right(),this.bottom()),new g(this.left(),this.bottom())]}getSide(t){const i=this.getVertices();return new w(i[t],i[(t+1)%4])}getSectorId(t){const i=t.subtract(this.center());if(i.y<=0&&Math.abs(i.x)<=Math.abs(i.y))return 0;if(i.x>=0&&Math.abs(i.x)>=Math.abs(i.y))return 1;if(i.y>=0&&Math.abs(i.x)<=Math.abs(i.y))return 2;if(i.x<=0&&Math.abs(i.x)>=Math.abs(i.y))return 3;throw new Error("algorithm error")}getSector(t){return this.getSide(this.getSectorId(t))}}class m{constructor(t){this.intersection=t,this.time=0,this.flipMultiplier=.4*Math.random()-.2+1,this.stateNum=0,this.lightsFlipInterval=20,this.states=[["L","","L",""],["FR","","FR",""],["","L","","L"],["","FR","","FR"]]}get flipInterval(){return this.flipMultiplier*this.lightsFlipInterval}get state(){let t=this.states[this.stateNum%this.states.length];this.intersection.roads.length<=2&&(t=["LFR","LFR","LFR","LFR"]);const i=[];for(let s=0,n=t.length;s<n;s++){const n=t[s];i.push(this.decode(n))}return i}decode(t){const i=[0,0,0],s=[].indexOf||function(t){for(let i=0,s=this.length;i<s;i++)if(i in this&&this[i]===t)return i;return-1};return s.call(t,"L")>=0&&(i[0]=1),s.call(t,"F")>=0&&(i[1]=1),s.call(t,"R")>=0&&(i[2]=1),i}flip(){return this.stateNum+=1}onTick(t){return this.time+=t,this.time>this.flipInterval?(this.flip(),this.time-=this.flipInterval):null}}class v{constructor(t){this.rect=t,this.id=o("intersection"),this.roads=[],this.inRoads=[],this.controlSignals=new m(this)}copy(t){t.rect=p.copy(t.rect);const i=Object.create(v.prototype);return c(i,t),i.roads=[],i.inRoads=[],i.controlSignals=new m(i),i}toJSON(){return{id:this.id,rect:this.rect}}update(){let t,i,s,n,e;const r=this.roads;for(i=0,n=r.length;i<n;i++)t=r[i],t.update();const h=this.inRoads,o=[];for(s=0,e=h.length;s<e;s++)t=h[s],o.push(t.update());return o}}class M{constructor(t,i,s){this.car=t,this.position=s,this.id=o("laneposition"),this.free=!0,this.tmpLane=i}get lane(){return this.tmpLane}set lane(t){this.release(),this.tmpLane=t}get relativePosition(){return this.position/this.lane.length}get nextCarDistance(){let t,i;const s=this.getNext();return s?(i=s.position-s.car.length/2,t=this.position+this.car.length/2,{car:s.car,distance:i-t}):{car:null,distance:1/0}}acquire(){let t;return null!=(null!=(t=this.lane)?t.addCarPosition:void 0)?(this.free=!1,this.lane.addCarPosition(this)):null}release(){let t;return!this.free&&(null!=(t=this.lane)?t.removeCar:void 0)?(this.free=!0,this.lane.removeCar(this)):null}getNext(){return this.lane&&!this.free?this.lane.getNext(this):null}}class b{constructor(t,i,s,n){this.A=t,this.B=i,this.O=s,this.Q=n,this.AB=new w(this.A,this.B),this.AO=new w(this.A,this.O),this.OQ=new w(this.O,this.Q),this.QB=new w(this.Q,this.B),this.len=null}get length(){let t,i,s,n,e;if(null==this.len)for(s=10,n=null,this.len=0,t=e=0;e<=10;t=++e)i=this.getPoint(t/10),n&&(this.len+=i.subtract(n).length),n=i;return this.len}getPoint(t){const i=this.AO.getPoint(t),s=this.OQ.getPoint(t),n=this.QB.getPoint(t),e=new w(i,s).getPoint(t),r=new w(s,n).getPoint(t);return new w(e,r).getPoint(t)}getDirection(t){const i=this.AO.getPoint(t),s=this.OQ.getPoint(t),n=this.QB.getPoint(t),e=new w(i,s).getPoint(t),r=new w(s,n).getPoint(t);return new w(e,r).direction}}class y{constructor(t,i,s){this.car=t,this.current=new M(this.car,i,s||0),this.current.acquire(),this.next=new M(this.car),this.temp=new M(this.car),this.isChangingLanes=!1}get lane(){return this.temp.lane||this.current.lane}get absolutePosition(){return null!=this.temp.lane?this.temp.position:this.current.position}get relativePosition(){return this.absolutePosition/this.lane.length}get direction(){return this.lane.getDirection(this.relativePosition)}get coords(){return this.lane.getPoint(this.relativePosition)}get nextCarDistance(){const t=this.current.nextCarDistance,i=this.next.nextCarDistance;return t.distance<i.distance?t:i}get distanceToStopLine(){return this.canEnterIntersection()?1/0:this.getDistanceToIntersection()}get nextIntersection(){return this.current.lane.road.target}get previousIntersection(){return this.current.lane.road.source}isValidTurn(){const t=this.car.nextLane,i=this.current.lane,s=i.getTurnDirection(t);if(3===s)throw Error("no U-turns are allowed");if(0===s&&!i.isLeftmost)throw Error("no left turns from this lane");if(2===s&&!i.isRightmost)throw Error("no right turns from this lane");return!0}canEnterIntersection(){const t=this.car.nextLane,i=this.current.lane;if(!t)return!0;const s=this.nextIntersection,n=i.getTurnDirection(t),e=i.road.targetSideId;return s.controlSignals.state[e][n]}getDistanceToIntersection(){const t=this.current.lane.length-this.car.length/2-this.current.position;return this.isChangingLanes?1/0:Math.max(t,0)}timeToMakeTurn(t){return null==t&&(t=0),this.getDistanceToIntersection()<=t}moveForward(t){let i,s;t=Math.max(t,0),this.current.position+=t,this.next.position+=t,this.temp.position+=t,this.timeToMakeTurn()&&this.canEnterIntersection()&&this.isValidTurn()&&this.i(this.car.popNextLane(),0);const n=this.temp.position/(null!=(i=this.temp.lane)?i.length:void 0),e=2*this.car.length;return this.isChangingLanes&&this.temp.position>e&&!this.current.free&&this.current.release(),this.isChangingLanes&&this.next.free&&this.temp.position+e>(null!=(s=this.temp.lane)?s.length:void 0)&&this.next.acquire(),this.isChangingLanes&&n>=1&&this.s(),!this.current.lane||this.isChangingLanes||this.car.nextLane?null:this.car.pickNextLane()}changeLane(t){if(this.isChangingLanes)throw Error("already changing lane");if(null==t)throw Error("no next lane");if(t===this.lane)throw Error("next lane == current lane");if(this.lane.road!==t.road)throw Error("not neighbouring lanes");const i=this.current.position+3*this.car.length;return this.i(t,i)}h(){const t=this.current.lane.getPoint(this.current.relativePosition),i=this.next.lane.getPoint(this.next.relativePosition),s=i.subtract(t).length,n=this.current.lane.middleLine.vector.normalized.mult(.3*s),e=t.add(n),r=this.next.lane.middleLine.vector.normalized.mult(.3*s),h=i.subtract(r);return new b(t,i,e,h)}o(){return this.h()}i(t,i){if(this.isChangingLanes)throw Error("already changing lane");if(null==t)return 0;this.isChangingLanes=!0,this.next.lane=t,this.next.position=i;const s=this.o();return this.temp.lane=s,this.temp.position=0,this.next.position-=this.temp.lane.length}s(){if(!this.isChangingLanes)throw Error("no lane changing is going on");return this.isChangingLanes=!1,this.current.lane=this.next.lane,this.current.position=this.next.position||0,this.current.acquire(),this.next.lane=null,this.next.position=NaN,this.temp.lane=null,this.temp.position=NaN,this.current.lane}release(){let t,i,s;return null!=(t=this.current)&&t.release(),null!=(i=this.next)&&i.release(),null!=(s=this.temp)?s.release():void 0}}const C=[];class L{constructor(t,i){this.type=l(C.length-1),this.id=o("car"),this.color=(300+240*Math.random()|0)%360,this.tmpSpeed=0,this.width=2,this.length=2,this.maxSpeed=30,this.s0=2,this.timeHeadway=1.5,this.maxAcceleration=1,this.maxDeceleration=3,this.trajectory=new y(this,t,i),this.alive=!0,this.preferedLane=null}get coords(){return this.trajectory.coords}get speed(){return this.tmpSpeed}set speed(t){t<0&&(t=0),t>this.maxSpeed&&(t=this.maxSpeed),this.tmpSpeed=t}get direction(){return this.trajectory.direction}release(){return this.trajectory.release()}getAcceleration(){let t;const i=this.trajectory.nextCarDistance,s=Math.max(i.distance,0),n=this.maxAcceleration,e=this.maxDeceleration,r=this.speed-(null!=(t=i.car)?t.speed:void 0)||0,h=Math.pow(this.speed/this.maxSpeed,4),o=this.s0,u=this.speed*this.timeHeadway,l=o+u+this.speed*r/(2*Math.sqrt(n*e)),c=Math.pow(l/s,2),a=1+u+Math.pow(this.speed,2)/(2*e),f=1-h-c-Math.pow(a/this.trajectory.distanceToStopLine,2);return this.maxAcceleration*f}move(t){const i=this.getAcceleration();if(this.speed+=i*t,!this.trajectory.isChangingLanes&&this.nextLane){const t=this.trajectory.current.lane,i=t.getTurnDirection(this.nextLane),s=function(){switch(i){case 0:return t.leftmostAdjacent;case 2:return t.rightmostAdjacent;default:return t}}();s!==t&&this.trajectory.changeLane(s)}const s=this.speed*t+.5*i*Math.pow(t,2);return this.trajectory.nextCarDistance.distance<s&&console.log("bad IDM"),this.trajectory.timeToMakeTurn(s)&&null==this.nextLane?(this.alive=!1,this.alive):this.trajectory.moveForward(s)}pickNextRoad(){const t=this.trajectory.nextIntersection,i=this.trajectory.current.lane,s=t.roads.filter((function(t){return t.target!==i.road.source}));if(0===s.length)return null;return h(s)}pickNextLane(){if(this.nextLane)throw Error("next lane is already chosen");this.nextLane=null;const t=this.pickNextRoad();if(!t)return null;const i=this.trajectory.current.lane.road.getTurnDirection(t),s=function(){switch(i){case 0:return t.lanesNumber-1;case 1:return l(0,t.lanesNumber-1);case 2:return 0}return null}();return this.nextLane=t.lanes[s],this.nextLane}popNextLane(){const t=this.nextLane;return this.nextLane=null,this.preferedLane=null,t}}class E{constructor(t,i,s){this.sourceSegment=t,this.targetSegment=i,this.road=s,this.leftAdjacent=null,this.rightAdjacent=null,this.leftmostAdjacent=null,this.rightmostAdjacent=null,this.carsPositions={},this.update()}get sourceSideId(){return this.road.sourceSideId}get targetSideId(){return this.road.targetSideId}get isRightmost(){return this===this.rightmostAdjacent}get isLeftmost(){return this===this.leftmostAdjacent}get leftBorder(){return new w(this.sourceSegment.source,this.targetSegment.target)}get rightBorder(){return new w(this.sourceSegment.target,this.targetSegment.source)}toJSON(){const t=c({},this);return delete t.carsPositions,t}update(){return this.middleLine=new w(this.sourceSegment.center,this.targetSegment.center),this.length=this.middleLine.length,this.direction=this.middleLine.direction}getTurnDirection(t){return t?this.road.getTurnDirection(t.road):1}getDirection(){return this.direction}getPoint(t){return this.middleLine.getPoint(t)}addCarPosition(t){if(t.id in this.carsPositions)throw Error("car is already here");return this.carsPositions[t.id]=t}removeCar(t){if(!(t.id in this.carsPositions))throw Error("removing unknown car");return delete this.carsPositions[t.id]}getNext(t){if(t.lane!==this)throw Error("car is on other lane");let i=null,s=1/0;const n=this.carsPositions;for(const e in n){const r=n[e],h=r.position-t.position;!r.free&&0<h&&h<s&&(s=h,i=r)}return i}}class R{constructor(t,i,s){this.source=t,this.target=i,this.id=o("road"),this.lanes=[],this.gridSize=s||32,this.lanesNumber=null,this.update()}get length(){return this.targetSide.target.subtract(this.sourceSide.source).length}get leftmostLane(){return this.lanes[this.lanesNumber-1]}get rightmostLane(){return this.lanes[0]}copy(t){const i=Object.create(R.prototype);return c.extend(i,t),null==i.lanes&&(i.lanes=[]),i}toJSON(){return{id:this.id,source:this.source.id,target:this.target.id}}getTurnDirection(t){if(this.target!==t.source)throw Error("invalid roads");const i=this.targetSideId;return(t.sourceSideId-i-1+8)%4}update(){let t,i,s,n,e,r;if(!this.source||!this.target)throw Error("incomplete road");this.sourceSideId=this.source.rect.getSectorId(this.target.rect.center()),this.sourceSide=this.source.rect.getSide(this.sourceSideId).subsegment(.5,1),this.targetSideId=this.target.rect.getSectorId(this.source.rect.center()),this.targetSide=this.target.rect.getSide(this.targetSideId).subsegment(0,.5),this.lanesNumber=0|Math.min(this.sourceSide.length,this.targetSide.length),this.lanesNumber=Math.max(2,this.lanesNumber/this.gridSize|0);const h=this.sourceSide.split(this.lanesNumber,!0),o=this.targetSide.split(this.lanesNumber);if(null==this.lanes||this.lanes.length<this.lanesNumber)for(null==this.lanes&&(this.lanes=[]),t=s=0,e=this.lanesNumber-1;0<=e?s<=e:s>=e;t=0<=e?++s:--s)null==(i=this.lanes)[t]&&(i[t]=new E(h[t],o[t],this));const u=[];for(t=n=0,r=this.lanesNumber-1;0<=r?n<=r:n>=r;t=0<=r?++n:--n)this.lanes[t].sourceSegment=h[t],this.lanes[t].targetSegment=o[t],this.lanes[t].leftAdjacent=this.lanes[t+1],this.lanes[t].rightAdjacent=this.lanes[t-1],this.lanes[t].leftmostAdjacent=this.lanes[this.lanesNumber-1],this.lanes[t].rightmostAdjacent=this.lanes[0],u.push(this.lanes[t].update());return u}}class x{constructor(t){this.toRemove=[],this.options=t||{},this.carsNumber=this.options.carsNumber||10,this.gridSize=this.options.gridSize||32,this.u=0,this.l=0,this.g=5,this.carsList={},this.p=new n.GLTFLayer("traffic",{gltfCoordinateSystem:"gltf"}),this.m="stop",this.v=[],this.M={},this.set()}run(){this.m="running",this.C()}stop(){this.m="stop"}remove(){this.L&&cancelAnimationFrame(this.L),this.p.remove(),delete this.map}setSymbols(t){this.v=t;for(let t=0;t<this.v.length;t++){const i=this.v[t];this.M[i.url]=new n.MultiGLTFMarker([],{symbol:i}).addTo(this.p)}}C(){if("running"!==this.m)return;const t=Date.now();this.l=t;const i=Date.now();let s,n=i-this.u||0;n>100&&(n=100),this.u=i,this.onTick(this.g*n/1e3);let e=this.toRemove.length;for(;e--;)this.R(this.toRemove[e]);this.clearTmpRemove();const r=this.cars.all();for(s in r)this.N(r[s],s);this.L=window.requestAnimationFrame(this.C.bind(this))}I(){for(const t in this.M)this.M[t].removeData();for(const t in this.carsList){const i=this.carsList[t],s=i.url;this.M[s].addData(i)}}N(t){const i=t.id.substring(3);if(this.carsList[i]){if(!t)return;const s=t.coords,e=t.direction,r=this.map,h=r.pointAtResToCoordinate(new n.Point(s.x/this.gridSize,s.y/this.gridSize),r.getGLRes()),o=e/Math.PI*180+90;this.carsList[i].coordinates=h,this.carsList[i].rotation=[0,0,o];const u=this.S(i),l=this.carsList[i].url;u>-1?this.M[l].updateData(u,this.carsList[i]):this.M[l].addData(this.carsList[i])}else{const t=this.v[Math.floor(Math.random()*this.v.length)];this.carsList[i]={coordinates:null,direction:null,url:t.url},this.showHideCar(this.carsList[i],"show")}}showHideCar(t,i,s){const e=this;n.animation.Animation.animate({"symbol":{transparent:1}},{duration:1e3,easing:"out"},(function(n){if("running"===n.state.playState){let r=0;"show"===i?(r=n.styles.symbol.transparent,t.color=[1,1,1,r]):"hide"===i&&(r=1-n.styles.symbol.transparent,t.color=[1,1,1,r],r<.01&&setTimeout((function(){const t=e.S(s);if(!e.carsList[s])return;const i=e.carsList[s].url;t>-1&&e.M[i].removeData(t),delete e.carsList[s]}),100))}})).play()}S(t){const i=this.carsList[t];if(!i)return-1;const s=i.url;return this.M[s].getAllData().indexOf(this.carsList[t])}R(t){const i=t.substring(3);null!=this.carsList[i]&&this.showHideCar(this.carsList[i],"hide",i)}get instantSpeed(){const t=function(t,i,s){const n=[];return null==t?n:nativeMap&&t.map===nativeMap?t.map(i,s):(a(t,(t,e,r)=>{n.push(i.call(s,t,e,r))}),n)}(this.cars.all(),t=>t.speed);return 0===t.length?0:function(t,i,s,n){let e=arguments.length>2;return null==t&&(t=[]),nativeReduce&&t.reduce===nativeReduce?(n&&(i=u(i,n)),e?t.reduce(i,s):t.reduce(i)):(a(t,(t,r,h)=>{e?s=i.call(n,s,t,r,h):(s=t,e=!0)}),s)}(t,(function(t,i){return t+i}))/t.length}get map(){const t=this.T;return t?t.getMap():null}addTo(t){this.T=t,this.p.addTo(t)}set(t){return null==t&&(t={}),this.intersections=new d(v,t.intersections),this.roads=new d(R,t.roads),this.cars=new d(L,t.cars),this.carsNumber=0}save(){const t=c({},this);return delete t.cars,window.localStorage.world=JSON.stringify(t)}setCarNumber(t){this.carsNumber=t}getCarNumber(){return this.carsNumber}load(){let t,i,s,n;if(t=window.localStorage.world,t=t&&JSON.parse(t),null==t)return null;this.clear(),this.carsNumber=t.carsNumber||0;const e=t.intersections;for(i in e)s=e[i],this.addIntersection(v.copy(s));const r=t.roads,h=[];for(i in r)n=r[i],n=(new R).copy(n),n.source=this.getIntersection(n.source),n.target=this.getIntersection(n.target),h.push(this.addRoad(n));return h}intersectSegment(t,i){for(let s=0;s<i.length-1;s++){const n=[i[s],i[s+1]],r=e.lineString(n),h=e.lineIntersect(t,r);if(h.features.length)return{intersectIndex:s,coord:h.features[0].geometry.coordinates}}return null}intersection(t,i,s,n,r,h){const o=e.lineString(t);for(let t=i+1;t<n.length;t++){const e=n[t],u=this.intersectSegment(o,e);if(!u)continue;const l={};l[i]={pre:s},l[t]={pre:u.intersectIndex+h[t]};const c={inLines:l,coordinate:this.map.coordinateToPointAtRes({x:u.coord[0],y:u.coord[1]},this.map.getGLRes())};r.push(c)}}generateTraffic(t){if(!this.map)return;const i={};let s=0;for(let n=0;n<t.length;n++)i[n]=s,s+=t[n].length;const n=[];let e=0;for(let s=0;s<t.length;s++){const r=t[s];for(let h=0;h<r.length-1;h++){const o=[r[h],r[h+1]];this.intersection(o,s,e+h,t,n,i)}e+=r.length}const r=[];let h=0;const o=this.map;for(let i=0;i<t.length;i++){const s=t[i];for(let t=0;t<s.length;t++){const n=o.coordinateToPointAtRes({x:s[t][0],y:s[t][1]},o.getGLRes()),e={};0===t?e[i]={pre:null}:(s.length,e[i]={pre:t-1+h});const u={inLines:e,coordinate:n};r.push(u)}h+=s.length}for(let t=0;t<r.length;t++){const i=r[t];this.comparePrePoint(i,t,n)}const u=this.gridSize,l=[];for(let t=0;t<r.length;t++){const i=r[t],s=i.coordinate.x,n=i.coordinate.y,e=new p(s*u-.5,n*u-.5,1,1),h=new v(e);h.connectRoads=i.roads,l.push(h),this.addIntersection(h)}const c=[];for(let t=0;t<n.length;t++){const i=n[t],s=i.coordinate.x,e=i.coordinate.y,r=new p(s*u-.5,e*u-.5,1,1),h=new v(r);h.connectRoads=i.roads,c.push(h),this.addIntersection(h)}for(let t=0;t<l.length;t++){const i=l[t],s=i.connectRoads;if(s)for(let t=0;t<s.length;t++){const n=s[t];if(null!=n.pre){let t=null;const s=n.type;"line"===s?t=l[n.pre]:"line-interact"===s&&(t=c[n.pre]),this.addRoad(new R(i,t)),this.addRoad(new R(t,i))}}}for(let t=0;t<c.length;t++){const i=c[t],s=i.connectRoads;if(s)for(let t=0;t<s.length;t++){const n=s[t];if(null!=n.pre){let t=null;const s=n.type;"line"===s?t=l[n.pre]:"line-interact"===s&&(t=c[n.pre]),this.addRoad(new R(i,t)),this.addRoad(new R(t,i))}}}}comparePrePoint(t,i,s){const n=this.getPre(t);if(n){const{pre:e,lineIndex:r}=n;for(let n=0;n<s.length;n++){const h=s[n];h.inLines[r]&&h.inLines[r].pre===e&&(t.roads=[{pre:n,type:"line-interact"}],h.roads?h.roads.push({pre:i-1,type:"line"}):h.roads=[{pre:i-1,type:"line"}])}t.roads||(t.roads=[{pre:i-1,type:"line"}])}}getPre(t){for(const i in t.inLines)if(null!==t.inLines[i].pre)return{pre:t.inLines[i].pre,lineIndex:i};return null}clear(){return this.set({})}onTick(t){let i,s,n;if(t>1)throw Error("delta > 1");this.refreshCars();const e=this.intersections.all();for(s in e)n=e[s],n.controlSignals.onTick(t);const r=this.cars.all(),h=[];for(s in r)i=r[s],i.move(t),i.alive?h.push(void 0):h.push(this.removeCar(i));return h}refreshCars(){return this.cars.length<this.carsNumber&&this.addRandomCar(),this.cars.length>this.carsNumber?this.removeRandomCar():null}addRoad(t){return this.roads.put(t),t.source.roads.push(t),t.target.inRoads.push(t),t.update()}getRoad(t){return this.roads.get(t)}addCar(t){return this.cars.put(t)}getCar(t){return this.cars.get(t)}removeCar(t){return this.toRemove.push(t.id),this.cars.pop(t)}clearTmpRemove(){this.toRemove=[]}addIntersection(t){return this.intersections.put(t)}getIntersection(t){return this.intersections.get(t)}addRandomCar(){let t;const i=h(this.roads.all());return null!=i&&(t=h(i.lanes),null!=t)?this.addCar(new L(t)):null}removeRandomCar(){const t=h(this.cars.all());return null!=t?this.removeCar(t):null}}"undefined"!=typeof window&&window.maptalks&&(window.maptalks.TrafficScene=x),"undefined"!=typeof console&&console.log("@maptalks/traffic v0.87.0")}));
|
|
6
|
+
!function(t,i){"object"==typeof exports&&"undefined"!=typeof module?i(exports,require("maptalks"),require("@maptalks/gl-layers"),require("turf")):"function"==typeof define&&define.amd?define(["exports","maptalks","@maptalks/gl-layers","turf"],i):i((t="undefined"!=typeof globalThis?globalThis:t||self).maptalks=t.maptalks||{},t.maptalks,t.maptalks,t.turf)}(this,(function(t,i,s,n){"use strict";function e(t){if(t&&t.t)return t;var i=Object.create(null);return t&&Object.keys(t).forEach((function(s){if("default"!==s){var n=Object.getOwnPropertyDescriptor(t,s);Object.defineProperty(i,s,n.get?n:{enumerable:!0,get:function(){return t[s]}})}})),i.default=t,Object.freeze(i)}var r=e(i),h=e(n);let o=0;function u(t,i,s){return null==i||s?(t.length!==+t.length&&(t=function(t){const i=function(t){if(!function(t){return t===Object(t)}(t))return[];const i=[];for(const s in t)g(t,s)&&i.push(s);return i}(t),s=i.length,n=new Array(s);for(let e=0;e<s;e++)n[e]=t[i[e]];return n}(t)),t[a(t.length-1)]):function(t){let i,s=0;const n=[];return d(t,t=>{i=i(s++),n[s-1]=n[i],n[i]=t}),n}(t).slice(0,Math.max(0,i))}function l(t){const i=++o+"";return t?t+i:i}function c(t,i){let s;if(nativeBind&&t.bind===nativeBind)return nativeBind.apply(t,slice.call(arguments,1));const n=slice.call(arguments,2);return s=function(){if(!(this instanceof s))return t.apply(i,n.concat(slice.call(arguments)));ctor.prototype=t.prototype;const e=new ctor;ctor.prototype=null;const r=t.apply(e,n.concat(slice.call(arguments)));return Object(r)===r?r:e}}function a(t,i){return i||(i=t,t=0),t+Math.floor(Math.random()*(i-t+1))}function f(t){return d(slice.call(arguments,1),(function(i){if(i)for(const s in i)t[s]=i[s]})),t}function d(t,i,s){if(null==t)return t;if(nativeForEach&&t.forEach===nativeForEach)t.forEach(i,s);else if(t.length===+t.length){for(let n=0,e=t.length;n<e;n++)if(i.call(s,t[n],n,t)===breaker)return null}else{const n=n(t);for(let e=0,r=n.length;e<r;e++)if(i.call(s,t[n[e]],n[e],t)===breaker)return null}return t}function g(t,i){return hasOwnProperty.call(t,i)}class w{constructor(t,i){let s,n,e;if(this.factory=t,this.objects={},null!=i&&null!=i.objects)for(s in e=i.objects,e)n=e[s],this.objects[s]=this.factory.copy(n)}get length(){return Object.keys(this.objects).length}toJSON(){return this.objects}get(t){return this.objects[t]}put(t){return this.objects[t.id]=t}pop(t){let i;const s=null!=(i=t.id)?i:t,n=this.objects[s];return"function"==typeof n.release&&n.release(),delete this.objects[s],n}all(){return this.objects}clear(){return this.objects={}}}class p{constructor(t,i){this.x=t||0,this.y=i||0}get length(){return Math.sqrt(this.x*this.x+this.y*this.y)}get direction(){return Math.atan2(this.y,this.x)}get normalized(){return new p(this.x/this.length,this.y/this.length)}add(t){return new p(this.x+t.x,this.y+t.y)}subtract(t){return new p(this.x-t.x,this.y-t.y)}mult(t){return new p(this.x*t,this.y*t)}divide(t){return new p(this.x/t,this.y/t)}}class m{constructor(t,i){this.source=t,this.target=i}get vector(){return this.target.subtract(this.source)}get length(){return this.vector.length}get direction(){return this.vector.direction}get center(){return this.getPoint(.5)}split(t,i){let s,n,e,r,h,o;const u=i?function(){h=[];for(let i=r=t-1;r<=0?i<=0:i>=0;r<=0?i++:i--)h.push(i);return h}.apply(this):function(){o=[];for(let i=0,s=t-1;0<=s?i<=s:i>=s;0<=s?i++:i--)o.push(i);return o}.apply(this),l=[];for(n=0,e=u.length;n<e;n++)s=u[n],l.push(this.subsegment(s/t,(s+1)/t));return l}getPoint(t){return this.source.add(this.vector.mult(t))}subsegment(t,i){const s=this.vector,n=this.source.add(s.mult(t)),e=this.source.add(s.mult(i));return new m(n,e)}}class v{constructor(t,i,s,n){this.x=t||0,this.y=i||0,this.width=s||0,this.height=n||0}copy(t){return new v(t.x,t.y,t.width,t.height)}toJSON(){return f({},this)}area(){return this.width*this.height}left(t){return null!=t&&(this.x=t),this.x}right(t){return null!=t&&(this.x=t-this.width),this.x+this.width}top(t){return null!=t&&(this.y=t),this.y}bottom(t){return null!=t&&(this.y=t-this.height),this.y+this.height}center(t){return null!=t&&(this.x=t.x-this.width/2,this.y=t.y-this.height/2),new p(this.x+this.width/2,this.y+this.heigh/2)}containsPoint(t){let i,s;return this.left()<=(i=t.x)&&i<=this.right()&&this.top()<=(s=t.y)&&s<=this.bottom()}containsRect(t){return this.left()<=t.left()&&t.right()<=this.right()&&this.top()<=t.top()&&t.bottom()<=this.bottom()}getVertices(){return[new p(this.left(),this.top()),new p(this.right(),this.top()),new p(this.right(),this.bottom()),new p(this.left(),this.bottom())]}getSide(t){const i=this.getVertices();return new m(i[t],i[(t+1)%4])}getSectorId(t){const i=t.subtract(this.center());if(i.y<=0&&Math.abs(i.x)<=Math.abs(i.y))return 0;if(i.x>=0&&Math.abs(i.x)>=Math.abs(i.y))return 1;if(i.y>=0&&Math.abs(i.x)<=Math.abs(i.y))return 2;if(i.x<=0&&Math.abs(i.x)>=Math.abs(i.y))return 3;throw new Error("algorithm error")}getSector(t){return this.getSide(this.getSectorId(t))}}class M{constructor(t){this.intersection=t,this.time=0,this.flipMultiplier=.4*Math.random()-.2+1,this.stateNum=0,this.lightsFlipInterval=20,this.states=[["L","","L",""],["FR","","FR",""],["","L","","L"],["","FR","","FR"]]}get flipInterval(){return this.flipMultiplier*this.lightsFlipInterval}get state(){let t=this.states[this.stateNum%this.states.length];this.intersection.roads.length<=2&&(t=["LFR","LFR","LFR","LFR"]);const i=[];for(let s=0,n=t.length;s<n;s++){const n=t[s];i.push(this.decode(n))}return i}decode(t){const i=[0,0,0],s=[].indexOf||function(t){for(let i=0,s=this.length;i<s;i++)if(i in this&&this[i]===t)return i;return-1};return s.call(t,"L")>=0&&(i[0]=1),s.call(t,"F")>=0&&(i[1]=1),s.call(t,"R")>=0&&(i[2]=1),i}flip(){return this.stateNum+=1}onTick(t){return this.time+=t,this.time>this.flipInterval?(this.flip(),this.time-=this.flipInterval):null}}class b{constructor(t){this.rect=t,this.id=l("intersection"),this.roads=[],this.inRoads=[],this.controlSignals=new M(this)}copy(t){t.rect=v.copy(t.rect);const i=Object.create(b.prototype);return f(i,t),i.roads=[],i.inRoads=[],i.controlSignals=new M(i),i}toJSON(){return{id:this.id,rect:this.rect}}update(){let t,i,s,n,e;const r=this.roads;for(i=0,n=r.length;i<n;i++)t=r[i],t.update();const h=this.inRoads,o=[];for(s=0,e=h.length;s<e;s++)t=h[s],o.push(t.update());return o}}class y{constructor(t,i,s){this.car=t,this.position=s,this.id=l("laneposition"),this.free=!0,this.tmpLane=i}get lane(){return this.tmpLane}set lane(t){this.release(),this.tmpLane=t}get relativePosition(){return this.position/this.lane.length}get nextCarDistance(){let t,i;const s=this.getNext();return s?(i=s.position-s.car.length/2,t=this.position+this.car.length/2,{car:s.car,distance:i-t}):{car:null,distance:1/0}}acquire(){let t;return null!=(null!=(t=this.lane)?t.addCarPosition:void 0)?(this.free=!1,this.lane.addCarPosition(this)):null}release(){let t;return!this.free&&(null!=(t=this.lane)?t.removeCar:void 0)?(this.free=!0,this.lane.removeCar(this)):null}getNext(){return this.lane&&!this.free?this.lane.getNext(this):null}}class L{constructor(t,i,s,n){this.A=t,this.B=i,this.O=s,this.Q=n,this.AB=new m(this.A,this.B),this.AO=new m(this.A,this.O),this.OQ=new m(this.O,this.Q),this.QB=new m(this.Q,this.B),this.len=null}get length(){let t,i,s,n,e;if(null==this.len)for(s=10,n=null,this.len=0,t=e=0;e<=10;t=++e)i=this.getPoint(t/10),n&&(this.len+=i.subtract(n).length),n=i;return this.len}getPoint(t){const i=this.AO.getPoint(t),s=this.OQ.getPoint(t),n=this.QB.getPoint(t),e=new m(i,s).getPoint(t),r=new m(s,n).getPoint(t);return new m(e,r).getPoint(t)}getDirection(t){const i=this.AO.getPoint(t),s=this.OQ.getPoint(t),n=this.QB.getPoint(t),e=new m(i,s).getPoint(t),r=new m(s,n).getPoint(t);return new m(e,r).direction}}class x{constructor(t,i,s){this.car=t,this.current=new y(this.car,i,s||0),this.current.acquire(),this.next=new y(this.car),this.temp=new y(this.car),this.isChangingLanes=!1}get lane(){return this.temp.lane||this.current.lane}get absolutePosition(){return null!=this.temp.lane?this.temp.position:this.current.position}get relativePosition(){return this.absolutePosition/this.lane.length}get direction(){return this.lane.getDirection(this.relativePosition)}get coords(){return this.lane.getPoint(this.relativePosition)}get nextCarDistance(){const t=this.current.nextCarDistance,i=this.next.nextCarDistance;return t.distance<i.distance?t:i}get distanceToStopLine(){return this.canEnterIntersection()?1/0:this.getDistanceToIntersection()}get nextIntersection(){return this.current.lane.road.target}get previousIntersection(){return this.current.lane.road.source}isValidTurn(){const t=this.car.nextLane,i=this.current.lane,s=i.getTurnDirection(t);if(3===s)throw Error("no U-turns are allowed");if(0===s&&!i.isLeftmost)throw Error("no left turns from this lane");if(2===s&&!i.isRightmost)throw Error("no right turns from this lane");return!0}canEnterIntersection(){const t=this.car.nextLane,i=this.current.lane;if(!t)return!0;const s=this.nextIntersection,n=i.getTurnDirection(t),e=i.road.targetSideId;return s.controlSignals.state[e][n]}getDistanceToIntersection(){const t=this.current.lane.length-this.car.length/2-this.current.position;return this.isChangingLanes?1/0:Math.max(t,0)}timeToMakeTurn(t){return null==t&&(t=0),this.getDistanceToIntersection()<=t}moveForward(t){let i,s;t=Math.max(t,0),this.current.position+=t,this.next.position+=t,this.temp.position+=t,this.timeToMakeTurn()&&this.canEnterIntersection()&&this.isValidTurn()&&this.i(this.car.popNextLane(),0);const n=this.temp.position/(null!=(i=this.temp.lane)?i.length:void 0),e=2*this.car.length;return this.isChangingLanes&&this.temp.position>e&&!this.current.free&&this.current.release(),this.isChangingLanes&&this.next.free&&this.temp.position+e>(null!=(s=this.temp.lane)?s.length:void 0)&&this.next.acquire(),this.isChangingLanes&&n>=1&&this.s(),!this.current.lane||this.isChangingLanes||this.car.nextLane?null:this.car.pickNextLane()}changeLane(t){if(this.isChangingLanes)throw Error("already changing lane");if(null==t)throw Error("no next lane");if(t===this.lane)throw Error("next lane == current lane");if(this.lane.road!==t.road)throw Error("not neighbouring lanes");const i=this.current.position+3*this.car.length;return this.i(t,i)}h(){const t=this.current.lane.getPoint(this.current.relativePosition),i=this.next.lane.getPoint(this.next.relativePosition),s=i.subtract(t).length,n=this.current.lane.middleLine.vector.normalized.mult(.3*s),e=t.add(n),r=this.next.lane.middleLine.vector.normalized.mult(.3*s),h=i.subtract(r);return new L(t,i,e,h)}o(){return this.h()}i(t,i){if(this.isChangingLanes)throw Error("already changing lane");if(null==t)return 0;this.isChangingLanes=!0,this.next.lane=t,this.next.position=i;const s=this.o();return this.temp.lane=s,this.temp.position=0,this.next.position-=this.temp.lane.length}s(){if(!this.isChangingLanes)throw Error("no lane changing is going on");return this.isChangingLanes=!1,this.current.lane=this.next.lane,this.current.position=this.next.position||0,this.current.acquire(),this.next.lane=null,this.next.position=NaN,this.temp.lane=null,this.temp.position=NaN,this.current.lane}release(){let t,i,s;return null!=(t=this.current)&&t.release(),null!=(i=this.next)&&i.release(),null!=(s=this.temp)?s.release():void 0}}const C=[];class E{constructor(t,i){this.type=a(C.length-1),this.id=l("car"),this.color=(300+240*Math.random()|0)%360,this.tmpSpeed=0,this.width=2,this.length=2,this.maxSpeed=30,this.s0=2,this.timeHeadway=1.5,this.maxAcceleration=1,this.maxDeceleration=3,this.trajectory=new x(this,t,i),this.alive=!0,this.preferedLane=null}get coords(){return this.trajectory.coords}get speed(){return this.tmpSpeed}set speed(t){t<0&&(t=0),t>this.maxSpeed&&(t=this.maxSpeed),this.tmpSpeed=t}get direction(){return this.trajectory.direction}release(){return this.trajectory.release()}getAcceleration(){let t;const i=this.trajectory.nextCarDistance,s=Math.max(i.distance,0),n=this.maxAcceleration,e=this.maxDeceleration,r=this.speed-(null!=(t=i.car)?t.speed:void 0)||0,h=Math.pow(this.speed/this.maxSpeed,4),o=this.s0,u=this.speed*this.timeHeadway,l=o+u+this.speed*r/(2*Math.sqrt(n*e)),c=Math.pow(l/s,2),a=1+u+Math.pow(this.speed,2)/(2*e),f=1-h-c-Math.pow(a/this.trajectory.distanceToStopLine,2);return this.maxAcceleration*f}move(t){const i=this.getAcceleration();if(this.speed+=i*t,!this.trajectory.isChangingLanes&&this.nextLane){const t=this.trajectory.current.lane,i=t.getTurnDirection(this.nextLane),s=function(){switch(i){case 0:return t.leftmostAdjacent;case 2:return t.rightmostAdjacent;default:return t}}();s!==t&&this.trajectory.changeLane(s)}const s=this.speed*t+.5*i*Math.pow(t,2);return this.trajectory.nextCarDistance.distance<s&&console.log("bad IDM"),this.trajectory.timeToMakeTurn(s)&&null==this.nextLane?(this.alive=!1,this.alive):this.trajectory.moveForward(s)}pickNextRoad(){const t=this.trajectory.nextIntersection,i=this.trajectory.current.lane,s=t.roads.filter((function(t){return t.target!==i.road.source}));if(0===s.length)return null;return u(s)}pickNextLane(){if(this.nextLane)throw Error("next lane is already chosen");this.nextLane=null;const t=this.pickNextRoad();if(!t)return null;const i=this.trajectory.current.lane.road.getTurnDirection(t),s=function(){switch(i){case 0:return t.lanesNumber-1;case 1:return a(0,t.lanesNumber-1);case 2:return 0}return null}();return this.nextLane=t.lanes[s],this.nextLane}popNextLane(){const t=this.nextLane;return this.nextLane=null,this.preferedLane=null,t}}class O{constructor(t,i,s){this.sourceSegment=t,this.targetSegment=i,this.road=s,this.leftAdjacent=null,this.rightAdjacent=null,this.leftmostAdjacent=null,this.rightmostAdjacent=null,this.carsPositions={},this.update()}get sourceSideId(){return this.road.sourceSideId}get targetSideId(){return this.road.targetSideId}get isRightmost(){return this===this.rightmostAdjacent}get isLeftmost(){return this===this.leftmostAdjacent}get leftBorder(){return new m(this.sourceSegment.source,this.targetSegment.target)}get rightBorder(){return new m(this.sourceSegment.target,this.targetSegment.source)}toJSON(){const t=f({},this);return delete t.carsPositions,t}update(){return this.middleLine=new m(this.sourceSegment.center,this.targetSegment.center),this.length=this.middleLine.length,this.direction=this.middleLine.direction}getTurnDirection(t){return t?this.road.getTurnDirection(t.road):1}getDirection(){return this.direction}getPoint(t){return this.middleLine.getPoint(t)}addCarPosition(t){if(t.id in this.carsPositions)throw Error("car is already here");return this.carsPositions[t.id]=t}removeCar(t){if(!(t.id in this.carsPositions))throw Error("removing unknown car");return delete this.carsPositions[t.id]}getNext(t){if(t.lane!==this)throw Error("car is on other lane");let i=null,s=1/0;const n=this.carsPositions;for(const e in n){const r=n[e],h=r.position-t.position;!r.free&&0<h&&h<s&&(s=h,i=r)}return i}}class R{constructor(t,i,s){this.source=t,this.target=i,this.id=l("road"),this.lanes=[],this.gridSize=s||32,this.lanesNumber=null,this.update()}get length(){return this.targetSide.target.subtract(this.sourceSide.source).length}get leftmostLane(){return this.lanes[this.lanesNumber-1]}get rightmostLane(){return this.lanes[0]}copy(t){const i=Object.create(R.prototype);return f.extend(i,t),null==i.lanes&&(i.lanes=[]),i}toJSON(){return{id:this.id,source:this.source.id,target:this.target.id}}getTurnDirection(t){if(this.target!==t.source)throw Error("invalid roads");const i=this.targetSideId;return(t.sourceSideId-i-1+8)%4}update(){let t,i,s,n,e,r;if(!this.source||!this.target)throw Error("incomplete road");this.sourceSideId=this.source.rect.getSectorId(this.target.rect.center()),this.sourceSide=this.source.rect.getSide(this.sourceSideId).subsegment(.5,1),this.targetSideId=this.target.rect.getSectorId(this.source.rect.center()),this.targetSide=this.target.rect.getSide(this.targetSideId).subsegment(0,.5),this.lanesNumber=0|Math.min(this.sourceSide.length,this.targetSide.length),this.lanesNumber=Math.max(2,this.lanesNumber/this.gridSize|0);const h=this.sourceSide.split(this.lanesNumber,!0),o=this.targetSide.split(this.lanesNumber);if(null==this.lanes||this.lanes.length<this.lanesNumber)for(null==this.lanes&&(this.lanes=[]),t=s=0,e=this.lanesNumber-1;0<=e?s<=e:s>=e;t=0<=e?++s:--s)null==(i=this.lanes)[t]&&(i[t]=new O(h[t],o[t],this));const u=[];for(t=n=0,r=this.lanesNumber-1;0<=r?n<=r:n>=r;t=0<=r?++n:--n)this.lanes[t].sourceSegment=h[t],this.lanes[t].targetSegment=o[t],this.lanes[t].leftAdjacent=this.lanes[t+1],this.lanes[t].rightAdjacent=this.lanes[t-1],this.lanes[t].leftmostAdjacent=this.lanes[this.lanesNumber-1],this.lanes[t].rightmostAdjacent=this.lanes[0],u.push(this.lanes[t].update());return u}}class N{constructor(t){this.toRemove=[],this.options=t||{},this.carsNumber=this.options.carsNumber||10,this.gridSize=this.options.gridSize||32,this.u=0,this.l=0,this.g=5,this.carsList={},this.p=new s.GLTFLayer("traffic"),this.m="stop",this.v=[],this.M={},this.set()}run(){this.m="running",this.L()}stop(){this.m="stop"}remove(){this.C&&cancelAnimationFrame(this.C),this.p.remove(),delete this.map}setSymbols(t){this.v=t;for(let t=0;t<this.v.length;t++){const i=this.v[t];this.M[i.url]=new s.MultiGLTFMarker([],{symbol:i}).addTo(this.p)}}L(){if("running"!==this.m)return;const t=Date.now();this.l=t;const i=Date.now();let s,n=i-this.u||0;n>100&&(n=100),this.u=i,this.onTick(this.g*n/1e3);let e=this.toRemove.length;for(;e--;)this.R(this.toRemove[e]);this.clearTmpRemove();const r=this.cars.all();for(s in r)this.N(r[s],s);this.C=window.requestAnimationFrame(this.L.bind(this))}I(){for(const t in this.M)this.M[t].removeData();for(const t in this.carsList){const i=this.carsList[t],s=i.url;this.M[s].addData(i)}}N(t){const i=t.id.substring(3);if(this.carsList[i]){if(!t)return;const s=t.coords,n=t.direction,e=this.map,h=e.pointAtResToCoordinate(new r.Point(s.x/this.gridSize,s.y/this.gridSize),e.getGLRes()),o=n/Math.PI*180+90;this.carsList[i].coordinates=h,this.carsList[i].rotation=[0,0,o];const u=this.S(i),l=this.carsList[i].url;u>-1?this.M[l].updateData(u,this.carsList[i]):this.M[l].addData(this.carsList[i])}else{const t=this.v[Math.floor(Math.random()*this.v.length)];this.carsList[i]={coordinates:null,direction:null,url:t.url},this.showHideCar(this.carsList[i],"show")}}showHideCar(t,i,s){const n=this;r.animation.Animation.animate({"symbol":{transparent:1}},{duration:1e3,easing:"out"},(function(e){if("running"===e.state.playState){let r=0;"show"===i?(r=e.styles.symbol.transparent,t.color=[1,1,1,r]):"hide"===i&&(r=1-e.styles.symbol.transparent,t.color=[1,1,1,r],r<.01&&setTimeout((function(){const t=n.S(s);if(!n.carsList[s])return;const i=n.carsList[s].url;t>-1&&n.M[i].removeData(t),delete n.carsList[s]}),100))}})).play()}S(t){const i=this.carsList[t];if(!i)return-1;const s=i.url;return this.M[s].getAllData().indexOf(this.carsList[t])}R(t){const i=t.substring(3);null!=this.carsList[i]&&this.showHideCar(this.carsList[i],"hide",i)}get instantSpeed(){const t=function(t,i,s){const n=[];return null==t?n:nativeMap&&t.map===nativeMap?t.map(i,s):(d(t,(t,e,r)=>{n.push(i.call(s,t,e,r))}),n)}(this.cars.all(),t=>t.speed);return 0===t.length?0:function(t,i,s,n){let e=arguments.length>2;return null==t&&(t=[]),nativeReduce&&t.reduce===nativeReduce?(n&&(i=c(i,n)),e?t.reduce(i,s):t.reduce(i)):(d(t,(t,r,h)=>{e?s=i.call(n,s,t,r,h):(s=t,e=!0)}),s)}(t,(function(t,i){return t+i}))/t.length}get map(){const t=this.T;return t?t.getMap():null}addTo(t){this.T=t,this.p.addTo(t)}set(t){return null==t&&(t={}),this.intersections=new w(b,t.intersections),this.roads=new w(R,t.roads),this.cars=new w(E,t.cars),this.carsNumber=0}save(){const t=f({},this);return delete t.cars,window.localStorage.world=JSON.stringify(t)}setCarNumber(t){this.carsNumber=t}getCarNumber(){return this.carsNumber}load(){let t,i,s,n;if(t=window.localStorage.world,t=t&&JSON.parse(t),null==t)return null;this.clear(),this.carsNumber=t.carsNumber||0;const e=t.intersections;for(i in e)s=e[i],this.addIntersection(b.copy(s));const r=t.roads,h=[];for(i in r)n=r[i],n=(new R).copy(n),n.source=this.getIntersection(n.source),n.target=this.getIntersection(n.target),h.push(this.addRoad(n));return h}intersectSegment(t,i){for(let s=0;s<i.length-1;s++){const n=[i[s],i[s+1]],e=h.lineString(n),r=h.lineIntersect(t,e);if(r.features.length)return{intersectIndex:s,coord:r.features[0].geometry.coordinates}}return null}intersection(t,i,s,n,e,r){const o=h.lineString(t);for(let t=i+1;t<n.length;t++){const h=n[t],u=this.intersectSegment(o,h);if(!u)continue;const l={};l[i]={pre:s},l[t]={pre:u.intersectIndex+r[t]};const c={inLines:l,coordinate:this.map.coordinateToPointAtRes({x:u.coord[0],y:u.coord[1]},this.map.getGLRes())};e.push(c)}}generateTraffic(t){if(!this.map)return;const i={};let s=0;for(let n=0;n<t.length;n++)i[n]=s,s+=t[n].length;const n=[];let e=0;for(let s=0;s<t.length;s++){const r=t[s];for(let h=0;h<r.length-1;h++){const o=[r[h],r[h+1]];this.intersection(o,s,e+h,t,n,i)}e+=r.length}const r=[];let h=0;const o=this.map;for(let i=0;i<t.length;i++){const s=t[i];for(let t=0;t<s.length;t++){const n=o.coordinateToPointAtRes({x:s[t][0],y:s[t][1]},o.getGLRes()),e={};0===t?e[i]={pre:null}:(s.length,e[i]={pre:t-1+h});const u={inLines:e,coordinate:n};r.push(u)}h+=s.length}for(let t=0;t<r.length;t++){const i=r[t];this.comparePrePoint(i,t,n)}const u=this.gridSize,l=[];for(let t=0;t<r.length;t++){const i=r[t],s=i.coordinate.x,n=i.coordinate.y,e=new v(s*u-.5,n*u-.5,1,1),h=new b(e);h.connectRoads=i.roads,l.push(h),this.addIntersection(h)}const c=[];for(let t=0;t<n.length;t++){const i=n[t],s=i.coordinate.x,e=i.coordinate.y,r=new v(s*u-.5,e*u-.5,1,1),h=new b(r);h.connectRoads=i.roads,c.push(h),this.addIntersection(h)}for(let t=0;t<l.length;t++){const i=l[t],s=i.connectRoads;if(s)for(let t=0;t<s.length;t++){const n=s[t];if(null!=n.pre){let t=null;const s=n.type;"line"===s?t=l[n.pre]:"line-interact"===s&&(t=c[n.pre]),this.addRoad(new R(i,t)),this.addRoad(new R(t,i))}}}for(let t=0;t<c.length;t++){const i=c[t],s=i.connectRoads;if(s)for(let t=0;t<s.length;t++){const n=s[t];if(null!=n.pre){let t=null;const s=n.type;"line"===s?t=l[n.pre]:"line-interact"===s&&(t=c[n.pre]),this.addRoad(new R(i,t)),this.addRoad(new R(t,i))}}}}comparePrePoint(t,i,s){const n=this.getPre(t);if(n){const{pre:e,lineIndex:r}=n;for(let n=0;n<s.length;n++){const h=s[n];h.inLines[r]&&h.inLines[r].pre===e&&(t.roads=[{pre:n,type:"line-interact"}],h.roads?h.roads.push({pre:i-1,type:"line"}):h.roads=[{pre:i-1,type:"line"}])}t.roads||(t.roads=[{pre:i-1,type:"line"}])}}getPre(t){for(const i in t.inLines)if(null!==t.inLines[i].pre)return{pre:t.inLines[i].pre,lineIndex:i};return null}clear(){return this.set({})}onTick(t){let i,s,n;if(t>1)throw Error("delta > 1");this.refreshCars();const e=this.intersections.all();for(s in e)n=e[s],n.controlSignals.onTick(t);const r=this.cars.all(),h=[];for(s in r)i=r[s],i.move(t),i.alive?h.push(void 0):h.push(this.removeCar(i));return h}refreshCars(){return this.cars.length<this.carsNumber&&this.addRandomCar(),this.cars.length>this.carsNumber?this.removeRandomCar():null}addRoad(t){return this.roads.put(t),t.source.roads.push(t),t.target.inRoads.push(t),t.update()}getRoad(t){return this.roads.get(t)}addCar(t){return this.cars.put(t)}getCar(t){return this.cars.get(t)}removeCar(t){return this.toRemove.push(t.id),this.cars.pop(t)}clearTmpRemove(){this.toRemove=[]}addIntersection(t){return this.intersections.put(t)}getIntersection(t){return this.intersections.get(t)}addRandomCar(){let t;const i=u(this.roads.all());return null!=i&&(t=u(i.lanes),null!=t)?this.addCar(new E(t)):null}removeRandomCar(){const t=u(this.cars.all());return null!=t?this.removeCar(t):null}}"undefined"!=typeof window&&window.maptalks&&(window.maptalks.TrafficScene=N),t.TrafficScene=N,Object.defineProperty(t,"t",{value:!0}),"undefined"!=typeof console&&console.log("@maptalks/traffic v0.87.2")}));
|
package/package.json
CHANGED
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@maptalks/traffic",
|
|
3
|
-
"version": "0.87.
|
|
4
|
-
"description": "a tool to render traffic effect",
|
|
5
|
-
"license": "UNLICENSED",
|
|
6
|
-
"repository": {
|
|
7
|
-
"type": "git",
|
|
8
|
-
"url": "https://github.com/liubgithub/traffic.git"
|
|
9
|
-
},
|
|
10
|
-
"main": "dist/maptalks.traffic.js",
|
|
11
|
-
"module": "dist/maptalks.traffic.es.js",
|
|
12
|
-
"unpkg": "dist/maptalks.traffic.js",
|
|
13
|
-
"jsdelivr": "dist/maptalks.traffic.js",
|
|
14
|
-
"files": [
|
|
15
|
-
"dist/maptalks.traffic.js",
|
|
16
|
-
"dist/maptalks.traffic.es.js"
|
|
17
|
-
],
|
|
18
|
-
"scripts": {
|
|
19
|
-
"dev": "rollup -w -c rollup.config.js",
|
|
20
|
-
"build": "rollup --environment BUILD:production -c rollup.config.js",
|
|
21
|
-
"build-dev": "rollup -c rollup.config.js",
|
|
22
|
-
"pretest": "npm run lint && npm run build",
|
|
23
|
-
"test": "karma start --single-run",
|
|
24
|
-
"tdd": "karma start --no-single-run",
|
|
25
|
-
"preversion": "npm run lint",
|
|
26
|
-
"version": "npm run build",
|
|
27
|
-
"lint": "eslint src/**/*.js",
|
|
28
|
-
"prepare": "npm run build"
|
|
29
|
-
},
|
|
30
|
-
"devDependencies": {
|
|
31
|
-
"@babel/eslint-parser": "^7.15.0",
|
|
32
|
-
"@babel/preset-env": "^7.15.0",
|
|
33
|
-
"@maptalks/
|
|
34
|
-
"@rollup/plugin-commonjs": "^20.0.0",
|
|
35
|
-
"@rollup/plugin-json": "^4.1.0",
|
|
36
|
-
"@rollup/plugin-node-resolve": "^13.0.4",
|
|
37
|
-
"@rollup/plugin-replace": "4.0.0",
|
|
38
|
-
"eslint": "^7.32.0",
|
|
39
|
-
"eslint-plugin-mocha": "^9.0.0",
|
|
40
|
-
"expect.js": "^0.3.1",
|
|
41
|
-
"karma": "^6.4.1",
|
|
42
|
-
"karma-chrome-launcher": "^3.1.1",
|
|
43
|
-
"karma-expect": "^1.1.3",
|
|
44
|
-
"karma-mocha": "^2.0.1",
|
|
45
|
-
"karma-mocha-reporter": "^2.2.5",
|
|
46
|
-
"maptalks": "^1.0.0-rc.23",
|
|
47
|
-
"mocha": "^9.0.3",
|
|
48
|
-
"rollup": "^2.56.2",
|
|
49
|
-
"rollup-plugin-terser": "^5.3.1",
|
|
50
|
-
"turf": "3.0.14"
|
|
51
|
-
},
|
|
52
|
-
"gitHead": "
|
|
53
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@maptalks/traffic",
|
|
3
|
+
"version": "0.87.2",
|
|
4
|
+
"description": "a tool to render traffic effect",
|
|
5
|
+
"license": "UNLICENSED",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/liubgithub/traffic.git"
|
|
9
|
+
},
|
|
10
|
+
"main": "dist/maptalks.traffic.js",
|
|
11
|
+
"module": "dist/maptalks.traffic.es.js",
|
|
12
|
+
"unpkg": "dist/maptalks.traffic.js",
|
|
13
|
+
"jsdelivr": "dist/maptalks.traffic.js",
|
|
14
|
+
"files": [
|
|
15
|
+
"dist/maptalks.traffic.js",
|
|
16
|
+
"dist/maptalks.traffic.es.js"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"dev": "rollup -w -c rollup.config.js",
|
|
20
|
+
"build": "rollup --environment BUILD:production -c rollup.config.js",
|
|
21
|
+
"build-dev": "rollup -c rollup.config.js",
|
|
22
|
+
"pretest": "npm run lint && npm run build",
|
|
23
|
+
"test": "karma start --single-run",
|
|
24
|
+
"tdd": "karma start --no-single-run",
|
|
25
|
+
"preversion": "npm run lint",
|
|
26
|
+
"version": "npm run build",
|
|
27
|
+
"lint": "eslint src/**/*.js",
|
|
28
|
+
"prepare": "npm run build"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@babel/eslint-parser": "^7.15.0",
|
|
32
|
+
"@babel/preset-env": "^7.15.0",
|
|
33
|
+
"@maptalks/gl-layers": "0.23.0",
|
|
34
|
+
"@rollup/plugin-commonjs": "^20.0.0",
|
|
35
|
+
"@rollup/plugin-json": "^4.1.0",
|
|
36
|
+
"@rollup/plugin-node-resolve": "^13.0.4",
|
|
37
|
+
"@rollup/plugin-replace": "4.0.0",
|
|
38
|
+
"eslint": "^7.32.0",
|
|
39
|
+
"eslint-plugin-mocha": "^9.0.0",
|
|
40
|
+
"expect.js": "^0.3.1",
|
|
41
|
+
"karma": "^6.4.1",
|
|
42
|
+
"karma-chrome-launcher": "^3.1.1",
|
|
43
|
+
"karma-expect": "^1.1.3",
|
|
44
|
+
"karma-mocha": "^2.0.1",
|
|
45
|
+
"karma-mocha-reporter": "^2.2.5",
|
|
46
|
+
"maptalks": "^1.0.0-rc.23",
|
|
47
|
+
"mocha": "^9.0.3",
|
|
48
|
+
"rollup": "^2.56.2",
|
|
49
|
+
"rollup-plugin-terser": "^5.3.1",
|
|
50
|
+
"turf": "3.0.14"
|
|
51
|
+
},
|
|
52
|
+
"gitHead": "9eeea4807723d460fa7e09969c6556d53f6bed84"
|
|
53
|
+
}
|