people.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806
  1. // Raccatto i parametri dall'URL -- mi aspetto un parametro di nome 'link'!
  2. thisUrlParams = {};
  3. window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
  4. thisUrlParams[key] = value;
  5. });
  6. console.log('URL get params: ', thisUrlParams);
  7. // Funzioni per eseguire le queries
  8. function prepareQueryURL(query){
  9. sparqlEndpoint = 'http://dev.restore.ovi.cnr.it:8890/sparql/';
  10. sparqlUrlParams = '?default-graph-uri=&query=' + encodeURIComponent(query) + '&output=json&callback=?';
  11. return sparqlEndpoint + sparqlUrlParams;
  12. }
  13. function doJsonQuery(query){
  14. queryURL = prepareQueryURL(query);
  15. response = $.ajax({//OGGETTO
  16. url: queryURL,
  17. dataType: "json",
  18. success: function (data){},
  19. error: function (e) {}
  20. });
  21. return response;
  22. }
  23. // Funzioni per raccattare + stringhificare l'output
  24. queryStringOutput = "";
  25. function stringifyResponse(val){
  26. resultArray = val['results']['bindings'];
  27. out = "";
  28. for(i = 0; i < resultArray.length; i++){
  29. out = out + JSON.stringify(resultArray[i])
  30. }
  31. queryStringOutput = (queryStringOutput + out).replace("}{",",");
  32. }
  33. prefixes = "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \
  34. PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \
  35. PREFIX crm: <http://www.cidoc-crm.org/cidoc-crm/> \
  36. PREFIX owl: <http://www.w3.org/2002/07/owl#> \
  37. PREFIX schema: <http://schema.org/> \
  38. PREFIX foaf: <http://xmlns.com/foaf/0.1/> \
  39. PREFIX person: <http://www.w3.org/ns/person#>"
  40. query = prefixes + " SELECT DISTINCT ?place ?label ?coordinates \
  41. WHERE { \
  42. {?pc crm:P02_has_range <" + thisUrlParams.link + "> . \
  43. ?event_from crm:P01_has_domain ?pc ; \
  44. rdf:type crm:EL3_Receive_Letter; \
  45. crm:P26_moved_to ?place_from . \
  46. ?place_from rdf:type crm:E53_Place ; \
  47. owl:sameAs ?place . \
  48. ?place rdfs:label ?label ; \
  49. crm:P168_place_is_defined_by ?coordinates . \
  50. } UNION { \
  51. ?pc crm:P02_has_range <" + thisUrlParams.link + "> . \
  52. ?event_from crm:P01_has_domain ?pc ; \
  53. rdf:type crm:EL2_Send_Letter; \
  54. crm:P27_moved_from ?place_from . \
  55. ?place_from rdf:type crm:E53_Place ; \
  56. owl:sameAs ?place . \
  57. ?place rdfs:label ?label ; \
  58. crm:P168_place_is_defined_by ?coordinates . \
  59. } \
  60. }"
  61. queryInfo = prefixes + " SELECT DISTINCT ?graph ?label ?identifier ?name ?givenName ?familyName ?alias (GROUP_CONCAT(DISTINCT CONCAT(?variant, '| ', ?otherName) ; SEPARATOR = ';') AS ?variants) ?gender ?Birth_Date ?Birth_Place ?Death_Date ?Death_Place ?patronymic ?occupation (group_concat(distinct ?relative1 ;separator=', ') as ?relatives) ?qualification ?group \
  62. WHERE { \
  63. VALUES ?uri {<" + thisUrlParams.link + ">} \
  64. GRAPH ?graph {?uri rdfs:label ?label} \
  65. ?uri foaf:name ?name . \
  66. OPTIONAL {?uri crm:P1_is_identified_by ?id . \
  67. ?id rdfs:label ?identifier } \
  68. OPTIONAL {?uri foaf:givenName ?givenName} \
  69. OPTIONAL {?uri foaf:familyName ?familyName} \
  70. OPTIONAL {?uri foaf:gender ?gender} \
  71. OPTIONAL {?uri person:patronymicName ?patronymic } \
  72. OPTIONAL {?uri schema:hasOccupation ?uriOccupation . \
  73. ?uriOccupation rdf:type schema:Occupation; \
  74. rdfs:label ?occupation } \
  75. OPTIONAL {?uri schema:honorificPrefix ?qualification} \
  76. OPTIONAL {?uri schema:relatedTo ?uriRel1 . \
  77. ?uriRel1 rdfs:label ?relative1} \
  78. OPTIONAL {?uri crm:P100i_died_in ?Death . \
  79. ?Death crm:P4_has_time-span ?Death_TS; \
  80. crm:P7_took_place_at ?Place_D .\
  81. ?Death_TS rdfs:label ?Death_Date . \
  82. ?Place_D rdfs:label ?Death_Place } \
  83. OPTIONAL {?uri crm:P98i_was_born ?Birth . \
  84. ?Birth crm:P4_has_time-span ?Birth_TS; \
  85. crm:P7_took_place_at ?Place_B . \
  86. ?Birth_TS rdfs:label ?Birth_Date . \
  87. ?Place_B rdfs:label ?Birth_Place } \
  88. OPTIONAL {?uri crm:P107i_is_current_or_former_member_of ?uriGroup . \
  89. ?uriGroup rdfs:label ?group } \
  90. OPTIONAL {?uri schema:alternateName ?alias . } \
  91. OPTIONAL {?uri owl:sameAs ?variant . \
  92. ?variant foaf:name ?otherName . } \
  93. } \
  94. GROUP BY ?graph ?label ?identifier ?name ?givenName ?familyName ?alias ?gender ?Birth_Date ?Birth_Place ?Death_Date ?Death_Place ?patronymic ?occupation ?qualification ?group \
  95. LIMIT 1 "
  96. queryLetters = prefixes + " SELECT DISTINCT ?type ?segnatura ?document_uri ?document_name ?time_span ?InfObj \
  97. WHERE {?pc crm:P02_has_range <" + thisUrlParams.link + "> . \
  98. ?ev_move crm:P01_has_domain ?pc ; \
  99. rdfs:label ?type ; \
  100. rdfs:subClassOf ?event . \
  101. ?document_uri crm:P25i_moved_by ?event ; \
  102. rdfs:label ?document_name . \
  103. ?document_uri crm:P1_is_identified_by ?uriSegnatura . \
  104. ?uriSegnatura crm:P2_has_type 'Segnatura' ; \
  105. rdfs:label ?segnatura . \
  106. OPTIONAL {GRAPH <http://dev.restore.ovi.cnr.it:8890/ovi/datini> {?document_uri crm:P128_carries ?InfObj . \
  107. ?InfObj rdf:type crm:E73_Information_Object} }. \
  108. OPTIONAL {?ev_move crm:P4_has_time-span ?uri_ts . \
  109. ?uri_ts rdfs:label ?time_span . } \
  110. }"
  111. queryNetwork = prefixes + " SELECT DISTINCT COUNT(?event) AS ?count ?uri2 SAMPLE(?label2) AS ?text \
  112. WHERE { \
  113. {?event rdf:type crm:EL1_Exchange_Letters . \
  114. ?event_to rdfs:subClassOf ?event; \
  115. rdf:type crm:EL2_Send_Letter ; \
  116. crm:P01_has_domain ?pc_to . \
  117. ?pc_to crm:P02_has_range ?uri . \
  118. ?uri rdfs:label ?label . \
  119. ?event_from rdfs:subClassOf ?event; \
  120. rdf:type crm:EL3_Receive_Letter; \
  121. crm:P01_has_domain ?pc_from . \
  122. ?pc_from crm:P02_has_range ?uri2 . \
  123. ?uri2 rdfs:label ?label2 . \
  124. FILTER (?uri = <" + thisUrlParams.link + ">) \
  125. } UNION { \
  126. ?event rdf:type crm:EL1_Exchange_Letters . \
  127. ?event_to rdfs:subClassOf ?event; \
  128. rdf:type crm:EL3_Receive_Letter ; \
  129. crm:P01_has_domain ?pc_from . \
  130. ?pc_from crm:P02_has_range ?uri . \
  131. ?uri rdfs:label ?label . \
  132. ?event_from rdfs:subClassOf ?event; \
  133. rdf:type crm:EL2_Send_Letter; \
  134. crm:P01_has_domain ?pc_to . \
  135. ?pc_to crm:P02_has_range ?uri2 . \
  136. ?uri2 rdfs:label ?label2 . \
  137. FILTER (?uri = <" + thisUrlParams.link + ">) \
  138. } \
  139. } ORDER BY DESC (?count)"
  140. queryURL = prepareQueryURL(query);
  141. queryNet = prepareQueryURL(queryNetwork);
  142. query = prepareQueryURL(queryInfo);
  143. queryEx = prepareQueryURL(queryLetters);
  144. response = $.ajax({
  145. url: query,
  146. dataType: "json",
  147. success: function (data){
  148. handle_data(data);
  149. },
  150. error: function (e) {}
  151. });
  152. response = $.ajax({
  153. url: queryURL,
  154. dataType: "json",
  155. success: function (data){
  156. handle_map(data);
  157. },
  158. error: function (e) {}
  159. });
  160. responseNet = $.ajax({
  161. url: queryNet,
  162. dataType: "json",
  163. success: function (data){
  164. handle_network(data);
  165. },
  166. error: function (e) {}
  167. });
  168. responseLet = $.ajax({
  169. url: queryEx,
  170. dataType: "json",
  171. success: function (data){
  172. handle_Letters(data);
  173. },
  174. error: function (e) {}
  175. });
  176. function handle_data(json) {
  177. console.log(json['results']['bindings']);
  178. var graph = "";
  179. var label = "";
  180. if ("givenName" in json.results.bindings) {
  181. givenName = value['givenName']['value'];
  182. }
  183. $.each(
  184. json['results']['bindings'],
  185. function (index, value) {
  186. var graph = value['graph']['value'];
  187. var label = value['label']['value'];
  188. var name = value['name']['value'];
  189. var givenName = "";
  190. var familyName = "";
  191. var alias = "";
  192. var gender = "";
  193. var patronymic = "";
  194. var occupation = "";
  195. var relative = "";
  196. var identifier = "";
  197. var birth_date = "";
  198. var birth_place = "";
  199. var death_date = "";
  200. var death_place = "";
  201. var qualification = "";
  202. var group = "";
  203. var variants = "";
  204. if (value.hasOwnProperty('givenName')) {
  205. $("#givenName").css("display", "flex");
  206. givenName = value['givenName']['value'];
  207. }
  208. if (value.hasOwnProperty('familyName')) {
  209. $("#familyName").css("display", "flex");
  210. familyName = value['familyName']['value'].toLowerCase();
  211. familyName = familyName.charAt(0).toUpperCase() + familyName.slice(1)
  212. }
  213. if (value.hasOwnProperty('alias')) {
  214. $("#aliasName").css("display", "flex");
  215. alias = value['alias']['value'];
  216. }
  217. if (value.hasOwnProperty('gender')) {
  218. $("#gender").css("display", "flex");
  219. gender = value['gender']['value'];
  220. }
  221. if (value.hasOwnProperty('patronymic')) {
  222. $("#patronymic").css("display", "flex");
  223. patronymic = value['patronymic']['value'];
  224. }
  225. if (value.hasOwnProperty('occupation')) {
  226. $("#occupation").css("display", "flex");
  227. occupation = value['occupation']['value'];
  228. }
  229. if (value.hasOwnProperty('relatives')) {
  230. if (value['relatives']['value'] != "") {
  231. relative = value['relatives']['value'];
  232. }
  233. }
  234. if (value.hasOwnProperty('qualification')) {
  235. $("#honorific").css("display", "flex");
  236. qualification = value['qualification']['value'];
  237. }
  238. if (value.hasOwnProperty('Birth_Date')) {
  239. $("#BirthDate").css("display", "flex");
  240. birth_date = value['Birth_Date']['value'];
  241. }
  242. if (value.hasOwnProperty('Birth_Place')) {
  243. $("#BirthPlace").css("display", "flex");
  244. birth_place = value['Birth_Place']['value'];
  245. }
  246. if (value.hasOwnProperty('Death_Date')) {
  247. $("#DeathDate").css("display", "flex");
  248. death_date = value['Death_Date']['value'];
  249. }
  250. if (value.hasOwnProperty('Death_Place')) {
  251. $("#DeathPlace").css("display", "flex");
  252. death_place = value['Death_Place']['value'];
  253. }
  254. if (value.hasOwnProperty('group')) {
  255. $("#groups").css("display", "flex");
  256. group = value['group']['value'];
  257. }
  258. if (value.hasOwnProperty('variants')) {
  259. $("#otherNames").css("display", "flex");
  260. let strings = value['variants']['value'];
  261. variants = strings.split(";");
  262. }
  263. var dataset = get_dataset_name(graph);
  264. var second_name = patronymic + " " + relative;
  265. var first_name = "";
  266. if ((givenName != "") || (second_name != " ") || (familyName != "")) {
  267. first_name = givenName + " " + second_name + " " + familyName;
  268. } else {
  269. first_name = name;
  270. }
  271. var name_string = "";
  272. if (variants.length>0) {
  273. for (var i=0; i<variants.length; i++) {
  274. let chunk = variants[i].split("| ");
  275. name_string = name_string + "<a href='" + chunk[0] + "'>" + chunk[1] + "</a><br />";
  276. }
  277. }
  278. console.log(variants);
  279. /*for (var i=0; i<l; i++) {
  280. names_string = names_string + "<a href='" + variants[i][0] + "'>" + variants[i][1] + "</a>";
  281. }*/
  282. document.getElementById("grafo").innerHTML = dataset;
  283. document.getElementById("nome_persona").innerHTML = first_name;
  284. document.getElementById("nome").innerHTML = name;
  285. document.getElementById("genere").innerHTML = gender;
  286. document.getElementById("nome_proprio").innerHTML = givenName;
  287. document.getElementById("nome_famiglia").innerHTML = familyName;
  288. document.getElementById("alias").innerHTML = alias;
  289. document.getElementById("variants").innerHTML = name_string;
  290. document.getElementById("patronimico").innerHTML = second_name;
  291. document.getElementById("qualifica").innerHTML = qualification;
  292. document.getElementById("occupazione").innerHTML = occupation;
  293. document.getElementById("data_nascita").innerHTML = birth_date;
  294. document.getElementById("data_morte").innerHTML = death_date;
  295. document.getElementById("luogo_nascita").innerHTML = birth_place;
  296. document.getElementById("luogo_morte").innerHTML = death_place;
  297. document.getElementById("gruppi_appartenenza").innerHTML = group;
  298. const collection = document.getElementsByClassName("PN");
  299. for (var i=0; i<collection.length; i++) {
  300. collection[i].innerHTML = first_name;
  301. }
  302. });
  303. }
  304. function get_dataset_name(graph) {
  305. var string = "Scheda Onomastica";
  306. if (graph == "http://dev.restore.ovi.cnr.it:8890/aspo/onomastica") {
  307. string = string + " / Onomastica Datini";
  308. }
  309. else if (graph == "http://dev.restore.ovi.cnr.it:8890/mpp/authors"){
  310. string = string + " / Artisti";
  311. }
  312. else {
  313. string = string;
  314. }
  315. return (string);
  316. }
  317. function handle_Letters(json) {
  318. console.log(json);
  319. const send = [];
  320. const receive = [];
  321. var i=0;
  322. var j=0;
  323. $.each(
  324. json['results']['bindings'],
  325. function (index, value) {
  326. type = value['type']['value'];
  327. uri = value['document_uri']['value'];
  328. title = value['document_name']['value'];
  329. segnatura = value['segnatura']['value'];
  330. var data = "";
  331. var InfObj = "";
  332. if (value.hasOwnProperty('time_span')) {
  333. data = value['time_span']['value'];
  334. }
  335. if (value.hasOwnProperty('InfObj')) {
  336. InfObj = value['InfObj']['value'];
  337. }
  338. if (type == "Invio") {
  339. send.push([uri, title, segnatura, data, InfObj]);
  340. i++;
  341. } else {
  342. receive.push([uri, title, segnatura, data, InfObj]);
  343. j++;
  344. }
  345. });
  346. var Send_Letters = "";
  347. var Receive_Letters = "";
  348. //POPULATE SEND LETTERS BOX
  349. for (var i=0; i<send.length; i++) {
  350. var letter = '<a href=' + send[i][0] + ' target="_blank">' + send[i][1] + '</a>';
  351. var infObject_button = "";
  352. if (send[i][2] != "") {
  353. letter = letter + "<br />Segnatura: " + send[i][2];
  354. }
  355. if (send[i][3] != "") {
  356. letter = letter + "<br />Data invio: " + send[i][3];
  357. }
  358. if (send[i][4] != "") {
  359. infObject_button += '<button type="button" id="' + send[i][4] +
  360. '" class="lettera btn btn-default" alt="lettera" ><i class="fa fa-envelope"></i><p class="btn-text">Scheda Lettera</p></button>';
  361. } else {
  362. infObject_button += '<button type="button" id="' + send[i][0] +
  363. '" class="object btn btn-default" alt="oggetto" title="' + send[i][1] +
  364. '"><i class="fa fa-book"></i><p class="btn-text">Scheda Oggetto</p></button>';
  365. }
  366. Send_Letters += '<div class="row res"><div class="col-8"><p>'+ letter +'</p></div>' +
  367. '<div class="col d-flex align-items-start justify-content-end">' + infObject_button +
  368. '<button type="button" id="' + send[i][0] + '" class="cit btn btn-default" alt="scheda" title="Info"><i class="fa fa-quote-right"></i><p class="btn-text">Citazione</p></button>' +
  369. '<button type="button" id="' + send[i][0] + '" class="hyp btn btn-default" alt="scheda" title="Info"><i class="fa fa-link"></i><p class="btn-text">Hyperlink</p></button>' +
  370. '<a href="http://dev.restore.ovi.cnr.it/lodlive/?' + send[i][0] + '" target="_blank"><button type="button" class="btn btn-default info" alt="LOD"><i class="fa fa-share-alt"></i><p class="btn-text">Lod</p></button></a></div></div>';
  371. }
  372. //POPULATE RECEIVE LETTERS BOX
  373. for (var i=0; i<receive.length; i++) {
  374. var letter = '<a href=' + receive[i][0] + ' target="_blank">' + receive[i][1] + '</a>';
  375. var infObject_button = "";
  376. if (receive[i][2] != "") {
  377. letter = letter + "<br />Segnatura: " + receive[i][2];
  378. }
  379. if (receive[i][3] != "") {
  380. letter = letter + "<br />Data ricezione: " + receive[i][3];
  381. }
  382. if (receive[i][4] != "") {
  383. infObject_button += '<button type="button" id="' + receive[i][4] +
  384. '" class="lettera btn btn-default" alt="lettera" ><i class="fa fa-envelope"></i><p class="btn-text">Scheda Lettera</p></button>';
  385. } else {
  386. infObject_button += '<button type="button" id="' + receive[i][0] +
  387. '" class="object btn btn-default" alt="oggetto" title="' + receive[i][1] +
  388. '"><i class="fa fa-book"></i><p class="btn-text">Scheda Oggetto</p></button>';
  389. }
  390. Receive_Letters += '<div class="row res"><div class="col-8"><p>'+ letter +'</p></div>' +
  391. '<div class="col d-flex align-items-start justify-content-end">' + infObject_button +
  392. '<button type="button" id="' + receive[i][0] + '" class="cit btn btn-default" alt="scheda" title="Info"><i class="fa fa-quote-right"></i><p class="btn-text">Citazione</p></button>' +
  393. '<button type="button" id="' + receive[i][0] + '" class="hyp btn btn-default" alt="scheda" title="Info"><i class="fa fa-link"></i><p class="btn-text">Hyperlink</p></button>' +
  394. '<a href="http://dev.restore.ovi.cnr.it/lodlive/?' + receive[i][0] + '" target="_blank"><button type="button" class="btn btn-default info" alt="LOD"><i class="fa fa-share-alt"></i><p class="btn-text">Lod</p></button></a></div></div>';
  395. }
  396. document.getElementById("l_send").innerHTML = send.length;
  397. document.getElementById("l_receive").innerHTML = receive.length;
  398. document.getElementById("letters_send").innerHTML = Send_Letters;
  399. document.getElementById("letters_receive").innerHTML = Receive_Letters;
  400. if (i==0) {
  401. var messaggio = "<p class='no-results'>Nessun risultato trovato</p>";
  402. document.getElementById("letters_send").innerHTML = messaggio;
  403. }
  404. if (j==0) {
  405. var messaggio = "<p class='no-results'>Nessun risultato trovato</p>";
  406. document.getElementById("letters_receive").innerHTML = messaggio;
  407. }
  408. }
  409. function handle_map(json) {
  410. console.log(json);
  411. const locations = [];
  412. const place_names = [];
  413. var lat = 0;
  414. var long = 0;
  415. var i=0;
  416. var myPlaces = "";
  417. $.each(
  418. json['results']['bindings'],
  419. function (index, value) {
  420. const loc = []
  421. var uri = value['place']['value'];
  422. var label = value['label']['value'];
  423. var coord = value['coordinates']['value'];
  424. const coordinates = coord.split(", ");
  425. loc.push(label);
  426. myPlaces += "<div class='item-place-person'><div class='clickPlace item-place-person-label' data-point='"+ coordinates + "'>" + label + "</div><div class='item-place-person-action'><div class='luogo' id='" +
  427. uri + "'><i class='far fa-map' style='cursor:pointer'></i></div></div></div>";
  428. loc.push(coordinates[0]);
  429. lat += parseInt(coordinates[0]);
  430. loc.push(coordinates[1]);
  431. long += parseInt(coordinates[1].replace(/^(\.)/,"0.").replace("-.", "-0."));
  432. locations.push(loc);
  433. i++;
  434. });
  435. var latitude = lat/i;
  436. var longitude = long/i;
  437. document.getElementById("list_places_person").innerHTML = myPlaces;
  438. var cloudmadeUrl = 'http://{s}.tile.cloudmade.com/BC9A493B41014CAABB98F0471D759707/997/256/{z}/{x}/{y}.png',
  439. cloudmadeAttribution = 'Map data &copy; 2011 OpenStreetMap contributors, Imagery &copy; 2011 CloudMade, Points &copy 2012 LINZ',
  440. cloudmade = new L.TileLayer(cloudmadeUrl, {maxZoom: 17, attribution: cloudmadeAttribution}),
  441. latlng = new L.LatLng(latitude, longitude);
  442. var map = new L.Map('map', {center: latlng, zoom: 5, layers: [cloudmade]});
  443. mapLink = '<a href="https://openstreetmap.org">OpenStreetMap</a>';
  444. var markers = new L.MarkerClusterGroup();
  445. var markerList = [];
  446. var geo = new L.tileLayer(
  447. 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
  448. attribution: '&copy; ' + mapLink + ' Contributors',
  449. maxZoom: 18,
  450. }).addTo(map);
  451. function populate() {
  452. for (var i = 0; i < locations.length; i++) {
  453. var a = locations[i];
  454. var title = a[0];
  455. var marker = new L.Marker(new L.LatLng(a[1], a[2]), { title: title });
  456. marker.bindPopup(title);
  457. markers.addLayer(marker);
  458. markerList.push(marker);
  459. }
  460. }
  461. populate();
  462. map.addLayer(markers);
  463. $('.clickPlace').on('click', function(){
  464. // parse lat and lng from the divs data attribute
  465. var latlng = $(this).data().point.split(',');
  466. var lat = latlng[0];
  467. var lng = latlng[1];
  468. var zoom = 10;
  469. // set the view
  470. map.setView([lat, lng], zoom);
  471. });
  472. }
  473. function handle_network(json) {
  474. console.log(json);
  475. const words = [];
  476. const tempArray = [];
  477. var listwords = "";
  478. var ArrayNames = "";
  479. var temp = 0;
  480. var sum = 0;
  481. var i=0;
  482. var j=0;
  483. $.each(
  484. json['results']['bindings'],
  485. function (index, value) {
  486. text = value['text']['value'];
  487. link = value['uri2']['value'];
  488. num = parseInt(value['count']['value']);
  489. /*count = 0;
  490. if ((num - temp) > 50) {
  491. count = temp + 12;
  492. } else {
  493. count = num;
  494. }
  495. words.push([text, count]);
  496. temp = count;
  497. sum += temp;*/
  498. tempArray.push([text, num]);
  499. ArrayNames += "<div class='item-place-person'><div class='item-place-person-label'>" +
  500. text + "<br /><span class='num_occ'>[Co-occorrenze: " + num + "]</span></div><div class='item-place-person-action'><div class='persona' id='" +
  501. link + "'><i class='fa fa-user' style='cursor:pointer'></i></div></div></div></div>";
  502. });
  503. if (tempArray.length < 8) {
  504. for (var k=0; k<tempArray.length; k++) {
  505. text = tempArray[k][0];
  506. count = tempArray[k][1] + 36;
  507. words.push([text, count]);
  508. }
  509. } else {
  510. for (var k=tempArray.length-1; k>=0; k--) {
  511. text = tempArray[k][0];
  512. num = tempArray[k][1];
  513. count = 0;
  514. if ((num - temp) > 50) {
  515. count = temp + 12;
  516. } else {
  517. count = num;
  518. }
  519. words.push([text, count]);
  520. temp = count;
  521. sum += temp;
  522. }
  523. }
  524. document.getElementById("list_person_network").innerHTML = ArrayNames;
  525. /*var tot = parseInt(words[0][1]);*/
  526. for (var i in words) {
  527. var text = words[i][0]
  528. var count = words[i][1];
  529. listwords += '{ "word": \"' + text + '\", "size": \"' + count + '\"},';
  530. }
  531. let listL = ('[' + listwords + ']').replace(',]', ']');
  532. const links = JSON.parse(listL);
  533. console.log(links);
  534. // List of words
  535. var myWords = links;
  536. // set the dimensions and margins of the graph
  537. var margin = {top: 10, right: 10, bottom: 10, left: 10},
  538. width = 850 - margin.left - margin.right,
  539. height = 500 - margin.top - margin.bottom;
  540. // append the svg object to the body of the page
  541. var svg = d3.select("#myWordCloud").append("svg")
  542. .attr("width", width + margin.left + margin.right)
  543. .attr("height", height + margin.top + margin.bottom)
  544. .append("g")
  545. .attr("transform",
  546. "translate(" + (width/2-50) + "," + (height/2+20) + ")");
  547. // Constructs a new cloud layout instance. It run an algorithm to find the position of words that suits your requirements
  548. // Wordcloud features that are different from one word to the other must be here
  549. var layout = d3.layout.cloud()
  550. .size([width, height])
  551. .words(myWords.map(function(d) { return {text: d.word, size:d.size/2}; }))
  552. .padding(5) //space between words
  553. .rotate(function() { return ~~(Math.random() * 2);})
  554. .fontSize(function(d) { return d.size + 6; }) // font size of words
  555. .on("end", draw);
  556. layout.start();
  557. // This function takes the output of 'layout' above and draw the words
  558. // Wordcloud features that are THE SAME from one word to the other can be here
  559. function draw(words) {
  560. var cloud = svg.selectAll("g text")
  561. .data(words, function(d) { return d.text; })
  562. //Entering words
  563. cloud.enter()
  564. .append("text")
  565. .style("font-family", "Impact")
  566. .attr("text-anchor", "middle")
  567. .attr('font-size', 1)
  568. .text(function(d) { return d.text; });
  569. //Entering and existing words
  570. cloud
  571. .transition()
  572. .duration(600)
  573. .style("font-size", function(d) { return d.size + "px"; })
  574. .attr("transform", function(d) {
  575. return "translate(" + [d.x, d.y] + ")rotate(" + d.rotate + ")";
  576. })
  577. .style("fill-opacity", 1);
  578. //Exiting words
  579. cloud.exit()
  580. .transition()
  581. .duration(200)
  582. .style('fill-opacity', 1e-6)
  583. .attr('font-size', 1)
  584. .remove();
  585. }
  586. }
  587. $(document).on("click", ".luogo", function (ev) {
  588. var link = this.id;
  589. //alert(nome_autore);
  590. //$('#myModal').text("");
  591. window.open("Luogo.html?link="+this.id);
  592. });
  593. $(document).on("click", ".persona", function (ev) {
  594. var link = this.id;
  595. //alert(nome_autore);
  596. //$('#myModal').text("");
  597. window.open("Persona.html?link="+this.id);
  598. });
  599. $(document).on("click", ".lettera", function (ev) {
  600. var link = this.id;
  601. //alert(nome_autore);
  602. //$('#myModal').text("");
  603. window.open("lettera.html?link="+this.id);
  604. });
  605. $(document).on("click", ".object", function (ev) {
  606. var link = this.id;
  607. //alert(nome_autore);
  608. //$('#myModal').text("");
  609. window.open("object.html?link="+this.id);
  610. });
  611. $(document).on("click", ".hyp", function (ev) {
  612. var link = this.id;
  613. $("#myModal").empty();
  614. $("#myModal").css("display", "block");
  615. $('#myModal').append("<div class='modal-content'><div class='modal-close'><span class='close'>&times;</span></div><div id='myInput'>" +
  616. link + "</div><button id='copy_btn' class='btn btn-theme-primary btn-md' onclick='myFunction()'>Copia</button>");
  617. });
  618. $(document).on("click", ".close", function (ev) {
  619. var link = this.id;
  620. //alert(nome_autore);
  621. //$('#myModal').text("");
  622. $("#myModal").css("display", "none");
  623. });
  624. $(document).on("click", ".back", function (ev) {
  625. $("#myTab").css("display", "none");
  626. });
  627. $(document).on("click", ".cit", function (ev) {
  628. var author ="RESTORE. smart access to digital heritage and memory"
  629. var year = new Date().getFullYear()
  630. var today = new Date();
  631. var dd = String(today.getDate()).padStart(2, '0');
  632. var mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0!
  633. var yyyy = today.getFullYear();
  634. today = dd + '/' + mm + '/' + yyyy;
  635. var link = this.id;
  636. //alert(nome_autore);
  637. //$('#myModal').text("");
  638. $("#myModal").empty();
  639. $("#myModal").css("display", "block");
  640. $('#myModal').append("<div class='modal-content'><div class='modal-close'><span class='close'>&times;</span></div><div id='myInput'>" +
  641. author + " " + year + ", accesso effettuato: " + today + ", &lt;" + link + "&gt;</div><button id='copy_btn' class='btn btn-theme-primary btn-md' onclick='myFunction()'>Copia</button>");
  642. });
  643. function copyToClipboard(text) {
  644. var sampleTextarea = document.createElement("textarea");
  645. document.body.appendChild(sampleTextarea);
  646. sampleTextarea.value = text; //save main text in it
  647. sampleTextarea.select(); //select textarea contenrs
  648. document.execCommand("copy");
  649. document.body.removeChild(sampleTextarea);
  650. }
  651. function myFunction(){
  652. var copy = document.getElementById("myInput");
  653. copyText = copy.textContent;
  654. copyToClipboard(copyText);
  655. //copyToClipboard(copyText.value);
  656. }