meshviewer/lib/map/clientlayer.js

53 lines
1.3 KiB
JavaScript
Raw Normal View History

define(['leaflet', 'helper'],
function (L, helper) {
'use strict';
2015-04-17 20:27:24 +00:00
return L.TileLayer.Canvas.extend({
setData: function (d) {
this.data = d;
// pre-calculate start angles
this.data.all().forEach(function (n) {
n.startAngle = (parseInt(n.node.nodeinfo.node_id.substr(10, 2), 16) / 255) * 2 * Math.PI;
});
this.redraw();
2015-04-17 20:27:24 +00:00
},
drawTile: function (canvas, tilePoint) {
if (!this.data) {
return;
}
2015-04-17 20:27:24 +00:00
var tileSize = this.options.tileSize;
var s = tilePoint.multiplyBy(tileSize);
var map = this._map;
2015-04-17 20:27:24 +00:00
var margin = 50;
var bbox = helper.getTileBBox(s, map, tileSize, margin);
var nodes = this.data.search(bbox);
if (nodes.length === 0) {
return;
}
2015-04-17 20:27:24 +00:00
var ctx = canvas.getContext('2d');
var startDistance = 12;
2015-04-17 20:27:24 +00:00
ctx.beginPath();
2015-04-17 20:27:24 +00:00
nodes.forEach(function (d) {
var p = map.project([d.node.nodeinfo.location.latitude, d.node.nodeinfo.location.longitude]);
p.x -= s.x;
p.y -= s.y;
helper.positionClients(ctx, p, d.startAngle, d.node.statistics.clients, startDistance);
});
ctx.fillStyle = 'rgba(220, 0, 103, 0.7)';
ctx.fill();
}
});
});