2016-05-25 22:27:46 +00:00
|
|
|
define(["leaflet"],
|
|
|
|
function (L) {
|
2015-06-01 20:36:10 +00:00
|
|
|
|
2015-04-17 20:27:24 +00:00
|
|
|
return L.TileLayer.Canvas.extend({
|
|
|
|
setData: function (d) {
|
2016-05-22 11:23:43 +00:00
|
|
|
this.data = d;
|
2015-06-01 20:36:10 +00:00
|
|
|
|
|
|
|
//pre-calculate start angles
|
|
|
|
this.data.all().forEach(function (d) {
|
2016-05-25 22:27:46 +00:00
|
|
|
d.startAngle = (parseInt(d.node.nodeinfo.node_id.substr(10, 2), 16) / 255) * 2 * Math.PI;
|
2016-05-22 11:23:43 +00:00
|
|
|
});
|
|
|
|
this.redraw();
|
2015-04-17 20:27:24 +00:00
|
|
|
},
|
|
|
|
drawTile: function (canvas, tilePoint) {
|
2015-04-19 10:22:09 +00:00
|
|
|
function getTileBBox(s, map, tileSize, margin) {
|
2016-05-22 11:23:43 +00:00
|
|
|
var tl = map.unproject([s.x - margin, s.y - margin]);
|
|
|
|
var br = map.unproject([s.x + margin + tileSize, s.y + margin + tileSize]);
|
2015-04-19 10:22:09 +00:00
|
|
|
|
2016-05-22 11:23:43 +00:00
|
|
|
return [br.lat, tl.lng, tl.lat, br.lng];
|
2015-04-19 10:22:09 +00:00
|
|
|
}
|
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
if (!this.data) {
|
2016-05-22 11:23:43 +00:00
|
|
|
return;
|
2016-05-22 12:51:30 +00:00
|
|
|
}
|
2015-04-17 20:27:24 +00:00
|
|
|
|
2016-05-22 11:23:43 +00:00
|
|
|
var tileSize = this.options.tileSize;
|
|
|
|
var s = tilePoint.multiplyBy(tileSize);
|
|
|
|
var map = this._map;
|
2015-04-17 20:27:24 +00:00
|
|
|
|
2016-05-22 11:23:43 +00:00
|
|
|
var margin = 50;
|
|
|
|
var bbox = getTileBBox(s, map, tileSize, margin);
|
2015-04-19 10:22:09 +00:00
|
|
|
|
2016-05-22 11:23:43 +00:00
|
|
|
var nodes = this.data.search(bbox);
|
2015-04-19 10:22:09 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
if (nodes.length === 0) {
|
2016-05-22 11:23:43 +00:00
|
|
|
return;
|
2016-05-22 12:51:30 +00:00
|
|
|
}
|
2015-04-17 20:27:24 +00:00
|
|
|
|
2016-05-22 11:23:43 +00:00
|
|
|
var ctx = canvas.getContext("2d");
|
2015-04-19 10:22:09 +00:00
|
|
|
|
2016-05-22 11:23:43 +00:00
|
|
|
var radius = 3;
|
|
|
|
var a = 1.2;
|
|
|
|
var startDistance = 12;
|
2015-04-17 20:27:24 +00:00
|
|
|
|
2016-05-22 11:23:43 +00:00
|
|
|
ctx.beginPath();
|
2015-04-17 20:27:24 +00:00
|
|
|
nodes.forEach(function (d) {
|
2016-05-22 11:23:43 +00:00
|
|
|
var p = map.project([d.node.nodeinfo.location.latitude, d.node.nodeinfo.location.longitude]);
|
|
|
|
var clients = d.node.statistics.clients;
|
2015-04-19 10:22:09 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
if (clients === 0) {
|
2016-05-22 11:23:43 +00:00
|
|
|
return;
|
2016-05-22 12:51:30 +00:00
|
|
|
}
|
2015-04-19 10:22:09 +00:00
|
|
|
|
2016-05-22 11:23:43 +00:00
|
|
|
p.x -= s.x;
|
|
|
|
p.y -= s.y;
|
2015-04-19 10:22:09 +00:00
|
|
|
|
2015-06-26 23:37:36 +00:00
|
|
|
for (var orbit = 0, i = 0; i < clients; orbit++) {
|
2016-05-22 11:23:43 +00:00
|
|
|
var distance = startDistance + orbit * 2 * radius * a;
|
|
|
|
var n = Math.floor((Math.PI * distance) / (a * radius));
|
|
|
|
var delta = clients - i;
|
2015-04-19 10:22:09 +00:00
|
|
|
|
2015-06-26 23:37:36 +00:00
|
|
|
for (var j = 0; j < Math.min(delta, n); i++, j++) {
|
2016-05-22 11:23:43 +00:00
|
|
|
var angle = 2 * Math.PI / n * j;
|
|
|
|
var x = p.x + distance * Math.cos(angle + d.startAngle);
|
|
|
|
var y = p.y + distance * Math.sin(angle + d.startAngle);
|
2015-04-19 10:22:09 +00:00
|
|
|
|
2016-05-22 11:23:43 +00:00
|
|
|
ctx.moveTo(x, y);
|
|
|
|
ctx.arc(x, y, radius, 0, 2 * Math.PI);
|
2015-06-26 23:37:36 +00:00
|
|
|
}
|
2015-04-19 10:22:09 +00:00
|
|
|
}
|
2016-05-22 11:23:43 +00:00
|
|
|
});
|
2015-04-19 10:22:09 +00:00
|
|
|
|
2016-05-22 11:23:43 +00:00
|
|
|
ctx.fillStyle = "rgba(220, 0, 103, 0.7)";
|
|
|
|
ctx.fill();
|
2015-04-19 10:22:09 +00:00
|
|
|
}
|
2016-05-22 11:23:43 +00:00
|
|
|
});
|
2016-05-22 12:51:30 +00:00
|
|
|
});
|