2017-04-30 12:59:39 +00:00
|
|
|
define(['leaflet', 'rbush', 'helper'],
|
|
|
|
function (L, rbush, helper) {
|
2017-01-29 23:51:08 +00:00
|
|
|
'use strict';
|
2015-06-01 20:36:10 +00:00
|
|
|
|
2017-03-14 18:25:11 +00:00
|
|
|
return L.GridLayer.extend({
|
2017-04-30 12:59:39 +00:00
|
|
|
mapRTree: function mapRTree(d) {
|
|
|
|
return {
|
2017-10-29 14:11:24 +00:00
|
|
|
minX: d.location.latitude, minY: d.location.longitude,
|
|
|
|
maxX: d.location.latitude, maxY: d.location.longitude,
|
2017-04-30 12:59:39 +00:00
|
|
|
node: d
|
|
|
|
};
|
|
|
|
},
|
|
|
|
setData: function (data) {
|
|
|
|
var rtreeOnlineAll = rbush(9);
|
|
|
|
|
|
|
|
this.data = rtreeOnlineAll.load(data.nodes.all.filter(helper.online).filter(helper.hasLocation).map(this.mapRTree));
|
2015-06-01 20:36:10 +00:00
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
// pre-calculate start angles
|
|
|
|
this.data.all().forEach(function (n) {
|
2017-10-29 14:11:24 +00:00
|
|
|
n.startAngle = (parseInt(n.node.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
|
|
|
},
|
2017-03-14 18:25:11 +00:00
|
|
|
createTile: function (tilePoint) {
|
|
|
|
var tile = L.DomUtil.create('canvas', 'leaflet-tile');
|
|
|
|
|
|
|
|
var tileSize = this.options.tileSize;
|
|
|
|
tile.width = tileSize;
|
|
|
|
tile.height = tileSize;
|
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
if (!this.data) {
|
2017-03-14 18:25:11 +00:00
|
|
|
return tile;
|
2016-05-22 12:51:30 +00:00
|
|
|
}
|
2015-04-17 20:27:24 +00:00
|
|
|
|
2017-03-14 18:25:11 +00:00
|
|
|
var ctx = tile.getContext('2d');
|
2016-05-22 11:23:43 +00:00
|
|
|
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;
|
2017-02-05 01:34:09 +00:00
|
|
|
var bbox = helper.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) {
|
2017-03-14 18:25:11 +00:00
|
|
|
return tile;
|
2016-05-22 12:51:30 +00:00
|
|
|
}
|
2015-04-17 20:27:24 +00:00
|
|
|
|
2017-10-28 23:38:43 +00:00
|
|
|
var startDistance = 10;
|
2015-04-17 20:27:24 +00:00
|
|
|
|
|
|
|
nodes.forEach(function (d) {
|
2017-10-29 14:11:24 +00:00
|
|
|
var p = map.project([d.node.location.latitude, d.node.location.longitude]);
|
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
|
|
|
|
2017-10-28 23:38:43 +00:00
|
|
|
helper.positionClients(ctx, p, d.startAngle, d.node, startDistance);
|
2016-05-22 11:23:43 +00:00
|
|
|
});
|
2015-04-19 10:22:09 +00:00
|
|
|
|
2017-03-14 18:25:11 +00:00
|
|
|
|
|
|
|
return tile;
|
2015-04-19 10:22:09 +00:00
|
|
|
}
|
2016-05-22 11:23:43 +00:00
|
|
|
});
|
2016-05-22 12:51:30 +00:00
|
|
|
});
|