map.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  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 ?ref ?toponym {\
  38. GRAPH ?graph {<" + thisUrlParams.link + "> crm:P168_place_is_defined_by ?coordinates;\
  39. rdfs:label ?name_place ;\
  40. owl:sameAs ?ref;\
  41. crm:P1_is_identified_by ?uri_toponym .\
  42. ?uri_toponym rdfs:label ?toponym\
  43. }\
  44. }"
  45. queryRiferimenti = prefixes + " SELECT DISTINCT ?references {\
  46. <" + thisUrlParams.link + "> owl:sameAs ?references\
  47. }"
  48. queryToponimi = prefixes + " SELECT DISTINCT ?toponimi {\
  49. <" + thisUrlParams.link + "> crm:P1_is_identified_by ?uri_toponym .\
  50. ?uri_toponym rdfs:label ?toponimi\
  51. }"
  52. queryRicezione = prefixes + " SELECT DISTINCT ?object ?label {\
  53. <" + thisUrlParams.link + "> owl:sameAs ?place .\
  54. ?event_to crm:P26_moved_to ?place ;\
  55. rdf:type crm:EL3_Receive_Letter ;\
  56. rdfs:subClassOf ?event .\
  57. ?object crm:P25i_moved_by ?event ; \
  58. rdfs:label ?label .\
  59. } "
  60. queryInvio = prefixes + " SELECT DISTINCT ?object ?label {\
  61. <" + thisUrlParams.link + "> owl:sameAs ?place .\
  62. ?event_to crm:P27_moved_from ?place ;\
  63. rdf:type crm:EL2_Send_Letter ;\
  64. rdfs:subClassOf ?event .\
  65. ?object crm:P25i_moved_by ?event ; \
  66. rdfs:label ?label .\
  67. }"
  68. queryCitazione = prefixes + " SELECT DISTINCT ?object ?label{\
  69. <" + thisUrlParams.link + "> crm:P1_is_identified_by ?toponym .\
  70. ?object crm:P67_refers_to ?toponym ;\
  71. rdfs:label ?label\
  72. }"
  73. queryURL = prepareQueryURL(query);
  74. queryRef = prepareQueryURL(queryRiferimenti);
  75. queryTopo = prepareQueryURL(queryToponimi);
  76. queryRec = prepareQueryURL(queryRicezione);
  77. querySend = prepareQueryURL(queryInvio);
  78. queryCit = prepareQueryURL(queryCitazione);
  79. response = $.ajax({//OGGETTO
  80. url: queryURL,
  81. dataType: "json",
  82. success: function (data){
  83. handle_data(data);
  84. },
  85. error: function (e) {}
  86. });
  87. response_ref = $.ajax({//OGGETTO
  88. url: queryRef,
  89. dataType: "json",
  90. success: function (data){
  91. handle_ref(data);
  92. },
  93. error: function (e) {}
  94. });
  95. response_top = $.ajax({//OGGETTO
  96. url: queryTopo,
  97. dataType: "json",
  98. success: function (data){
  99. handle_toponym(data);
  100. },
  101. error: function (e) {}
  102. });
  103. response_receive = $.ajax({//OGGETTO
  104. url: queryRec,
  105. dataType: "json",
  106. success: function (data){
  107. handle_receive(data);
  108. },
  109. error: function (e) {}
  110. });
  111. response_send = $.ajax({//OGGETTO
  112. url: querySend,
  113. dataType: "json",
  114. success: function (data){
  115. handle_send(data);
  116. },
  117. error: function (e) {}
  118. });
  119. response_cit = $.ajax({//OGGETTO
  120. url: queryCit,
  121. dataType: "json",
  122. success: function (data){
  123. handle_cit(data);
  124. },
  125. error: function (e) {}
  126. });
  127. function handle_data(json) {
  128. console.log(json);
  129. const locations = [];
  130. $.each(
  131. json['results']['bindings'],
  132. function (index, value) {
  133. const loc = []
  134. var graph = value['graph']['value'];
  135. var ref = value['ref']['value'];
  136. var label = value['name_place']['value'];
  137. var coord = value['coordinates']['value'];
  138. const coordinates = coord.split(", ");
  139. loc.push(label);
  140. loc.push(coordinates[0]);
  141. loc.push(coordinates[1]);
  142. locations.push(loc);
  143. document.getElementById("grafo").innerHTML = graph;
  144. document.getElementById("nome_luogo").innerHTML = label;
  145. });
  146. var map = L.map('map').setView([locations[0][1], locations[0][2]], 12);
  147. mapLink = '<a href="http://openstreetmap.org">OpenStreetMap</a>';
  148. L.tileLayer(
  149. 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
  150. attribution: '&copy; ' + mapLink + ' Contributors',
  151. maxZoom: 18,
  152. }).addTo(map);
  153. for (var i = 0; i < locations.length; i++) {
  154. marker = new L.marker([locations[i][1], locations[i][2]])
  155. .bindPopup(locations[i][0])
  156. .addTo(map);
  157. }
  158. }
  159. function handle_ref(json) {
  160. console.log(json);
  161. const references = [];
  162. $.each(
  163. json['results']['bindings'],
  164. function (index, value) {
  165. var ref = value['references']['value'];
  166. references.push(ref);
  167. });
  168. document.getElementById("riferimenti").innerHTML = references;
  169. }
  170. function handle_toponym(json) {
  171. console.log(json);
  172. const toponym = [];
  173. $.each(
  174. json['results']['bindings'],
  175. function (index, value) {
  176. var topo = value['toponimi']['value'];
  177. toponym.push(topo);
  178. });
  179. document.getElementById("toponimi").innerHTML = toponym;
  180. }
  181. function handle_receive(json) {
  182. console.log(json);
  183. const received = {};
  184. $.each(
  185. json['results']['bindings'],
  186. function (index, value) {
  187. key = value['object']['value'];
  188. data = value['label']['value'];
  189. received[key] = data;
  190. });
  191. var myArray = "";
  192. for (var key in received) {
  193. myArray += received[key] + "<br />";
  194. }
  195. document.getElementById("object_receive").innerHTML = myArray;
  196. }
  197. function handle_send(json) {
  198. console.log(json);
  199. const sent = {};
  200. $.each(
  201. json['results']['bindings'],
  202. function (index, value) {
  203. key = value['object']['value'];
  204. data = value['label']['value'];
  205. sent[key] = data;
  206. });
  207. var myArray = "";
  208. for (var key in sent) {
  209. myArray += sent[key] + "<br />";
  210. }
  211. document.getElementById("object_send").innerHTML = myArray;
  212. }
  213. function handle_cit(json) {
  214. console.log(json);
  215. const citations = {};
  216. $.each(
  217. json['results']['bindings'],
  218. function (index, value) {
  219. key = value['object']['value'];
  220. data = value['label']['value'];
  221. citations[key] = data;
  222. });
  223. var myArray = "";
  224. for (var key in citations) {
  225. myArray += citations[key] + "<br />";
  226. }
  227. document.getElementById("object_cit").innerHTML = myArray;
  228. }
  229. //out = "";
  230. //for(i = 0; i < resultArray.length; i++){
  231. // out = out + JSON.stringify(resultArray[i])
  232. //}
  233. //queryStringOutput = (queryStringOutput + out).replace("}{",",");
  234. /*
  235. var locations = [
  236. ["LOCATION_1", 11.8166, 122.0942],
  237. ["LOCATION_2", 11.9804, 121.9189],
  238. ["LOCATION_3", 10.7202, 122.5621],
  239. ["LOCATION_4", 11.3889, 122.6277],
  240. ["LOCATION_5", 10.5929, 122.6325]
  241. ];
  242. var map = L.map('map').setView([11.206051, 122.447886], 8);
  243. mapLink =
  244. '<a href="http://openstreetmap.org">OpenStreetMap</a>';
  245. L.tileLayer(
  246. 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
  247. attribution: '&copy; ' + mapLink + ' Contributors',
  248. maxZoom: 18,
  249. }).addTo(map);
  250. for (var i = 0; i < locations.length; i++) {
  251. marker = new L.marker([locations[i][1], locations[i][2]])
  252. .bindPopup(locations[i][0])
  253. .addTo(map);
  254. }
  255. */