-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtools.js
41 lines (35 loc) · 1.01 KB
/
tools.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
export function mapLoadPromise(map) {
return new Promise((resolve, reject) => {
map.on('load', () => resolve())
})
}
export async function importModel(url, width, bbox) {
const [west, south, east, north] = bbox
const aspect = (east - west) / (north - south)
const Model = (await import(url)).default
const worldOptions = {
minX: 0,
minY: 0,
maxX: width,
maxY: Math.round(width / aspect),
}
const model = new Model(worldOptions)
await model.startup()
model.setup()
util.toWindow({ Model, model, width, aspect, worldOptions })
return model
}
export function bboxCenter(bbox) {
const [west, south, east, north] = bbox
return [(west + east) / 2, (south + north) / 2]
}
export function bboxCoords(bbox) {
const [west, south, east, north] = bbox
return [
[west, north],
[east, north],
[east, south],
[west, south],
]
}
export default { mapLoadPromise, importModel, bboxCenter, bboxCoords }