map.js 31 KB

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