Commit 6dc3e688 authored by ZettaScript's avatar ZettaScript

Add id selection, highlight certs

parent fffac646
......@@ -81,7 +81,7 @@ a, a:visited {
<div id="header-text">
<h1>WorldWotMap</h1>
<a href="#map">&#11015; Voir la map &#11015;</a>
<p>WorldWotMap v0.1.0, &copy; 2018 <a href="https://zettascript.org/contact.php">Pascal Engélibert</a> (<a href="https://www.gnu.org/licenses/agpl.html">Licence GNU AGPL v3</a>)</p>
<p>WorldWotMap v0.1.0, &copy; 2018 <a href="https://zettascript.org/contact.php">Pascal Engélibert</a> (<a href="https://www.gnu.org/licenses/agpl.html">Licence GNU AGPL v3</a>) (<a href="https://framagit.org/ZettaScript/worldwotmap/">dépôt Git</a>)</p>
<p>Ceci est une carte affichant les comptes Ğ1 et leurs certifications. La carte peut être incomplète, car il est facultatif de renseigner sa position géographique sur Cesium+.</p>
<a href="gencache.py">Programme Python pour exporter les données de duniter.db</a>
</div>
......@@ -94,6 +94,11 @@ a, a:visited {
<li>Bleu&nbsp;: wallet</li>
<li>Rouge&nbsp;: identité</li>
</ul>
<div id="mapmenu-idcard" class="idcard" style="display: none;">
<input type="button" value="Déselectionner" onclick="" /><br />
<strong class="idcard-title"></strong><br />
<span class="idcard-pubkey"></span>
</div>
</div>
</div>
<script type="text/javascript">
......@@ -105,24 +110,70 @@ class Account {
this.address = address;
this.city = city;
this.point = point;
this.certsIssued = [];
this.certsReceived = [];
}
mapActiveAccount() {// Surprisingly, `this` is not the Account instance...
if(active_account != null)
mapInactiveAccount(active_account);
var account = accounts[this.options["pubkey"]];// Works for me
active_account = account.pubkey;
$("#mapmenu-idcard").attr("style", "display: initial;");
$("#mapmenu-idcard").attr("onclick", "mapInactiveAccount('"+account.pubkey+"');");
$("#mapmenu-idcard .idcard-title").html(account.title);
$("#mapmenu-idcard .idcard-pubkey").html(account.pubkey);
for(var cert in account.certsIssued) {
certs[account.certsIssued[cert]].line.setStyle({color:"#4f4", weight:3, opacity:0.6});
}
for(var cert in account.certsReceived) {
certs[account.certsReceived[cert]].line.setStyle({color:"#f44", weight:3, opacity:0.6});
}
}
}
function mapInactiveAccount(pubkey) {
active_account = null;
var account = accounts[pubkey];
$("#mapmenu-idcard").attr("style", "display: none;");
$("#mapmenu-idcard").attr("onclick", "");
$("#mapmenu-idcard .idcard-title").html("");
$("#mapmenu-idcard .idcard-pubkey").html("");
for(var cert in account.certsIssued) {
certs[account.certsIssued[cert]].line.setStyle({color:"black", weight:1, opacity:0.3});
}
for(var cert in account.certsReceived) {
certs[account.certsReceived[cert]].line.setStyle({color:"black", weight:1, opacity:0.3});
}
}
class Cert {
constructor(issuer, receiver, line) {
this.issuer = issuer;
this.receiver = receiver;
this.line = line;
}
}
var accounts = {};
var certs = [];
var ncerts = 0;
var active_account = null;
var map = L.map("map").setView([46.725, 2.834], 6);
L.tileLayer('https://{s}.tile.osm.org/{z}/{x}/{y}.png', {attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'}).addTo(map);
$.post("https://g1.data.duniter.fr/user/profile/_search", '{"query":{"bool":{"must":[{"exists":{"field":"geoPoint"}}]}},"from":1000,"size":1000,"_source":["title","geoPoint","avatar._content_type","address","city","description"]}', function(data) {
var accounts_data = data["hits"]["hits"];
for(var i=0; i < accounts_data.length; i ++) {
var account = accounts_data[i];
var point = L.circle([account["_source"]["geoPoint"]["lat"], account["_source"]["geoPoint"]["lon"]], {
var account_data = accounts_data[i];
var point = L.circle([account_data["_source"]["geoPoint"]["lat"], account_data["_source"]["geoPoint"]["lon"]], {
color: "#08f",
fillColor: "#08f",
fillOpacity: 0.1,
radius: 50
radius: 50,
pubkey: account_data["_id"]// Yay! Hack because JS is so bad with pointers...
}).addTo(map);
point.bindPopup("<b>"+account["_source"]["title"]+"</b><br/>"+account["_id"]);
accounts[account["_id"]] = new Account(account["_id"], account["_source"]["title"], [account["_source"]["geoPoint"]["lat"], account["_source"]["geoPoint"]["lon"]], account["_source"]["address"], account["_source"]["city"], point);
point.bindPopup("<b>"+account_data["_source"]["title"]+"</b><br/>"+account_data["_id"]);
var account = new Account(account_data["_id"], account_data["_source"]["title"], [account_data["_source"]["geoPoint"]["lat"], account_data["_source"]["geoPoint"]["lon"]], account_data["_source"]["address"], account_data["_source"]["city"], point);
accounts[account_data["_id"]] = account;
point.on("popupopen", account.mapActiveAccount);
}
$.get("duniterdb.json", null, function(data) {
......@@ -132,8 +183,14 @@ $.post("https://g1.data.duniter.fr/user/profile/_search", '{"query":{"bool":{"mu
}
}
for(var i=0; i < data["certs"].length; i ++) {
if(data["certs"][i][0] in accounts && data["certs"][i][1] in accounts && data["certs"][i][3] == 0)
L.polyline([accounts[data["certs"][i][0]].pos, accounts[data["certs"][i][1]].pos], {color:'black', weight:1, opacity:0.3}).addTo(map);
if(data["certs"][i][0] in accounts && data["certs"][i][1] in accounts && data["certs"][i][3] == 0) {
var line = L.polyline([accounts[data["certs"][i][0]].pos, accounts[data["certs"][i][1]].pos], {color:'black', weight:1, opacity:0.3}).addTo(map);
line.bindPopup("<b>"+accounts[data["certs"][i][0]].title+"</b> &rarr; <b>"+accounts[data["certs"][i][1]].title+"</b>");
certs.push(new Cert(data["certs"][i][0], data["certs"][i][1], line));
accounts[data["certs"][i][0]].certsIssued.push(ncerts);
accounts[data["certs"][i][1]].certsReceived.push(ncerts);
ncerts ++;
}
}
});
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment