home.html 3.27 KB
Newer Older
1
2
{% extends 'main_website/base.html' %}

Florent Chehab's avatar
Florent Chehab committed
3
4
{% load staticfiles %}

5
{% block content %}
Florent Chehab's avatar
Florent Chehab committed
6
    <div id="mapid" style="height:400px"></div>
Florent Chehab's avatar
Florent Chehab committed
7

Florent Chehab's avatar
Florent Chehab committed
8
9
    <link rel="stylesheet" href="{% static 'css/leaflet.css' %}"/>
    <script type="text/javascript" src="{% static 'js/leaflet.js' %}"></script>
Florent Chehab's avatar
Florent Chehab committed
10
11
12
13
14
    
    <link rel="stylesheet" href="{% static 'css/MarkerCluster.css' %}"/>
    <link rel="stylesheet" href="{% static 'css/MarkerCluster.Default.css' %}"/>
    <script type="text/javascript" src="{% static 'js/leaflet.markercluster.js' %}"></script>

Florent Chehab's avatar
Florent Chehab committed
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
    <script>

        var Stamen_Watercolor = L.tileLayer('https://stamen-tiles-{s}.a.ssl.fastly.net/watercolor/{z}/{x}/{y}.{ext}', {
            attribution: 'Map tiles by <a href="http://stamen.com">Stamen Design</a>, <a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a> &mdash; Map data &copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>',
            subdomains: 'abcd',
            minZoom: 1,
            maxZoom: 18,
            ext: 'png'
        });

        var Stamen_Label = L.tileLayer('https://stamen-tiles-{s}.a.ssl.fastly.net/toner-labels/{z}/{x}/{y}.{ext}', {
            attribution: 'Map tiles by <a href="http://stamen.com">Stamen Design</a>, <a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a> &mdash; Map data &copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>',
            subdomains: 'abcd',
            minZoom: 1,
            maxZoom: 18,
            ext: 'png'
        });

        var OpenStreetMap_Mapnik = L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
            maxZoom: 19,
            attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
        });

        var Esri_WorldImagery = L.tileLayer('https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}', {
            attribution: 'Tiles &copy; Esri &mdash; Source: Esri, i-cubed, USDA, USGS, AEX, GeoEye, Getmapping, Aerogrid, IGN, IGP, UPR-EGP, and the GIS User Community'
        });
        
        var Stamen = L.layerGroup();
        Stamen_Watercolor.addTo(Stamen);
        Stamen_Label.addTo(Stamen);

        var baseLayers = {
            "Stamen Watercolor": Stamen,
            "OpenStreetMap": OpenStreetMap_Mapnik,
            "Satellite": Esri_WorldImagery
        };
    
Florent Chehab's avatar
Florent Chehab committed
52
        // End of handling of layers, now let's handle markers.
Florent Chehab's avatar
Florent Chehab committed
53

Florent Chehab's avatar
Florent Chehab committed
54
        var universities_markers = L.markerClusterGroup();
Florent Chehab's avatar
Florent Chehab committed
55
56

        {% for univ in universities %}
Florent Chehab's avatar
Florent Chehab committed
57
58
            L.marker([{{ univ.localization_lat }}, {{ univ.localization_lon }}]).addTo(universities_markers)
            .bindPopup("<b>{{ univ.name }}</b>");
Florent Chehab's avatar
Florent Chehab committed
59
60
        {% endfor %}

Florent Chehab's avatar
Florent Chehab committed
61
62
63
64
65
66
67
68

        // Creation of map
        var mymap = L.map('mapid', {'layers':[Stamen, universities_markers]}).setView([45, 1.2], 4);
        
        L.control.layers(baseLayers).addTo(mymap);


        // Extra feature
Florent Chehab's avatar
Florent Chehab committed
69
70
71
72
73
74
75
76
77
78
79
80
81
        var popup = L.popup();
    
        function onMapClick(e) {
            popup
                .setLatLng(e.latlng)
                .setContent("You clicked the map at " + e.latlng.toString())
                .openOn(mymap);
        }
    
        mymap.on('click', onMapClick);
    </script>
    {% for univ in universities %}
        <p>{{ univ.country.name }}</p>
Florent Chehab's avatar
Florent Chehab committed
82
    {% endfor %}
83
84
{% endblock %}