map.js 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033
  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. query = prefixes + " SELECT DISTINCT ?graph ?uri ?name_place ?coordinates {\
  38. GRAPH ?graph { VALUES ?uri { <" + thisUrlParams.link + "> } \
  39. ?uri crm:P168_place_is_defined_by ?coordinates;\
  40. rdfs:label ?name_place .\
  41. }\
  42. }"
  43. queryRiferimenti = prefixes + " SELECT DISTINCT ?references {\
  44. <" + thisUrlParams.link + "> owl:sameAs ?references\
  45. }"
  46. queryToponimi = prefixes + " SELECT DISTINCT ?toponimi {\
  47. <" + thisUrlParams.link + "> crm:P1_is_identified_by ?uri_toponym .\
  48. ?uri_toponym rdfs:label ?toponimi\
  49. }"
  50. queryRicezione = prefixes + " SELECT DISTINCT ?segnatura ?document_uri ?document_name ?time_span ?InfObj \
  51. WHERE { \
  52. <" + thisUrlParams.link + "> owl:sameAs ?place . \
  53. ?event_to crm:P26_moved_to ?place ; \
  54. rdf:type crm:EL3_Receive_Letter ; \
  55. rdfs:subClassOf ?event . \
  56. ?document_uri crm:P25i_moved_by ?event ; \
  57. rdfs:label ?document_name . \
  58. ?document_uri crm:P1_is_identified_by ?uriSegnatura . \
  59. ?uriSegnatura crm:P2_has_type 'Segnatura' ; \
  60. rdfs:label ?segnatura . \
  61. OPTIONAL {GRAPH <http://dev.restore.ovi.cnr.it:8890/ovi/datini> {?document_uri crm:P128_carries ?InfObj . \
  62. ?InfObj rdf:type crm:E73_Information_Object} }. \
  63. OPTIONAL {?event_to crm:P4_has_time-span ?uri_ts . \
  64. ?uri_ts rdfs:label ?time_span . } \
  65. } "
  66. queryInvio = prefixes + " SELECT DISTINCT ?segnatura ?document_uri ?document_name ?time_span ?InfObj \
  67. WHERE { \
  68. <" + thisUrlParams.link + "> owl:sameAs ?place . \
  69. ?event_to crm:P27_moved_from ?place ; \
  70. rdf:type crm:EL2_Send_Letter ; \
  71. rdfs:subClassOf ?event . \
  72. ?document_uri crm:P25i_moved_by ?event ; \
  73. rdfs:label ?document_name . \
  74. ?document_uri crm:P1_is_identified_by ?uriSegnatura . \
  75. ?uriSegnatura crm:P2_has_type 'Segnatura' ; \
  76. rdfs:label ?segnatura . \
  77. OPTIONAL {GRAPH <http://dev.restore.ovi.cnr.it:8890/ovi/datini> {?document_uri crm:P128_carries ?InfObj . \
  78. ?InfObj rdf:type crm:E73_Information_Object} }. \
  79. OPTIONAL {?event_to crm:P4_has_time-span ?uri_ts . \
  80. ?uri_ts rdfs:label ?time_span . } \
  81. }"
  82. queryCitazione = prefixes + " SELECT DISTINCT ?segnatura ?document_uri ?document_name SAMPLE(?time_span) AS ?time_span ?InfObj \
  83. WHERE { \
  84. <" + thisUrlParams.link + "> crm:P1_is_identified_by ?toponym . \
  85. ?InfObj crm:P67_refers_to ?toponym . \
  86. ?document_uri crm:P128_carries ?InfObj ; \
  87. rdfs:label ?document_name . \
  88. OPTIONAL {?document_uri crm:P1_is_identified_by ?uriSegnatura . \
  89. ?uriSegnatura crm:P2_has_type 'Segnatura' ; \
  90. rdfs:label ?segnatura . } \
  91. OPTIONAL {?document_uri crm:P25i_moved_by ?event . \
  92. ?event_send rdfs:subClassOf ?event ; \
  93. rdf:type crm:EL2_Send_Letter ; \
  94. crm:P4_has_time-span ?uri_ts . \
  95. ?uri_ts rdfs:label ?time_span . } \
  96. } "
  97. queryPersone = prefixes + " SELECT DISTINCT ?role ?range SAMPLE(?name) AS ?label COUNT(?range) AS ?count \
  98. WHERE{ \
  99. {?place owl:sameAs <" + thisUrlParams.link + "> . \
  100. ?event_to crm:P26_moved_to ?place ; \
  101. rdf:type crm:EL3_Receive_Letter ; \
  102. crm:P01_has_domain ?domain . \
  103. ?domain crm:P02_has_range ?range ; \
  104. crm:P14.1_in_the_role_of ?uri_role . \
  105. ?uri_role rdfs:label ?role . \
  106. ?range rdfs:label ?lb ; \
  107. foaf:name ?name . \
  108. } UNION { \
  109. ?place owl:sameAs <" + thisUrlParams.link + "> . \
  110. ?event_to crm:P27_moved_from ?place ; \
  111. rdf:type crm:EL2_Send_Letter ; \
  112. crm:P01_has_domain ?domain . \
  113. ?domain crm:P02_has_range ?range ; \
  114. crm:P14.1_in_the_role_of ?uri_role . \
  115. ?uri_role rdfs:label ?role . \
  116. ?range rdfs:label ?lb ; \
  117. foaf:name ?name . \
  118. } \
  119. } GROUP BY ?role ?range \
  120. ORDER BY ?label"
  121. queryCount = prefixes + " SELECT ?place ?label COUNT(?label) AS ?Count \
  122. WHERE{ \
  123. ?place_to owl:sameAs <" + thisUrlParams.link + "> . \
  124. ?event_to crm:P26_moved_to ?place_to ; \
  125. rdf:type crm:EL3_Receive_Letter ; \
  126. rdfs:subClassOf ?event . \
  127. ?event_from rdfs:subClassOf ?event ; \
  128. rdf:type crm:EL2_Send_Letter ; \
  129. crm:P27_moved_from ?place . \
  130. ?place rdfs:label ?label \
  131. } \
  132. ORDER BY DESC (?Count)"
  133. queryCount2 = prefixes + " SELECT ?place ?label COUNT(?label) AS ?Count \
  134. WHERE{ \
  135. ?place_from owl:sameAs <" + thisUrlParams.link + "> . \
  136. ?event_from crm:P27_moved_from ?place_from ; \
  137. rdf:type crm:EL2_Send_Letter ; \
  138. rdfs:subClassOf ?event . \
  139. ?event_to rdfs:subClassOf ?event ; \
  140. rdf:type crm:EL2_Send_Letter ; \
  141. crm:P27_moved_from ?place . \
  142. ?place rdfs:label ?label . \
  143. } \
  144. ORDER BY DESC (?Count) "
  145. queryURL = prepareQueryURL(query);
  146. queryRef = prepareQueryURL(queryRiferimenti);
  147. queryTopo = prepareQueryURL(queryToponimi);
  148. queryRec = prepareQueryURL(queryRicezione);
  149. querySend = prepareQueryURL(queryInvio);
  150. queryCit = prepareQueryURL(queryCitazione);
  151. queryPer = prepareQueryURL(queryPersone);
  152. queryCon1 = prepareQueryURL(queryCount);
  153. queryCon2 = prepareQueryURL(queryCount2);
  154. response = $.ajax({//OGGETTO
  155. url: queryURL,
  156. dataType: "json",
  157. success: function (data){
  158. handle_data(data);
  159. },
  160. error: function (e) {}
  161. });
  162. response_ref = $.ajax({//OGGETTO
  163. url: queryRef,
  164. dataType: "json",
  165. success: function (data){
  166. handle_ref(data);
  167. },
  168. error: function (e) {}
  169. });
  170. response_top = $.ajax({//OGGETTO
  171. url: queryTopo,
  172. dataType: "json",
  173. success: function (data){
  174. handle_toponym(data);
  175. },
  176. error: function (e) {}
  177. });
  178. response_receive = $.ajax({//OGGETTO
  179. url: queryRec,
  180. dataType: "json",
  181. success: function (data){
  182. handle_receive(data);
  183. },
  184. error: function (e) {}
  185. });
  186. response_send = $.ajax({//OGGETTO
  187. url: querySend,
  188. dataType: "json",
  189. success: function (data){
  190. handle_send(data);
  191. },
  192. error: function (e) {}
  193. });
  194. response_cit = $.ajax({//OGGETTO
  195. url: queryCit,
  196. dataType: "json",
  197. success: function (data){
  198. handle_cit(data);
  199. },
  200. error: function (e) {}
  201. });
  202. response_per = $.ajax({//OGGETTO
  203. url: queryPer,
  204. dataType: "json",
  205. success: function (data){
  206. handle_persons(data);
  207. },
  208. error: function (e) {}
  209. });
  210. responseCountA = $.ajax({//OGGETTO
  211. url: queryCon1,
  212. dataType: "json",
  213. success: function (data){
  214. handle_count(data);
  215. },
  216. error: function (e) {}
  217. });
  218. responseCountP = $.ajax({//OGGETTO
  219. url: queryCon2,
  220. dataType: "json",
  221. success: function (data){
  222. handle_count2(data);
  223. },
  224. error: function (e) {}
  225. });
  226. function handle_data(json) {
  227. console.log(json);
  228. const locations = [];
  229. $.each(
  230. json['results']['bindings'],
  231. function (index, value) {
  232. const loc = []
  233. var graph = value['graph']['value'];
  234. var uri = value['uri']['value'];
  235. var label = value['name_place']['value'];
  236. var coord = value['coordinates']['value'];
  237. var variante = "";
  238. var note = "";
  239. const coordinates = coord.split(", ");
  240. loc.push(label);
  241. loc.push(coordinates[0]);
  242. loc.push(coordinates[1]);
  243. locations.push(loc);
  244. if (value.hasOwnProperty('variant')) {
  245. variante = value['variant']['value'];
  246. } else {
  247. variante = "Nessun risultato trovato";
  248. }
  249. if (value.hasOwnProperty('notes')) {
  250. note = value['notes']['value'];
  251. } else {
  252. note = "Nessuna informazione trovata";
  253. }
  254. var Buttons = '<button type="button" value="object" id="' + uri + '" class="cit btn btn-default" alt="scheda" title="Citazione"><i class="fa fa-quote-right"></i></button> \
  255. <button type="button" value="object" id="' + uri + '" class="hyp btn btn-default" alt="scheda" title="Hyperlink"><i class="fa fa-link"></i></button> \
  256. <a href="http://dev.restore.ovi.cnr.it/lodlive/?' + uri + '" target="_blank"><button type="button" class="btn btn-default info" alt="LOD" title="LodLive"><i class="fa fa-share-alt"></i></button></a></div></div>';
  257. document.getElementById("grafo").innerHTML = graph;
  258. document.getElementById("nome_luogo").innerHTML = label;
  259. document.getElementById("place_name").innerHTML = label;
  260. document.getElementById("coords").innerHTML = coord;
  261. document.getElementById("note").innerHTML = note;
  262. document.getElementById("variants").innerHTML = variante;
  263. document.getElementById("nome_lu").innerHTML = label;
  264. document.getElementById("nome_lp").innerHTML = label;
  265. document.getElementById("nome_ll").innerHTML = label;
  266. document.getElementById("nome_lg").innerHTML = label;
  267. document.getElementById("link_buttons").innerHTML = Buttons;
  268. });
  269. var map = L.map('map').setView([locations[0][1], locations[0][2]], 7);
  270. mapLink = '<a href="https://openstreetmap.org">OpenStreetMap</a>';
  271. L.tileLayer(
  272. 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
  273. attribution: '&copy; ' + mapLink + ' Contributors',
  274. maxZoom: 18,
  275. }).addTo(map);
  276. for (var i = 0; i < locations.length; i++) {
  277. marker = new L.marker([locations[i][1], locations[i][2]])
  278. .bindPopup(locations[i][0])
  279. .addTo(map);
  280. }
  281. }
  282. function handle_ref(json) {
  283. console.log(json);
  284. const references = [];
  285. var list_ref = "";
  286. $.each(
  287. json['results']['bindings'],
  288. function (index, value) {
  289. var ref = value['references']['value'];
  290. references.push(ref);
  291. });
  292. for (i=0; i<references.length; i++) {
  293. list_ref += "<a target='_blank' href='" + references[i] + "'>" + references[i] + "</a>";
  294. }
  295. document.getElementById("riferimenti").innerHTML = list_ref;
  296. }
  297. function handle_toponym(json) {
  298. console.log(json);
  299. const toponym = [];
  300. $.each(
  301. json['results']['bindings'],
  302. function (index, value) {
  303. var topo = value['toponimi']['value'];
  304. toponym.push(" " + topo);
  305. });
  306. document.getElementById("toponimi").innerHTML = toponym;
  307. }
  308. function handle_receive(json) {
  309. console.log(json);
  310. const received = [];
  311. var i=0;
  312. $.each(
  313. json['results']['bindings'],
  314. function (index, value) {
  315. uri = value['document_uri']['value'];
  316. title = value['document_name']['value'];
  317. segnatura = value['segnatura']['value'];
  318. var data = "";
  319. var InfObj = "";
  320. if (value.hasOwnProperty('time_span')) {
  321. data = value['time_span']['value'];
  322. }
  323. if (value.hasOwnProperty('InfObj')) {
  324. InfObj = value['InfObj']['value'];
  325. }
  326. received.push([uri, title, segnatura, data, InfObj]);
  327. });
  328. var myArray = "";
  329. for (var i=0; i<received.length; i++) {
  330. var letter = "";
  331. var infObject_button = "";
  332. var object_type = "";
  333. if (received[i][4] != "") {
  334. letter = '<div class="col-8"><p><span id="' + received[i][0] + '" class="title_doc lettera">'+ received[i][1] + '</span>';
  335. object_type = "lettera";
  336. infObject_button += '<button type="button" id="' + received[i][4] +
  337. '" class="lettera btn btn-default" alt="lettera" ><i class="fa fa-envelope"></i><p class="btn-text">Scheda Lettera</p></button>';
  338. } else {
  339. letter = '<div class="col-8"><p><span id="' + received[i][0] + '" class="title_doc object">'+ received[i][1] + '</span>';
  340. object_type = "object";
  341. infObject_button += '<button type="button" id="' + received[i][0] +
  342. '" class="object btn btn-default" alt="oggetto" title="' + received[i][1] +
  343. '"><i class="fa fa-book"></i><p class="btn-text">Scheda Oggetto</p></button>';
  344. }
  345. if (received[i][2] != "") {
  346. letter = letter + "<br />Segnatura: " + received[i][2];
  347. }
  348. if (received[i][3] != "") {
  349. letter = letter + "<br />Data: " + received[i][3];
  350. }
  351. letter = letter + '</p></div>';
  352. myArray += '<div class="row res">'+ letter +
  353. '<div class="col d-flex align-items-start justify-content-end">' + infObject_button +
  354. '<button value="' + object_type + '" type="button" id="' + received[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>' +
  355. '<button value="' + object_type + '" type="button" id="' + received[i][0] + '" class="hyp btn btn-default" alt="scheda" title="Info"><i class="fa fa-link"></i><p class="btn-text">Hyperlink</p></button>' +
  356. '<a href="http://dev.restore.ovi.cnr.it/lodlive/?' + received[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>';
  357. }
  358. document.getElementById("n_receive").innerHTML = received.length;
  359. document.getElementById("object_receive").innerHTML = myArray;
  360. if (received.length==0) {
  361. var messaggio = "<p class='no-results'>Nessun risultato trovato</p>";
  362. document.getElementById("object_receive").innerHTML = messaggio;
  363. }
  364. }
  365. function handle_send(json) {
  366. console.log(json);
  367. const sent = [];
  368. var i=0;
  369. $.each(
  370. json['results']['bindings'],
  371. function (index, value) {
  372. uri = value['document_uri']['value'];
  373. title = value['document_name']['value'];
  374. segnatura = value['segnatura']['value'];
  375. var data = "";
  376. var InfObj = "";
  377. if (value.hasOwnProperty('time_span')) {
  378. data = value['time_span']['value'];
  379. }
  380. if (value.hasOwnProperty('InfObj')) {
  381. InfObj = value['InfObj']['value'];
  382. }
  383. sent.push([uri, title, segnatura, data, InfObj]);
  384. });
  385. var myArray = "";
  386. for (var i=0; i<sent.length; i++) {
  387. var letter = "";
  388. var infObject_button = "";
  389. var object_type = "";
  390. if (sent[i][4] != "") {
  391. letter = '<div class="col-8"><p><span id="' + sent[i][0] + '" class="title_doc lettera">'+ sent[i][1] + '</span>';
  392. object_type = "lettera";
  393. infObject_button += '<button type="button" id="' + sent[i][4] +
  394. '" class="lettera btn btn-default" alt="lettera" ><i class="fa fa-envelope"></i><p class="btn-text">Scheda Lettera</p></button>';
  395. } else {
  396. letter = '<div class="col-8"><p><span id="' + sent[i][0] + '" class="title_doc object">'+ sent[i][1] + '</span>';
  397. object_type = "object";
  398. infObject_button += '<button type="button" id="' + sent[i][0] +
  399. '" class="object btn btn-default" alt="oggetto" title="' + sent[i][1] +
  400. '"><i class="fa fa-book"></i><p class="btn-text">Scheda Oggetto</p></button>';
  401. }
  402. if (sent[i][2] != "") {
  403. letter = letter + "<br />Segnatura: " + sent[i][2];
  404. }
  405. if (sent[i][3] != "") {
  406. letter = letter + "<br />Data: " + sent[i][3];
  407. }
  408. letter = letter + '</p></div>';
  409. myArray += '<div class="row res">'+ letter +
  410. '<div class="col d-flex align-items-start justify-content-end">' + infObject_button +
  411. '<button value="' + object_type + '" type="button" id="' + sent[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>' +
  412. '<button value="' + object_type + '" type="button" id="' + sent[i][0] + '" class="hyp btn btn-default" alt="scheda" title="Info"><i class="fa fa-link"></i><p class="btn-text">Hyperlink</p></button>' +
  413. '<a href="http://dev.restore.ovi.cnr.it/lodlive/?' + sent[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>';
  414. }
  415. document.getElementById("n_send").innerHTML = sent.length;
  416. document.getElementById("object_send").innerHTML = myArray;
  417. if (sent.length==0) {
  418. var messaggio = "<p class='no-results'>Nessun risultato trovato</p>";
  419. document.getElementById("object_send").innerHTML = messaggio;
  420. }
  421. }
  422. function handle_cit(json) {
  423. console.log(json);
  424. const citations = [];
  425. var i=0;
  426. $.each(
  427. json['results']['bindings'],
  428. function (index, value) {
  429. uri = value['document_uri']['value'];
  430. title = value['document_name']['value'];
  431. segnatura = value['segnatura']['value'];
  432. var data = "";
  433. var InfObj = "";
  434. if (value.hasOwnProperty('time_span')) {
  435. data = value['time_span']['value'];
  436. }
  437. if (value.hasOwnProperty('InfObj')) {
  438. InfObj = value['InfObj']['value'];
  439. }
  440. citations.push([uri, title, segnatura, data, InfObj]);
  441. });
  442. var myArray = "";
  443. for (var i=0; i<citations.length; i++) {
  444. var letter = "";
  445. var infObject_button = "";
  446. var object_type = "";
  447. if (citations[i][4] != "") {
  448. letter = '<div class="col-8"><p><span id="' + citations[i][0] + '" class="title_doc lettera">'+ citations[i][1] + '</span>';
  449. object_type = "lettera";
  450. infObject_button += '<button type="button" id="' + citations[i][4] +
  451. '" class="lettera btn btn-default" alt="lettera" ><i class="fa fa-envelope"></i><p class="btn-text">Scheda Lettera</p></button>';
  452. } else {
  453. letter = '<div class="col-8"><p><span id="' + citations[i][0] + '" class="title_doc object">'+ citations[i][1] + '</span>';
  454. object_type = "object";
  455. infObject_button += '<button type="button" id="' + citations[i][0] +
  456. '" class="object btn btn-default" alt="oggetto" title="' + citations[i][1] +
  457. '"><i class="fa fa-book"></i><p class="btn-text">Scheda Oggetto</p></button>';
  458. }
  459. if (citations[i][2] != "") {
  460. letter = letter + "<br />Segnatura: " + citations[i][2];
  461. }
  462. if (citations[i][3] != "") {
  463. letter = letter + "<br />Data: " + citations[i][3];
  464. }
  465. letter = letter + "</p></div>";
  466. myArray += '<div class="row res">'+ letter +
  467. '<div class="col d-flex align-items-start justify-content-end">' + infObject_button +
  468. '<button type="button" value="' + object_type + '" id="' + citations[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>' +
  469. '<button type="button" value="' + object_type + '" id="' + citations[i][0] + '" class="hyp btn btn-default" alt="scheda" title="Info"><i class="fa fa-link"></i><p class="btn-text">Hyperlink</p></button>' +
  470. '<a href="http://dev.restore.ovi.cnr.it/lodlive/?' + citations[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>';
  471. }
  472. document.getElementById("n_cit").innerHTML = citations.length;
  473. document.getElementById("object_cit").innerHTML = myArray;
  474. if (citations.length==0) {
  475. var messaggio = "<p class='no-results'>Nessun risultato trovato</p>";
  476. document.getElementById("object_cit").innerHTML = messaggio;
  477. }
  478. }
  479. function handle_persons(json) {
  480. console.log(json);
  481. const people = [];
  482. const person_names = [];
  483. const person_events = [];
  484. var Person = "";
  485. $.each(
  486. json['results']['bindings'],
  487. function (index, value) {
  488. var uri = value['range']['value'];
  489. var label = value['label']['value'];
  490. var ruolo = value['role']['value']
  491. var count = value['count']['value']
  492. var evento = ruolo + ": " + count
  493. person_events.push([uri, label, evento]);
  494. if (!person_names.includes(uri)) {
  495. person_names.push([uri, label]);
  496. }
  497. });
  498. for (var k=0; k<person_names.length; k++) {
  499. const tempArray = [];
  500. var uri = person_names[k][0];
  501. var nome = person_names[k][1]
  502. tempArray.push(uri);
  503. tempArray.push(nome);
  504. for (var y=0; y<person_events.length; y++) {
  505. var ev = person_events[y][2];
  506. if (person_names[k][0] == person_events[y][0]) {
  507. tempArray.push(ev);
  508. }
  509. }
  510. people.push(tempArray);
  511. }
  512. for (var i=0; i<people.length; i++) {
  513. var info = "";
  514. for (var h=2; h<people[i].length; h++) {
  515. info += people[i][h] + ' occorrenze<br />';
  516. }
  517. Person += '<div class="row res"><div class="col-8">' +
  518. '<p><span id="' + people[i][0] + '" class="title_doc persona">'+ people[i][1] + '</span><br />' + info + '</p></div>' +
  519. '<div class="col d-flex align-items-start justify-content-end"><button type="button" id="' + people[i][0] + '" class="persona btn btn-default" alt="persona" title="' +
  520. people[i][1] + '"><i class="fa fa-user"></i><p class="btn-text">Scheda Persona</p></button>' +
  521. '<button type="button" value="Persona" id="' + people[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>' +
  522. /*DA QUI HYPERLINK ->*/'<button type="button" value="Persona" id="' + people[i][0] + '" class="hyp btn btn-default" alt="scheda" title="Info"><i class="fa fa-link"></i><p class="btn-text">Hyperlink</p></button>' +
  523. /*DA QUI LOD ->*/'<a href="http://dev.restore.ovi.cnr.it/lodlive/?' + people[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>';
  524. }
  525. document.getElementById("n_per").innerHTML = people.length;
  526. document.getElementById("object_per").innerHTML = Person;
  527. if (people.length==0) {
  528. var messaggio = "<p class='no-results'>Nessun risultato trovato</p>";
  529. document.getElementById("object_per").innerHTML = messaggio;
  530. }
  531. }
  532. function handle_count(json) {
  533. console.log(json);
  534. const toponimi = [];
  535. const dataToponimi = [];
  536. var max = 0;
  537. $.each(
  538. json['results']['bindings'],
  539. function (index, value) {
  540. const topo = [];
  541. var toponimo = value['label']['value'];
  542. var count = value['Count']['value'];
  543. var temp = parseInt(count);
  544. toponimi.push(toponimo);
  545. dataToponimi.push([toponimo, count]);
  546. if (temp>max) {
  547. max = temp;
  548. }
  549. });
  550. // set the dimensions and margins of the graph
  551. var margin = {top: 20, right: 30, bottom: 40, left: 90},
  552. width = 460 - margin.left - margin.right,
  553. height = 400 - margin.top - margin.bottom;
  554. // append the svg object to the body of the page
  555. var svg = d3.select("#my_dataviz")
  556. .append("svg")
  557. .attr("width", width + margin.left + margin.right)
  558. .attr("height", height + margin.top + margin.bottom)
  559. .append("g")
  560. .attr("transform",
  561. "translate(" + margin.left + "," + margin.top + ")");
  562. // Parse the Data
  563. //d3.csv("https://raw.githubusercontent.com/holtzy/data_to_viz/master/Example_dataset/7_OneCatOneNum_header.csv", function(data) {
  564. // Add X axis
  565. var x = d3.scaleLinear()
  566. .domain([0, max])
  567. .range([ 0, width]);
  568. svg.append("g")
  569. .attr("transform", "translate(0," + height + ")")
  570. .call(d3.axisBottom(x))
  571. .selectAll("text")
  572. .attr("transform", "translate(-10,0)rotate(-45)")
  573. .style("text-anchor", "end");
  574. // Y axis
  575. var y = d3.scaleBand()
  576. .range([ 0, height ])
  577. .domain(toponimi)
  578. .padding(.1);
  579. svg.append("g")
  580. .call(d3.axisLeft(y))
  581. //Bars
  582. svg.selectAll("myRect")
  583. .data(dataToponimi)
  584. .enter()
  585. .append("rect")
  586. .attr("x", x(0) )
  587. .attr("y", function(d) { return y(d[0]); })
  588. .attr("width", function(d) { return x(d[1]); })
  589. .attr("height", y.bandwidth() )
  590. .attr("fill", "#69b3a2")
  591. /*var texts = svg.selectAll("myRect")
  592. .data(dataToponimi)
  593. .enter()
  594. .append("text");
  595. texts.attr("x", function(d){ return d[1] / 4 - 20})
  596. .attr("y", function(d,i){ return 22.26*i +20})
  597. .attr("text-anchor", "middle")
  598. .attr("fill", "#fff")
  599. .text(function(d){ return d[1]});*/
  600. }
  601. function handle_count2(json) {
  602. console.log(json);
  603. const toponimi = [];
  604. const dataToponimi = [];
  605. const values = [];
  606. var max = 0;
  607. $.each(
  608. json['results']['bindings'],
  609. function (index, value) {
  610. const topo = [];
  611. var toponimo = value['label']['value'];
  612. var count = value['Count']['value'];
  613. var temp = parseInt(count);
  614. toponimi.push(toponimo);
  615. dataToponimi.push([toponimo, count]);
  616. if (temp>max) {
  617. max = temp;
  618. }
  619. });
  620. // set the dimensions and margins of the graph
  621. var margin = {top: 20, right: 30, bottom: 40, left: 90},
  622. width = 460 - margin.left - margin.right,
  623. height = 400 - margin.top - margin.bottom;
  624. // append the svg object to the body of the page
  625. var svg = d3.select("#my_dataviz2")
  626. .append("svg")
  627. .attr("width", width + margin.left + margin.right)
  628. .attr("height", height + margin.top + margin.bottom)
  629. .append("g")
  630. .attr("transform",
  631. "translate(" + margin.left + "," + margin.top + ")");
  632. // Parse the Data
  633. //d3.csv("https://raw.githubusercontent.com/holtzy/data_to_viz/master/Example_dataset/7_OneCatOneNum_header.csv", function(data) {
  634. // Add X axis
  635. var x = d3.scaleLinear()
  636. .domain([0, max])
  637. .range([ 0, width]);
  638. svg.append("g")
  639. .attr("transform", "translate(0," + height + ")")
  640. .call(d3.axisBottom(x))
  641. .selectAll("text")
  642. .attr("transform", "translate(-10,0)rotate(-45)")
  643. .style("text-anchor", "end");
  644. // Y axis
  645. var y = d3.scaleBand()
  646. .range([ 0, height ])
  647. .domain(toponimi)
  648. .padding(.1);
  649. svg.append("g")
  650. .call(d3.axisLeft(y))
  651. //Bars
  652. svg.selectAll("myRect")
  653. .data(dataToponimi)
  654. .enter()
  655. .append("rect")
  656. .attr("x", x(0) )
  657. .attr("y", function(d) { return y(d[0]); })
  658. .attr("width", function(d) { return x(d[1]); })
  659. .attr("height", y.bandwidth() )
  660. .attr("fill", "#69b3a2")
  661. svg.selectAll("text2")
  662. .data(dataToponimi)
  663. .enter().append("text2")
  664. .text(function(d) {return d[1]})
  665. .attr("class", "text")
  666. }
  667. function open_info() {
  668. document.getElementById("info_luogo").style.display = "block";
  669. document.getElementById("place_info").style.display = "block";
  670. document.getElementById("topo").style.display = "none";
  671. document.getElementById("rif").style.display = "none";
  672. }
  673. function open_toponimi() {
  674. document.getElementById("info_luogo").style.display = "block";
  675. document.getElementById("place_info").style.display = "none";
  676. document.getElementById("topo").style.display = "block";
  677. document.getElementById("rif").style.display = "none";
  678. }
  679. function open_riferimenti() {
  680. document.getElementById("info_luogo").style.display = "block";
  681. document.getElementById("place_info").style.display = "none";
  682. document.getElementById("topo").style.display = "none";
  683. document.getElementById("rif").style.display = "block";
  684. }
  685. function open_collegamenti() {
  686. document.getElementById("references").style.display = "flex";
  687. document.getElementById("statistiche").style.display = "none";
  688. document.getElementById("regole_associazione").style.display = "none";
  689. }
  690. function open_statistiche() {
  691. document.getElementById("references").style.display = "none";
  692. document.getElementById("statistiche").style.display = "flex";
  693. document.getElementById("regole_associazione").style.display = "none";
  694. }
  695. function open_correlazioni() {
  696. document.getElementById("references").style.display = "none";
  697. document.getElementById("statistiche").style.display = "none";
  698. document.getElementById("regole_associazione").style.display = "flex";
  699. }
  700. /*
  701. var header = document.getElementById("ref_buttons");
  702. var btns = header.getElementsByClassName("btn");
  703. for (var i = 0; i < btns.length; i++) {
  704. btns[i].addEventListener("click", function() {
  705. var current = document.getElementsByClassName("active");
  706. current[0].className = current[0].className.replace(" active", "");
  707. this.className += " active";
  708. });
  709. }
  710. */
  711. //out = "";
  712. //for(i = 0; i < resultArray.length; i++){
  713. // out = out + JSON.stringify(resultArray[i])
  714. //}
  715. //queryStringOutput = (queryStringOutput + out).replace("}{",",");
  716. /*
  717. var locations = [
  718. ["LOCATION_1", 11.8166, 122.0942],
  719. ["LOCATION_2", 11.9804, 121.9189],
  720. ["LOCATION_3", 10.7202, 122.5621],
  721. ["LOCATION_4", 11.3889, 122.6277],
  722. ["LOCATION_5", 10.5929, 122.6325]
  723. ];
  724. var map = L.map('map').setView([11.206051, 122.447886], 8);
  725. mapLink =
  726. '<a href="http://openstreetmap.org">OpenStreetMap</a>';
  727. L.tileLayer(
  728. 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
  729. attribution: '&copy; ' + mapLink + ' Contributors',
  730. maxZoom: 18,
  731. }).addTo(map);
  732. for (var i = 0; i < locations.length; i++) {
  733. marker = new L.marker([locations[i][1], locations[i][2]])
  734. .bindPopup(locations[i][0])
  735. .addTo(map);
  736. }
  737. */
  738. $(document).on("click", ".persona", function (ev) {
  739. var link = this.id;
  740. //alert(nome_autore);
  741. //$('#myModal').text("");
  742. window.open("Persona.html?link="+this.id);
  743. });
  744. $(document).on("click", ".lettera", function (ev) {
  745. var link = this.id;
  746. //alert(nome_autore);
  747. //$('#myModal').text("");
  748. window.open("lettera.html?link="+this.id);
  749. });
  750. $(document).on("click", ".object", function (ev) {
  751. var link = this.id;
  752. //alert(nome_autore);
  753. //$('#myModal').text("");
  754. window.open("object.html?link="+this.id);
  755. });
  756. $(document).on("click", ".hyp", function (ev) {
  757. var baseurl = window.location.origin+window.location.pathname;
  758. let slash = baseurl.lastIndexOf("/");
  759. var type = $(this).val() + '.html';
  760. var link = this.id;
  761. var url = baseurl.substr(0, slash+1) + type + "?link="+link;
  762. var link = this.id;
  763. $("#myModal").empty();
  764. $("#myModal").css("display", "block");
  765. $('#myModal').append("<div class='modal-content'><div class='modal-close'><span class='close'>&times;</span></div><div id='myInput'>" +
  766. url + "</div><button id='copy_btn' class='btn btn-theme-primary btn-md' onclick='myFunction()'>Copia</button>");
  767. });
  768. $(document).on("click", ".close", function (ev) {
  769. var link = this.id;
  770. //alert(nome_autore);
  771. //$('#myModal').text("");
  772. $("#myModal").css("display", "none");
  773. });
  774. $(document).on("click", ".back", function (ev) {
  775. $("#myTab").css("display", "none");
  776. });
  777. $(document).on("click", ".cit", function (ev) {
  778. var author ="RESTORE. smart access to digital heritage and memory"
  779. var year = new Date().getFullYear()
  780. var today = new Date();
  781. var dd = String(today.getDate()).padStart(2, '0');
  782. var mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0!
  783. var yyyy = today.getFullYear();
  784. today = dd + '/' + mm + '/' + yyyy;
  785. var baseurl = window.location.origin+window.location.pathname;
  786. let slash = baseurl.lastIndexOf("/");
  787. var type = $(this).val() + '.html';
  788. var link = this.id;
  789. var url = baseurl.substr(0, slash+1) + type + "?link="+link;
  790. //alert(nome_autore);
  791. //$('#myModal').text("");
  792. $("#myModal").empty();
  793. $("#myModal").css("display", "block");
  794. $('#myModal').append("<div class='modal-content'><div class='modal-close'><span class='close'>&times;</span></div><div id='myInput'>" +
  795. author + " " + year + ", accesso effettuato: " + today + ", &lt;" + url + "&gt;</div><button id='copy_btn' class='btn btn-theme-primary btn-md' onclick='myFunction()'>Copia</button>");
  796. });
  797. function copyToClipboard(text) {
  798. var sampleTextarea = document.createElement("textarea");
  799. document.body.appendChild(sampleTextarea);
  800. sampleTextarea.value = text; //save main text in it
  801. sampleTextarea.select(); //select textarea contenrs
  802. document.execCommand("copy");
  803. document.body.removeChild(sampleTextarea);
  804. }
  805. function myFunction(){
  806. var copy = document.getElementById("myInput");
  807. copyText = copy.textContent;
  808. copyToClipboard(copyText);
  809. //copyToClipboard(copyText.value);
  810. }