Projet

Général

Profil

Télécharger (4,18 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / usr / local / univnautes / sp / sp / static / univnautes / univnautes.js @ 3e79844f

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
        console.log('refreshMarkers');
65
        var searchValue = searchinput.val().toLowerCase();
66
        var new_markers = new Array();
67
        for (var i=geoinfos.length-1; i>=0; i--) {
68
            var geoinfo = geoinfos[i];
69
            var slug = geoinfo['slug'];
70
            var listitem = $('#idp-' + slug);
71
            var name = geoinfo['name'];
72
            var entityid = geoinfo['entityid'];
73
            var geo = geoinfo['geo'];
74
            if (searchValue.length > 2) {
75
                if (name.toLowerCase().indexOf(searchValue) < 0) {
76
                    listitem.hide();
77
                    listitem.addClass('hidden');
78
                    continue;
79
                }
80
            } else {
81
                var show=false;
82
                for (var j=geo.length-1; j>=0; j--)
83
                    if (map.getBounds().contains(geo[j]))
84
                        show=true;
85
                if (!show) {
86
                    listitem.hide();
87
                    listitem.addClass('hidden');
88
                    continue;
89
                }
90
            }
91
            listitem.show();
92
            for (var j=geo.length-1; j>=0; j--) {
93
                var marker = new L.Marker(geo[j], { 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
}
(2-2/2)