-
Notifications
You must be signed in to change notification settings - Fork 7
/
searchissues.html
254 lines (205 loc) · 9.13 KB
/
searchissues.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
---
layout: page
title: Ricerca
subtitle: Qui puoi vedere i risultati di una ricerca fatta nelle nostre segnalazioni
lang: it
---
<div class="row">
<div class="col-lg-8 offset-lg-2 col-md-10 offset-md-1 col-sm-12">
<form class="global-search" role="form" action="/searchissues" method="get">
<div class="input-group">
<input type="text" class="form-control" id="search-box" name="query" placeholder="Cosa cerchi?">
<div class="input-group-btn">
<button class="btn btn-primary" type="submit"><span><i class="glyphicon glyphicon-search"></i> Cerca</span></button>
</div>
</div>
</form>
</div>
</div>
<div class="row">
<div class="col-lg-8 offset-lg-2 col-md-10 offset-md-1 col-sm-12">
<h2>Risultati</h2>
</div>
</div>
<style>
#map{ height: 600px; }
</style>
<div class="row">
<div class="col-md-12 col-sm-12 col-12"> <div id="map" class="w-100" style="height: 600px;"></div> </div>
<div class="row">
<div class="col-lg-8 offset-lg-2 col-md-10 offset-md-1 col-sm-12" id="search-results">
</div>
</div>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.6.0/dist/leaflet.css"
integrity="sha512-xwE/Az9zrjBIphAcBb3F6JVqxf46+CDLwfLMHloNu6KEQCAWi6HcDUbeOfBIptF7tcCzusKFjFw2yuvEpDL9wQ=="
crossorigin=""/>
<!-- Make sure you put this AFTER Leaflet's CSS -->
<script src="https://unpkg.com/leaflet@1.6.0/dist/leaflet.js"
integrity="sha512-gZwIG9x3wUXg2hdXF6+rVkLF/0Vi9U8D2Ntg4Ga5I5BZpVkVxlJWbSQtXPSiUTtC0TjtGOmxa1AJPuV0CPthew=="
crossorigin=""></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/Leaflet.awesome-markers/2.0.2/leaflet.awesome-markers.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/Leaflet.awesome-markers/2.0.2/leaflet.awesome-markers.min.js"></script>
<link rel="stylesheet" href="https://unpkg.com/leaflet.markercluster@1.4.1/dist/MarkerCluster.css"
crossorigin=""/>
<link rel="stylesheet" href="https://unpkg.com/leaflet.markercluster@1.4.1/dist/MarkerCluster.Default.css"
crossorigin=""/>
<script src="https://unpkg.com/leaflet.markercluster@1.4.1/dist/leaflet.markercluster.js"
crossorigin=""></script>
<script>
function urldecode(str) {
return decodeURIComponent((str+'').replace(/\+/g, '%20'));
}
window.store = {};
{% assign filteredissues = site.data.machgen.issuesjson %}
{% for member in filteredissues %}
window.store["{{site.url}}/issues/{{member.number}}"]={
"title": urldecode("{{ member.title | strip_html | url_encode }}"),
"label": {{member.issue.labels | join: ','}},
{% if member.issue.data.Descrizione != blank %}
"content": urldecode("{{ member.issue.data.Descrizione | url_encode }}"),
{% else %}
"content": "",
{% endif %}
{% if member.issue.created_at != blank %}
"date": "{{member.issue.created_at | date: '%-d/%m/%Y' }}",
"created_at": "{{member.issue.created_at | date: '%s' }}",
{% endif %}
{% if member.issue.provincia != blank %}
"provincia": "{{member.issue.provincia | url_encode}}",
{% endif %}
{% if member.issue.regione != blank %}
"regione": "{{member.issue.regione | url_encode}}",
{% endif %}
{%- if member.issue.data.Posizione != blank -%}
{%- assign coords = member.issue.data.Posizione | split: " " -%}
"lat": {{coords[0]}},
"lon": {{coords[1]}},
{%- elsif member.issue.data.location.address.lat != blank and member.issue.data.location.address.lon != blank -%}
"lat": {{member.issue.data.location.address.lat}},
"lon": {{member.issue.data.location.address.lon}},
{%- elsif member.issue.data.address.address.lat != blank and member.issue.data.address.address.lon != blank -%}
"lat": {{member.issue.data.address.address.lat}},
"lon": {{member.issue.data.address.address.lon}},
{%- elsif member.issue.data.lat != blank and member.issue.data.lon != blank -%}
"lat":{{member.issue.data.lat}},
"lon": {{member.issue.data.lon}},
{%- endif -%}
"url": "{{site.url}}/issues/{{member.number}}",
"state": "{{member.state}}"
};
{% endfor %}
</script>
<script>
var markerList=[];
function displayMap() {
// define icons
var markerIcons = {};
{% for categorytuple in issuecategories %}
{% assign category = categorytuple[1] %}
var newMarker = L.AwesomeMarkers.icon({icon: "{{category['markericon']}}", markerColor: "{{category['markercolor']}}", prefix: 'fa'});
{% for clabel in category['labelnames'] %}
markerIcons["{{clabel}}"]=newMarker;
{% endfor %}
{% endfor %}
var iconaDefault = L.AwesomeMarkers.icon({icon: '', markerColor: 'darkpurple'});
// initialize the map
var map = L.map('map', {
scrollWheelZoom: false
})
// create the tile layer with correct attribution
var osmUrl='{{site.tile_map}}';
var osmAttrib='© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>, Tiles courtesy of <a href="http://hot.openstreetmap.org/" target="_blank">Humanitarian OpenStreetMap Team</a>';
var osm = new L.TileLayer(osmUrl, {minZoom: {{site.issuemap.zoom}}>1?{{site.issuemap.zoom}}-1:{{site.issuemap.zoom}}, maxZoom: 19, attribution: osmAttrib});
var sumLat = 0.;
var sumLon = 0.;
markers = L.markerClusterGroup();
for (var i=0; i<markerList.length; i++) {
var lat = markerList[i][0];
var lon = markerList[i][1];
var popupText = markerList[i][2];
var popupURL = markerList[i][3];
var labels = markerList[i][4];
var iconaFinale = iconaDefault;
// Raccolte fondi, Supporto psicologico, Servizi e iniziative solidali pubbliche, Servizi e iniziative solidali private, Richiesta aiuto
for (var il = 0; il < labels.length; il++) {
if (labels[il] in markerIcons) {
iconaFinale = markerIcons[labels[il]];
break;
}
}
if (!isNaN(lat) && !isNaN(lon)) {
var markerLocation = new L.LatLng(lat, lon);
var marker = new L.Marker(markerLocation, {icon: iconaFinale});
markers.addLayer(marker);
marker.bindPopup("<a href=\"/issues/" + popupURL + "\">" + decodeURI(popupText) + "</a>");
sumLat += lat;
sumLon += lon;
}
}
map.addLayer(markers);
{% if page.mapcenter != blank and page.mapzoom != blank %}
map.addLayer(osm).setView([{{page.mapcenter[0]}},{{page.mapcenter[1]}}], {{page.mapzoom}});
{% else %}
map.addLayer(osm).setView([{{site.issuemap.center}}], {{site.issuemap.zoom}});
{% endif %}
//var group = new L.featureGroup([marker1, marker2, marker3]);
map.fitBounds(markers.getBounds().pad(0.1));
}
function getFeaturesInView() {
//console.log("getFeaturesInView");
var featuresInView = [];
var featuresNotInView = [];
for (var i=0; i<markerList.length; i++) {
if(map.getBounds().contains(L.latLng(markerList[i][0],markerList[i][1]))) {
featuresInView.push(markerList[i]);
} else {
featuresNotInView.push(markerList[i]);
}
}
return [featuresInView,featuresNotInView];
}
function setVisible(element) {
$("#issue"+element[3]).show();
//console.log("Show #issue"+element[3]);
}
function setInVisible(element) {
$("#issue"+element[3]).hide();
//console.log("Hide #issue"+element[3]);
}
function onMoveEnd(evt) {
[inView,notInView]=getFeaturesInView();
console.log(notInView);
console.log(inView);
notInView.forEach(setInVisible);
inView.forEach(setVisible);
}
map.on('moveend', onMoveEnd);
/**
* Get the URL parameters
* source: https://css-tricks.com/snippets/javascript/get-url-variables/
* @param {String} url The URL
* @return {Object} The URL parameters
*/
var getParams = function (url) {
var params = {};
var parser = document.createElement('a');
parser.href = url;
var query = parser.search.substring(1);
var vars = query.split('&');
for (var i = 0; i < vars.length; i++) {
var pair = vars[i].split('=');
params[pair[0]] = decodeURIComponent(pair[1]);
}
return params;
};
function processParams (){
params = getParams(window.location.href);
//console.log(params);
}
window.onload = processParams;
</script>
<script src="//code.jquery.com/jquery-1.12.3.js"></script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/elasticlunr/0.9.5/elasticlunr.min.js"></script>
<script type="text/javascript" src="../js/lunr.stemmer.support.min.js"></script>
<script type="text/javascript" src="../js/lunr.it.min.js"></script>
<script type="text/javascript" src="../js/search.min.js"></script>