use node_id hash to calculate startAngle for client layer

This commit is contained in:
Florian Klink 2015-06-01 22:36:10 +02:00
parent 47c7fcbfb5
commit 008a1d0b0b
3 changed files with 15 additions and 5 deletions

3
app.js
View file

@ -13,7 +13,8 @@ require.config({
"numeral-intl": "../bower_components/numeraljs/min/languages.min",
"virtual-dom": "../bower_components/virtual-dom/dist/virtual-dom",
"rbush": "../bower_components/rbush/rbush",
"helper": "../helper"
"helper": "../helper",
"jshashes": "../bower_components/jshashes/hashes"
},
shim: {
"leaflet.label": ["leaflet"],

View file

@ -24,7 +24,8 @@
"roboto-fontface": "~0.3.0",
"virtual-dom": "~2.0.1",
"leaflet-providers": "~1.0.27",
"rbush": "https://github.com/mourner/rbush.git#~1.3.5"
"rbush": "https://github.com/mourner/rbush.git#~1.3.5",
"jshashes": "~1.0.5"
},
"authors": [
"Nils Schneider <nils@nilsschneider.net>"

View file

@ -1,8 +1,16 @@
define(["leaflet"],
function (L) {
define(["leaflet", "jshashes"],
function (L, jsHashes) {
var MD5 = new jsHashes.MD5()
return L.TileLayer.Canvas.extend({
setData: function (d) {
this.data = d
//pre-calculate start angles
this.data.all().forEach(function (d) {
var hash = MD5.hex(d.node.nodeinfo.node_id)
d.startAngle = (parseInt(hash.substr(0, 2), 16) / 255) * 2 * Math.PI
})
this.redraw()
},
drawTile: function (canvas, tilePoint) {
@ -33,7 +41,6 @@ define(["leaflet"],
var radius = 3
var a = 1.2
var startDistance = 12
var startAngle = Math.PI
ctx.beginPath()
nodes.forEach(function (d) {
@ -47,6 +54,7 @@ define(["leaflet"],
p.y -= s.y
var distance = startDistance
var startAngle = d.startAngle
var angle = startAngle
for (var i = 0; i < clients; i++) {