nodes.js 844 Bytes
Newer Older
Athanasios's avatar
Athanasios committed
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
class Nodes {

  constructor() {
    this.nodes = [];
  }

  get sorted() {
    return this.nodes.sort((a, b) => a.distanceToCamera > b.distanceToCamera);
  }

  add(context, node, boundingSphere) {

    let entry = {
      id: node.id,
      level: node.level,
      lng: node.mbs[0],
      lat: node.mbs[1],
      radius: node.mbs[3],
      url: `${context.layer}/nodes/${node.id}`,
      distanceToCamera: boundingSphere.distanseTo(context.camera.position),
      time: context.requestTime
    };

    if (context.intersect) {
      let requestedBB = context.bb.clone();
      requestedBB.extend(25);
      if (requestedBB.intersectWithGeographic(boundingSphere.geographicCenter)) {
        this.nodes.push(entry);
      }
    } else {
      this.nodes.push(entry);
    }

  }

}

module.exports = Nodes;