-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmisc.js
105 lines (95 loc) · 2.31 KB
/
misc.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
// ------------------------------
// ------------------------------
// ------------------------------
// ------------------------------
// let cities
// fetch('./data/cities.geojson')
// .then((response) => response.json())
// .then(json => cities = json)
let cities = await util.xhrPromise('./data/uscities.geojson', 'json')
let counties = await util.xhrPromise('./data/uscounties.json', 'json')
let states = await util.xhrPromise('./data/usstates.geojson', 'json')
// function mapPromise(map) {
// return new Promise((resolve, reject) => {
// map.on('load', () => resolve())
// })
// }
// await mapPromise(map)
// console.log('map loaded')
// ------------------------------
import('../src/gis.js').then(m => (window.gis = m.default))
util.dump()
l = ls.oneOf()
len = gis.lonLat2meters([l.end0.lon, l.end0.lat], [l.end1.lon, l.end1.lat])
radians = degrees => (degrees * Math.PI) / 180
let [pt1, pt2] = [
[l.end0.lon, l.end0.lat],
[l.end1.lon, l.end1.lat],
]
let [lon1, lat1] = pt1.map(val => radians(val))
// ------------------------------
async function foo(val) {
const ms = 2000
await util.timeoutPromise(ms)
console.log('done', ms)
// ms returned as the result of the foo promise
return ms
}
foo(2000).then(val => console.log(val))
// ------------------------------
s = `{
"ticks": 500,
"model": [
"ticks",
"world",
"patches",
"turtles",
"links",
"population",
"speed",
"wiggle"
],
"patches": 10201,
"patch": {
"id": 6061
},
"turtles": 1000,
"turtle": {
"id": 970,
"theta": 2.2594884500660295,
"x": 8.959619891506229,
"y": 19.997493746915403,
"links": [
970
]
},
"links": 1000,
"link": {
"id": 973,
"end0": {
"id": 973,
"theta": -0.1238336464778842,
"x": -11.468510239029987,
"y": -38.12513187598359,
"links": [
811,
973
]
},
"end1": {
"id": 310,
"theta": -5.147058801081283,
"x": -1.1990260586185204,
"y": -9.070063756578504,
"links": [
310,
973
]
}
}
}
`
re = /"([^"]+)":/gm
s.replace(/"([^"]+)":/gm, '$1:')
sample.replace(/"([^"]+)":/gm, '$1:')
// ------------------------------