map.js 33 KB

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