map.js 28 KB

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