Completed
Pull Request — develop (#85)
by Xaver
01:10
created

clientlayer.js ➔ ... ➔ nodes.forEach   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
c 0
b 0
f 0
nc 1
dl 0
loc 8
rs 9.4285
nop 1
1
define(['leaflet', 'helper'],
2
  function (L, helper) {
3
    'use strict';
4
5
    return L.GridLayer.extend({
6
      setData: function (d) {
7
        this.data = d;
8
9
        // pre-calculate start angles
10
        this.data.all().forEach(function (n) {
11
          n.startAngle = (parseInt(n.node.nodeinfo.node_id.substr(10, 2), 16) / 255) * 2 * Math.PI;
12
        });
13
        this.redraw();
14
      },
15
      createTile: function (tilePoint) {
16
        var tile = L.DomUtil.create('canvas', 'leaflet-tile');
17
18
        var tileSize = this.options.tileSize;
19
        tile.width = tileSize;
20
        tile.height = tileSize;
21
22
        if (!this.data) {
23
          return tile;
24
        }
25
26
        var ctx = tile.getContext('2d');
27
        var s = tilePoint.multiplyBy(tileSize);
28
        var map = this._map;
29
30
        var margin = 50;
31
        var bbox = helper.getTileBBox(s, map, tileSize, margin);
32
33
        var nodes = this.data.search(bbox);
34
35
        if (nodes.length === 0) {
36
          return tile;
37
        }
38
39
        var startDistance = 12;
40
41
        ctx.beginPath();
42
        nodes.forEach(function (d) {
43
          var p = map.project([d.node.nodeinfo.location.latitude, d.node.nodeinfo.location.longitude]);
44
45
          p.x -= s.x;
46
          p.y -= s.y;
47
48
          helper.positionClients(ctx, p, d.startAngle, d.node.statistics.clients, startDistance);
49
        });
50
51
        ctx.fillStyle = 'rgba(220, 0, 103, 0.7)';
52
        ctx.fill();
53
54
        return tile;
55
      }
56
    });
57
  });
58