From 008a1d0b0b9491a17af02fbcc1e8cf9a051149b7 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Mon, 1 Jun 2015 22:36:10 +0200 Subject: [PATCH] use node_id hash to calculate startAngle for client layer --- app.js | 3 ++- bower.json | 3 ++- lib/map/clientlayer.js | 14 +++++++++++--- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/app.js b/app.js index 50e61c6..71c87e6 100644 --- a/app.js +++ b/app.js @@ -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"], diff --git a/bower.json b/bower.json index 20bf6fe..540768f 100644 --- a/bower.json +++ b/bower.json @@ -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 " diff --git a/lib/map/clientlayer.js b/lib/map/clientlayer.js index 7dd5b57..036bf47 100644 --- a/lib/map/clientlayer.js +++ b/lib/map/clientlayer.js @@ -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++) {