nodes.js 914 Bytes
Newer Older
athanasios's avatar
athanasios committed
1
2
const config = require("../config");

Athanasios's avatar
Athanasios committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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
    };

athanasios's avatar
athanasios committed
26
    if (context.bb != null) {
Athanasios's avatar
Athanasios committed
27
      let requestedBB = context.bb.clone();
athanasios's avatar
athanasios committed
28
      requestedBB.extend(config.boundingBoxBufferPercent);
Athanasios's avatar
Athanasios committed
29
30
31
32
33
34
35
36
37
38
39
40
      if (requestedBB.intersectWithGeographic(boundingSphere.geographicCenter)) {
        this.nodes.push(entry);
      }
    } else {
      this.nodes.push(entry);
    }

  }

}

module.exports = Nodes;