map.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723
  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 ?object ?label {\
  50. <" + thisUrlParams.link + "> owl:sameAs ?place .\
  51. ?event_to crm:P26_moved_to ?place ;\
  52. rdf:type crm:EL3_Receive_Letter ;\
  53. rdfs:subClassOf ?event .\
  54. ?object crm:P25i_moved_by ?event ; \
  55. rdfs:label ?label .\
  56. } "
  57. queryInvio = prefixes + " SELECT DISTINCT ?object ?label {\
  58. <" + thisUrlParams.link + "> owl:sameAs ?place .\
  59. ?event_to crm:P27_moved_from ?place ;\
  60. rdf:type crm:EL2_Send_Letter ;\
  61. rdfs:subClassOf ?event .\
  62. ?object crm:P25i_moved_by ?event ; \
  63. rdfs:label ?label .\
  64. }"
  65. queryCitazione = prefixes + " SELECT DISTINCT ?object ?label\
  66. {<" + thisUrlParams.link + "> crm:P1_is_identified_by ?toponym .\
  67. ?object crm:P67_refers_to ?toponym ;\
  68. rdfs:label ?label\
  69. }"
  70. queryPersone = prefixes + " SELECT DISTINCT ?range ?label \
  71. WHERE{ \
  72. {?place owl:sameAs <" + thisUrlParams.link + "> .\
  73. ?event_to crm:P26_moved_to ?place ;\
  74. rdf:type crm:EL3_Receive_Letter ;\
  75. crm:P01_has_domain ?domain .\
  76. ?domain crm:P02_has_range ?range .\
  77. ?range rdfs:label ?label .\
  78. } UNION {\
  79. ?place owl:sameAs <" + thisUrlParams.link + "> .\
  80. ?event_to crm:P27_moved_from ?place ;\
  81. rdf:type crm:EL2_Send_Letter ;\
  82. crm:P01_has_domain ?domain .\
  83. ?domain crm:P02_has_range ?range .\
  84. ?range rdfs:label ?label .\
  85. }\
  86. }"
  87. queryCount = prefixes + " SELECT ?place ?label COUNT(?label) AS ?Count \
  88. WHERE{ \
  89. ?place_to owl:sameAs <" + thisUrlParams.link + "> . \
  90. ?event_to crm:P26_moved_to ?place_to ; \
  91. rdf:type crm:EL3_Receive_Letter ; \
  92. rdfs:subClassOf ?event . \
  93. ?event_from rdfs:subClassOf ?event ; \
  94. rdf:type crm:EL2_Send_Letter ; \
  95. crm:P27_moved_from ?place . \
  96. ?place rdfs:label ?label \
  97. } \
  98. ORDER BY DESC (?Count)"
  99. queryCount2 = prefixes + " SELECT ?place ?label COUNT(?label) AS ?Count \
  100. WHERE{ \
  101. ?place_from owl:sameAs <" + thisUrlParams.link + "> . \
  102. ?event_from crm:P27_moved_from ?place_from ; \
  103. rdf:type crm:EL2_Send_Letter ; \
  104. rdfs:subClassOf ?event . \
  105. ?event_to rdfs:subClassOf ?event ; \
  106. rdf:type crm:EL2_Send_Letter ; \
  107. crm:P27_moved_from ?place . \
  108. ?place rdfs:label ?label . \
  109. } \
  110. ORDER BY DESC (?Count) "
  111. queryURL = prepareQueryURL(query);
  112. queryRef = prepareQueryURL(queryRiferimenti);
  113. queryTopo = prepareQueryURL(queryToponimi);
  114. queryRec = prepareQueryURL(queryRicezione);
  115. querySend = prepareQueryURL(queryInvio);
  116. queryCit = prepareQueryURL(queryCitazione);
  117. queryPer = prepareQueryURL(queryPersone);
  118. queryCon1 = prepareQueryURL(queryCount);
  119. queryCon2 = prepareQueryURL(queryCount2);
  120. response = $.ajax({//OGGETTO
  121. url: queryURL,
  122. dataType: "json",
  123. success: function (data){
  124. handle_data(data);
  125. },
  126. error: function (e) {}
  127. });
  128. response_ref = $.ajax({//OGGETTO
  129. url: queryRef,
  130. dataType: "json",
  131. success: function (data){
  132. handle_ref(data);
  133. },
  134. error: function (e) {}
  135. });
  136. response_top = $.ajax({//OGGETTO
  137. url: queryTopo,
  138. dataType: "json",
  139. success: function (data){
  140. handle_toponym(data);
  141. },
  142. error: function (e) {}
  143. });
  144. response_receive = $.ajax({//OGGETTO
  145. url: queryRec,
  146. dataType: "json",
  147. success: function (data){
  148. handle_receive(data);
  149. },
  150. error: function (e) {}
  151. });
  152. response_send = $.ajax({//OGGETTO
  153. url: querySend,
  154. dataType: "json",
  155. success: function (data){
  156. handle_send(data);
  157. },
  158. error: function (e) {}
  159. });
  160. response_cit = $.ajax({//OGGETTO
  161. url: queryCit,
  162. dataType: "json",
  163. success: function (data){
  164. handle_cit(data);
  165. },
  166. error: function (e) {}
  167. });
  168. response_per = $.ajax({//OGGETTO
  169. url: queryPer,
  170. dataType: "json",
  171. success: function (data){
  172. handle_persons(data);
  173. },
  174. error: function (e) {}
  175. });
  176. responseCountA = $.ajax({//OGGETTO
  177. url: queryCon1,
  178. dataType: "json",
  179. success: function (data){
  180. handle_count(data);
  181. },
  182. error: function (e) {}
  183. });
  184. responseCountP = $.ajax({//OGGETTO
  185. url: queryCon2,
  186. dataType: "json",
  187. success: function (data){
  188. handle_count2(data);
  189. },
  190. error: function (e) {}
  191. });
  192. function handle_data(json) {
  193. console.log(json);
  194. const locations = [];
  195. $.each(
  196. json['results']['bindings'],
  197. function (index, value) {
  198. const loc = []
  199. var graph = value['graph']['value'];
  200. var label = value['name_place']['value'];
  201. var coord = value['coordinates']['value'];
  202. const coordinates = coord.split(", ");
  203. loc.push(label);
  204. loc.push(coordinates[0]);
  205. loc.push(coordinates[1]);
  206. locations.push(loc);
  207. document.getElementById("grafo").innerHTML = graph;
  208. document.getElementById("nome_luogo").innerHTML = label;
  209. document.getElementById("nome_lu").innerHTML = label;
  210. document.getElementById("nome_lp").innerHTML = label;
  211. document.getElementById("nome_ll").innerHTML = label;
  212. document.getElementById("nome_lg").innerHTML = label;
  213. document.getElementById("nome_st1").innerHTML = label;
  214. document.getElementById("nome_st2").innerHTML = label;
  215. });
  216. var map = L.map('map').setView([locations[0][1], locations[0][2]], 7);
  217. mapLink = '<a href="http://openstreetmap.org">OpenStreetMap</a>';
  218. L.tileLayer(
  219. 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
  220. attribution: '&copy; ' + mapLink + ' Contributors',
  221. maxZoom: 18,
  222. }).addTo(map);
  223. for (var i = 0; i < locations.length; i++) {
  224. marker = new L.marker([locations[i][1], locations[i][2]])
  225. .bindPopup(locations[i][0])
  226. .addTo(map);
  227. }
  228. }
  229. function handle_ref(json) {
  230. console.log(json);
  231. const references = [];
  232. var list_ref = "";
  233. $.each(
  234. json['results']['bindings'],
  235. function (index, value) {
  236. var ref = value['references']['value'];
  237. references.push(ref);
  238. });
  239. for (i=0; i<references.length; i++) {
  240. list_ref += "<div class='row'><div class='col'><a href='" + references[i] + "'>" + references[i] + "</a></div></div>";
  241. }
  242. document.getElementById("riferimenti").innerHTML = list_ref;
  243. }
  244. function handle_toponym(json) {
  245. console.log(json);
  246. const toponym = [];
  247. $.each(
  248. json['results']['bindings'],
  249. function (index, value) {
  250. var topo = value['toponimi']['value'];
  251. toponym.push(" " + topo);
  252. });
  253. document.getElementById("toponimi").innerHTML = toponym;
  254. }
  255. function handle_receive(json) {
  256. console.log(json);
  257. const received = {};
  258. var i=0;
  259. $.each(
  260. json['results']['bindings'],
  261. function (index, value) {
  262. key = value['object']['value'];
  263. data = value['label']['value'];
  264. received[key] = data;
  265. i++;
  266. });
  267. var myArray = "";
  268. for (var key in received) {
  269. myArray += "<div class='row'><div class='col-10'>" + received[key] + "</div><div class='col'><a href='" + key + "'><i class='fas fa-external-link-alt' aria-hidden='true'></i></a></div></div>";
  270. }
  271. document.getElementById("n_receive").innerHTML = i;
  272. document.getElementById("object_receive").innerHTML = myArray;
  273. if (i==0) {
  274. var messaggio = "<p>Nessun risultato trovato</p>";
  275. document.getElementById("object_receive").innerHTML = messaggio;
  276. }
  277. }
  278. function handle_send(json) {
  279. console.log(json);
  280. const sent = {};
  281. var i=0;
  282. $.each(
  283. json['results']['bindings'],
  284. function (index, value) {
  285. key = value['object']['value'];
  286. data = value['label']['value'];
  287. sent[key] = data;
  288. i++;
  289. });
  290. var myArray = "";
  291. for (var key in sent) {
  292. myArray += "<div class='row'><div class='col-10'>" + sent[key] + "</div><div class='col'><a href='" + key + "'><i class='fas fa-external-link-alt' aria-hidden='true'></i></a></div></div>";
  293. }
  294. document.getElementById("n_send").innerHTML = i;
  295. document.getElementById("object_send").innerHTML = myArray;
  296. if (i==0) {
  297. var messaggio = "<p>Nessun risultato trovato</p>";
  298. document.getElementById("object_send").innerHTML = messaggio;
  299. }
  300. }
  301. function handle_cit(json) {
  302. console.log(json);
  303. const citations = {};
  304. var i=0;
  305. $.each(
  306. json['results']['bindings'],
  307. function (index, value) {
  308. key = value['object']['value'];
  309. data = value['label']['value'];
  310. citations[key] = data;
  311. i++;
  312. });
  313. var myArray = "";
  314. for (var key in citations) {
  315. myArray += "<div class='row'><div class='col-10'>" + citations[key] + "</div><div class='col'><a href='" + key + "'><i class='fas fa-external-link-alt' aria-hidden='true'></i></a></div></div>";
  316. }
  317. document.getElementById("n_cit").innerHTML = i;
  318. document.getElementById("object_cit").innerHTML = myArray;
  319. if (i==0) {
  320. var messaggio = "<p>Nessun risultato trovato</p>";
  321. document.getElementById("object_cit").innerHTML = messaggio;
  322. }
  323. }
  324. function handle_persons(json) {
  325. console.log(json);
  326. const people = {};
  327. var i=0;
  328. $.each(
  329. json['results']['bindings'],
  330. function (index, value) {
  331. key = value['range']['value'];
  332. data = value['label']['value'];
  333. people[key] = data;
  334. i++;
  335. });
  336. var myArray = "";
  337. for (var key in people) {
  338. myArray += "<div class='row'><div class='col-9'>" + people[key] + "</div><div class='persona col' id='" +
  339. key + "'><i class='fa fa-user'></i></div><div class='col'><a href='" +
  340. key + "'><i class='fas fa-external-link-alt' aria-hidden='true'></i></a></div></div>";
  341. }
  342. document.getElementById("n_per").innerHTML = i;
  343. document.getElementById("object_per").innerHTML = myArray;
  344. if (i==0) {
  345. var messaggio = "<p>Nessun risultato trovato</p>";
  346. document.getElementById("object_per").innerHTML = messaggio;
  347. }
  348. }
  349. function handle_count(json) {
  350. console.log(json);
  351. const toponimi = [];
  352. const dataToponimi = [];
  353. var max = 0;
  354. $.each(
  355. json['results']['bindings'],
  356. function (index, value) {
  357. const topo = [];
  358. var toponimo = value['label']['value'];
  359. var count = value['Count']['value'];
  360. var temp = parseInt(count);
  361. toponimi.push(toponimo);
  362. dataToponimi.push([toponimo, count]);
  363. if (temp>max) {
  364. max = temp;
  365. }
  366. });
  367. // set the dimensions and margins of the graph
  368. var margin = {top: 20, right: 30, bottom: 40, left: 90},
  369. width = 460 - margin.left - margin.right,
  370. height = 400 - margin.top - margin.bottom;
  371. // append the svg object to the body of the page
  372. var svg = d3.select("#my_dataviz")
  373. .append("svg")
  374. .attr("width", width + margin.left + margin.right)
  375. .attr("height", height + margin.top + margin.bottom)
  376. .append("g")
  377. .attr("transform",
  378. "translate(" + margin.left + "," + margin.top + ")");
  379. // Parse the Data
  380. //d3.csv("https://raw.githubusercontent.com/holtzy/data_to_viz/master/Example_dataset/7_OneCatOneNum_header.csv", function(data) {
  381. // Add X axis
  382. var x = d3.scaleLinear()
  383. .domain([0, max])
  384. .range([ 0, width]);
  385. svg.append("g")
  386. .attr("transform", "translate(0," + height + ")")
  387. .call(d3.axisBottom(x))
  388. .selectAll("text")
  389. .attr("transform", "translate(-10,0)rotate(-45)")
  390. .style("text-anchor", "end");
  391. // Y axis
  392. var y = d3.scaleBand()
  393. .range([ 0, height ])
  394. .domain(toponimi)
  395. .padding(.1);
  396. svg.append("g")
  397. .call(d3.axisLeft(y))
  398. //Bars
  399. svg.selectAll("myRect")
  400. .data(dataToponimi)
  401. .enter()
  402. .append("rect")
  403. .attr("x", x(0) )
  404. .attr("y", function(d) { return y(d[0]); })
  405. .attr("width", function(d) { return x(d[1]); })
  406. .attr("height", y.bandwidth() )
  407. .attr("fill", "#69b3a2")
  408. /*var texts = svg.selectAll("myRect")
  409. .data(dataToponimi)
  410. .enter()
  411. .append("text");
  412. texts.attr("x", function(d){ return d[1] / 4 - 20})
  413. .attr("y", function(d,i){ return 22.26*i +20})
  414. .attr("text-anchor", "middle")
  415. .attr("fill", "#fff")
  416. .text(function(d){ return d[1]});*/
  417. }
  418. function handle_count2(json) {
  419. console.log(json);
  420. const toponimi = [];
  421. const dataToponimi = [];
  422. const values = [];
  423. var max = 0;
  424. $.each(
  425. json['results']['bindings'],
  426. function (index, value) {
  427. const topo = [];
  428. var toponimo = value['label']['value'];
  429. var count = value['Count']['value'];
  430. var temp = parseInt(count);
  431. toponimi.push(toponimo);
  432. dataToponimi.push([toponimo, count]);
  433. if (temp>max) {
  434. max = temp;
  435. }
  436. });
  437. // set the dimensions and margins of the graph
  438. var margin = {top: 20, right: 30, bottom: 40, left: 90},
  439. width = 460 - margin.left - margin.right,
  440. height = 400 - margin.top - margin.bottom;
  441. // append the svg object to the body of the page
  442. var svg = d3.select("#my_dataviz2")
  443. .append("svg")
  444. .attr("width", width + margin.left + margin.right)
  445. .attr("height", height + margin.top + margin.bottom)
  446. .append("g")
  447. .attr("transform",
  448. "translate(" + margin.left + "," + margin.top + ")");
  449. // Parse the Data
  450. //d3.csv("https://raw.githubusercontent.com/holtzy/data_to_viz/master/Example_dataset/7_OneCatOneNum_header.csv", function(data) {
  451. // Add X axis
  452. var x = d3.scaleLinear()
  453. .domain([0, max])
  454. .range([ 0, width]);
  455. svg.append("g")
  456. .attr("transform", "translate(0," + height + ")")
  457. .call(d3.axisBottom(x))
  458. .selectAll("text")
  459. .attr("transform", "translate(-10,0)rotate(-45)")
  460. .style("text-anchor", "end");
  461. // Y axis
  462. var y = d3.scaleBand()
  463. .range([ 0, height ])
  464. .domain(toponimi)
  465. .padding(.1);
  466. svg.append("g")
  467. .call(d3.axisLeft(y))
  468. //Bars
  469. svg.selectAll("myRect")
  470. .data(dataToponimi)
  471. .enter()
  472. .append("rect")
  473. .attr("x", x(0) )
  474. .attr("y", function(d) { return y(d[0]); })
  475. .attr("width", function(d) { return x(d[1]); })
  476. .attr("height", y.bandwidth() )
  477. .attr("fill", "#69b3a2")
  478. svg.selectAll("text2")
  479. .data(dataToponimi)
  480. .enter().append("text2")
  481. .text(function(d) {return d[1]})
  482. .attr("class", "text")
  483. }
  484. function open_info() {
  485. document.getElementById("info_luogo").style.display = "block";
  486. document.getElementById("place_info").style.display = "block";
  487. document.getElementById("topo").style.display = "none";
  488. document.getElementById("rif").style.display = "none";
  489. }
  490. function open_toponimi() {
  491. document.getElementById("info_luogo").style.display = "block";
  492. document.getElementById("place_info").style.display = "none";
  493. document.getElementById("topo").style.display = "block";
  494. document.getElementById("rif").style.display = "none";
  495. }
  496. function open_riferimenti() {
  497. document.getElementById("info_luogo").style.display = "block";
  498. document.getElementById("place_info").style.display = "none";
  499. document.getElementById("topo").style.display = "none";
  500. document.getElementById("rif").style.display = "block";
  501. }
  502. function open_collegamenti() {
  503. document.getElementById("references").style.display = "flex";
  504. document.getElementById("statistiche").style.display = "none";
  505. }
  506. function open_statistiche() {
  507. document.getElementById("references").style.display = "none";
  508. document.getElementById("statistiche").style.display = "flex";
  509. }
  510. var header = document.getElementById("ref_buttons");
  511. var btns = header.getElementsByClassName("btn");
  512. for (var i = 0; i < btns.length; i++) {
  513. btns[i].addEventListener("click", function() {
  514. var current = document.getElementsByClassName("active");
  515. current[0].className = current[0].className.replace(" active", "");
  516. this.className += " active";
  517. });
  518. }
  519. //out = "";
  520. //for(i = 0; i < resultArray.length; i++){
  521. // out = out + JSON.stringify(resultArray[i])
  522. //}
  523. //queryStringOutput = (queryStringOutput + out).replace("}{",",");
  524. /*
  525. var locations = [
  526. ["LOCATION_1", 11.8166, 122.0942],
  527. ["LOCATION_2", 11.9804, 121.9189],
  528. ["LOCATION_3", 10.7202, 122.5621],
  529. ["LOCATION_4", 11.3889, 122.6277],
  530. ["LOCATION_5", 10.5929, 122.6325]
  531. ];
  532. var map = L.map('map').setView([11.206051, 122.447886], 8);
  533. mapLink =
  534. '<a href="http://openstreetmap.org">OpenStreetMap</a>';
  535. L.tileLayer(
  536. 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
  537. attribution: '&copy; ' + mapLink + ' Contributors',
  538. maxZoom: 18,
  539. }).addTo(map);
  540. for (var i = 0; i < locations.length; i++) {
  541. marker = new L.marker([locations[i][1], locations[i][2]])
  542. .bindPopup(locations[i][0])
  543. .addTo(map);
  544. }
  545. */
  546. $(document).on("click", ".persona", function (ev) {
  547. var link = this.id;
  548. //alert(nome_autore);
  549. //$('#myModal').text("");
  550. window.open("Persona.html?link="+this.id);
  551. });