-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.html
180 lines (165 loc) · 9.56 KB
/
index.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
<!DOCTYPE html>
<html>
<head>
<title>Pouvons-nous nous rencontrer ?</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="description" content="Pouvons-nous nous rencontrer ?">
<link rel="icon" type="image/png" href="favicon.ico"/>
<link rel="apple-touch-icon" href="apple-touch-icon.png"/>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css"
integrity="sha512-xwE/Az9zrjBIphAcBb3F6JVqxf46+CDLwfLMHloNu6KEQCAWi6HcDUbeOfBIptF7tcCzusKFjFw2yuvEpDL9wQ=="
crossorigin=""/>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<link href="https://fonts.googleapis.com/css2?family=Roboto+Condensed:wght@300;400;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.2/css/all.css" integrity="sha384-oS3vJWv+0UjzBfQzYUhtDYW+Pj2yciDJxpsK1OYPAYjqT085Qq/1cq5FLXAZQ7Ay" crossorigin="anonymous">
<link rel="stylesheet" href="./index.css" />
</head>
<body>
<div class="main">
<div class="locations">
<div class="location__container">
<h1>Pouvons-nous nous rencontrer ?</h1>
<div class="locations__form">
<form>
<div class="form-group input-group">
<label><i class="fas fa-crosshairs"></i>Ma localisation</label>
<input id="location-1" type="text" class="form-control input-location" placeholder="Renseignez votre localisation">
</div>
<div class="form-group input-field">
<label><i class="fas fa-map-marker-alt"></i>Localisation de mon proche #1</label>
<input id="location-2" type="text" class="form-control input-location" placeholder="Renseignez la localisation de votre proche">
</div>
<div class="more-locations" id="more-locations">
<div class="more-locations-entry">
<div class="form-group input-field">
<label><i class="fas fa-map-marker-alt"></i>Localisation de mon proche #2</label>
<input id="location-3" type="text" class="form-control input-location" placeholder="Renseignez la localisation de votre proche">
</div>
<div class="form-group input-field">
<label><i class="fas fa-map-marker-alt"></i>Localisation de mon proche #3</label>
<input id="location-4" type="text" class="form-control input-location" placeholder="Renseignez la localisation de votre proche">
</div>
</div>
<a class="more-link" href="#" title="Plus de localisations">
<i class="fas fa-plus-circle more"></i>
<i class="fas fa-minus-circle less"></i>
<span class="more">Plus</span> <span class="less">Moins</span> de localisations
</a>
</div>
</form>
</div>
<div class="presentation">
<p>En raison de l'épidémie de COVID-19, il est interdit de se déplacer à plus de 10km de son domicile sans une autorisation spécifique, sur tout ou partie du territoire.</p>
<p>Cet outil vous permet de renseigner votre localisation ainsi que celle d'un ou plusieurs proches et de simuler la possibilité d'une rencontre !</p>
</div>
</div>
</div>
<div class="map">
<div id="map"></div>
</div>
</main>
<script src="https://cdnjs.cloudflare.com/ajax/libs/autocomplete.js/0.37.1/autocomplete.min.js"></script>
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"
integrity="sha512-gZwIG9x3wUXg2hdXF6+rVkLF/0Vi9U8D2Ntg4Ga5I5BZpVkVxlJWbSQtXPSiUTtC0TjtGOmxa1AJPuV0CPthew=="
crossorigin=""></script>
<script>
var map = L.map('map').setView([46.227638, 2.213749], 5);
L.tileLayer('https://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer/tile/{z}/{y}/{x}', {
attribution: '© ESRI contributors'
}).addTo(map);
var featureGroup = L.featureGroup([]).addTo(map);
var locations = {}
var locationNamesAndColors = {
"location-1" : "#45a2cc",
"location-2" : "#455FCC",
"location-3" : "#CC6F45",
"location-4" : "#B245CC"
}
var callbackLocation = function(event, suggestion, dataset, context, locationName){
var latitude = suggestion.geometry.coordinates[1];
var longitude = suggestion.geometry.coordinates[0];
var marker1 = L.marker([latitude, longitude]);
var circle1 = L.circle([latitude, longitude], {
color: locationNamesAndColors[locationName],
fillColor: locationNamesAndColors[locationName],
fillOpacity: 0.25,
radius: 10000
});
locations[locationName] = {
"marker": marker1,
"circle": circle1
};
featureGroup.remove();
featureGroup = L.featureGroup([]).addTo(map);
Object.keys(locations).forEach(function(locationKey) {
var location = locations[locationKey];
location.marker.addTo(featureGroup);
location.circle.addTo(featureGroup);
})
map.fitBounds(featureGroup.getBounds());
var url = new URL(window.location.href);
url.searchParams.set(locationName, suggestion.properties.label);
history.pushState({}, '', url);
}
var createLocationLabel = function(item){
if (item.properties.type === 'municipality') {
return item.properties.label + ' (' + item.properties.postcode + ')'
} else {
return item.properties.label
}
}
var setAutocomplete = function(locationLabel){
autocomplete('#' + locationLabel, { hint: false }, [
{
source: function(query, callback) {
fetch('https://api-adresse.data.gouv.fr/search/?q=' + query + '&limit=10')
.then(function(res) {
return res.json()
})
.then(function(response) {
callback(response.features)
})
},
displayKey: function(item) {
return createLocationLabel(item);
},
templates: {
suggestion: function(item) {
return createLocationLabel(item);
},
empty: `<div class="aa-suggestion aa-suggestion-empty">Aucune correspondance...</div>`
}
}
]).on('autocomplete:selected', function(event, suggestion, dataset, context){
callbackLocation(event, suggestion, dataset, context, locationLabel);
});
}
Object.keys(locationNamesAndColors).forEach(
function(locationName){
var url = new URL(window.location.href);
var locationURLParameter = url.searchParams.get(locationName);
if(locationURLParameter){
fetch('https://api-adresse.data.gouv.fr/search/?q=' + locationURLParameter + '&limit=1')
.then(function(response) {
return response.json();
})
.then(function(json){
if(json.features.length > 0){
var item = json.features[0];
callbackLocation({},item,{},{},locationName);
document.getElementById(locationName).value = createLocationLabel(item);
}
});
}
setAutocomplete(locationName);
}
);
// Toggle menu
document.querySelector('.more-link').addEventListener('click', function(e) {
var element = document.getElementById("more-locations");
element.classList.toggle("show");
});
</script>
</body>
</html>