1
|
/*
|
2
|
UnivNautes
|
3
|
Copyright (C) 2014 Entr'ouvert
|
4
|
|
5
|
This program is free software: you can redistribute it and/or modify it under
|
6
|
the terms of the GNU Affero General Public License as published by the Free
|
7
|
Software Foundation, either version 3 of the License, or (at your option) any
|
8
|
later version.
|
9
|
|
10
|
This program is distributed in the hope that it will be useful, but WITHOUT
|
11
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
12
|
FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
13
|
details.
|
14
|
|
15
|
You should have received a copy of the GNU Affero General Public License
|
16
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17
|
*/
|
18
|
|
19
|
function univnautes(bounds) {
|
20
|
|
21
|
var redirectTimeout;
|
22
|
var refreshMarkersTimeout;
|
23
|
var redirectLink = '';
|
24
|
var searchinput = $('input#search');
|
25
|
|
26
|
var start_center = [46.5, 2.5];
|
27
|
if (bounds) {
|
28
|
var start_lat = (bounds[0][0] + bounds[1][0])/2;
|
29
|
var start_lon = (bounds[0][1] + bounds[1][1])/2;
|
30
|
start_center = [start_lat, start_lon];
|
31
|
}
|
32
|
|
33
|
var map = L.map('map', {
|
34
|
center: start_center,
|
35
|
zoom: 6,
|
36
|
maxZoom: 16
|
37
|
});
|
38
|
L.tileLayer('/map/{z}/{x}/{y}.png').addTo(map);
|
39
|
L.control.scale( { 'imperial': false, 'updateWhenIdle': true } ).addTo(map);
|
40
|
|
41
|
map.attributionControl.setPrefix('');
|
42
|
map.attributionControl.addAttribution('');
|
43
|
|
44
|
var markers = new L.MarkerClusterGroup({
|
45
|
spiderfyOnMaxZoom: true,
|
46
|
showCoverageOnHover: false,
|
47
|
zoomToBoundsOnClick: true,
|
48
|
animateAddingMarkers: false,
|
49
|
disableClusteringAtZoom: 50,
|
50
|
maxClusterRadius: 25,
|
51
|
spiderfyDistanceMultiplier: 3,
|
52
|
singleMarkerMode: true,
|
53
|
});
|
54
|
|
55
|
/*
|
56
|
geoinfos = [ {
|
57
|
"entityid": "https://shib-idp-1.oru.se/idp/shibboleth",
|
58
|
"geo": [ [ 59.7065, 14.5473 ], [ 59.2547, 15.2485 ] ],
|
59
|
"slug": "orebro-universitet"
|
60
|
}, ... ]
|
61
|
*/
|
62
|
|
63
|
function refreshMarkers() {
|
64
|
var searchValue = searchinput.val().toLowerCase();
|
65
|
var new_markers = new Array();
|
66
|
for (var i=geoinfos.length-1; i>=0; i--) {
|
67
|
var geoinfo = geoinfos[i];
|
68
|
var slug = geoinfo['slug'];
|
69
|
var listitem = $('#idp-' + slug);
|
70
|
var name = geoinfo['name'];
|
71
|
var entityid = geoinfo['entityid'];
|
72
|
var geo = geoinfo['geo'];
|
73
|
if (searchValue.length > 2) {
|
74
|
if (name.toLowerCase().indexOf(searchValue) < 0) {
|
75
|
listitem.hide();
|
76
|
listitem.addClass('hidden');
|
77
|
continue;
|
78
|
}
|
79
|
} else {
|
80
|
var show=false;
|
81
|
for (var j=geo.length-1; j>=0; j--)
|
82
|
if (map.getBounds().contains(geo[j]))
|
83
|
show=true;
|
84
|
if (!show) {
|
85
|
listitem.hide();
|
86
|
listitem.addClass('hidden');
|
87
|
continue;
|
88
|
}
|
89
|
}
|
90
|
listitem.show();
|
91
|
for (var j=geo.length-1; j>=0; j--) {
|
92
|
var marker = new L.Marker(geo[j], {
|
93
|
title: name,
|
94
|
icon: new L.DivIcon({
|
95
|
html: '<div><span></span></div>',
|
96
|
className: 'marker-cluster marker-cluster-one',
|
97
|
iconSize: new L.Point(40, 40)
|
98
|
})
|
99
|
});
|
100
|
marker.entityid = entityid;
|
101
|
marker.bindPopup('<p>' + name + '</p><p align="center"><button class="connexion"><a href="/authsaml2/sso?entity_id=' + entityid + '"></i>Connexion</a></button></p>');
|
102
|
new_markers.push(marker);
|
103
|
}
|
104
|
}
|
105
|
markers.clearLayers();
|
106
|
markers.addLayers(new_markers);
|
107
|
}
|
108
|
|
109
|
function delayRefresh(e) {
|
110
|
clearTimeout(refreshMarkersTimeout);
|
111
|
refreshMarkersTimeout = setTimeout(refreshMarkers, 500);
|
112
|
}
|
113
|
|
114
|
if (bounds) {
|
115
|
map.fitBounds(bounds);
|
116
|
}
|
117
|
|
118
|
map.addLayer(markers);
|
119
|
refreshMarkers();
|
120
|
map.on('moveend', delayRefresh);
|
121
|
|
122
|
searchinput.on('keyup webkitspeechchange speechchange', delayRefresh);
|
123
|
|
124
|
}
|