Passed
Push — develop ( 9a1b4b...96b452 )
by Xaver
03:40
created

lib/map/clientlayer.js   A

Complexity

Total Complexity 8
Complexity/F 1.33

Size

Lines of Code 62
Function Count 6

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 8
eloc 37
mnd 2
bc 2
fnc 6
dl 0
loc 62
rs 10
bpm 0.3333
cpm 1.3333
noi 0
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A clientlayer.js ➔ mapRTree 0 7 2
1
define(['leaflet', 'rbush', 'helper'],
2
  function (L, RBush, helper) {
3
    'use strict';
4
5
    return L.GridLayer.extend({
6
      mapRTree: function mapRTree(d) {
7
        return {
8
          minX: d.location.latitude, minY: d.location.longitude,
9
          maxX: d.location.latitude, maxY: d.location.longitude,
10
          node: d
11
        };
12
      },
13
      setData: function (data) {
14
        var rtreeOnlineAll = new RBush(9);
15
16
        this.data = rtreeOnlineAll.load(data.nodes.online.filter(helper.hasLocation).map(this.mapRTree));
17
18
        // pre-calculate start angles
19
        this.data.all().forEach(function (n) {
20
          n.startAngle = (parseInt(n.node.node_id.substr(10, 2), 16) / 255) * 2 * Math.PI;
21
        });
22
        this.redraw();
23
      },
24
      createTile: function (tilePoint) {
25
        var tile = L.DomUtil.create('canvas', 'leaflet-tile');
26
27
        var tileSize = this.options.tileSize;
28
        tile.width = tileSize;
29
        tile.height = tileSize;
30
31
        if (!this.data) {
32
          return tile;
33
        }
34
35
        var ctx = tile.getContext('2d');
36
        var s = tilePoint.multiplyBy(tileSize);
37
        var map = this._map;
38
39
        var margin = 50;
40
        var bbox = helper.getTileBBox(s, map, tileSize, margin);
41
42
        var nodes = this.data.search(bbox);
43
44
        if (nodes.length === 0) {
45
          return tile;
46
        }
47
48
        var startDistance = 10;
49
50
        nodes.forEach(function (d) {
51
          var p = map.project([d.node.location.latitude, d.node.location.longitude]);
52
53
          p.x -= s.x;
54
          p.y -= s.y;
55
56
          helper.positionClients(ctx, p, d.startAngle, d.node, startDistance);
57
        });
58
59
        return tile;
60
      }
61
    });
62
  });
63