-
Notifications
You must be signed in to change notification settings - Fork 14
/
maj_population_2017_dept.html
202 lines (199 loc) · 5.48 KB
/
maj_population_2017_dept.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
<html>
<head>
<meta charset="UTF-8">
<script src="js/jquery-2.1.1.min.js"></script>
<script src="js/jquery.tablesorter.min.js"></script>
<link rel="stylesheet" href="css/tablesorter.css" type="text/css"/>
<style>
body{
font-family: monospace;
}
#bandeau{
top:0px;
width:100%;
height:70px;
z-index:3;
position:fixed;
background-color:white;
}
#reponse{
position:absolute;
top:80px;
z-index:2;
}
#credits{
background:darkgrey;
position:fixed;
bottom:0px;
width:100%;
overflow:visible;
z-index:4;
text-align: justify;
}
#pied_de_page{
position:relative;
width:100%;
height:30px;
z-index:3;
}
#wait_ajax{
position:fixed;
z-index:1;
width:100%;
height:100%;
background-color:lightgray;
opacity:0;
text-align:center;
}
#wait_ajax span{
background-color:black;
vertical-align:middle;
font-size:30px;
line-height:500px;
color:white;
border:50px solid black;
}
#table_population tr td{
background:white;
color:black;
font-weight: normal;
}
#table_population tr td.zone_click{
cursor:pointer;
color:blue;
text-decoration: underline;
}
#table_population tr td.zone_click.clicked{
background-color:green;
color:white;
}
table.tablesorter thead tr .header {
height:40px;
}
</style>
<script>
var menu_labels
var commune_valide = false
var osm_state
var titre = "Population 2017 des communes OSM par département"
function is_valid_dept(d){
pattern_dept = new RegExp('^([01]|[3-8])([0-9])$|^2([aAbB]|[1-9])$|^9([0-5]|7[1-4]|76)$')
res = false
if (pattern_dept.test(d)){
res = d
}
return res
}
function check_url_for_dept(){
var res
if (window.location.hash){
if (window.location.hash.split('dept=')[1]){
if (is_valid_dept(window.location.hash.split('dept=')[1].split('&')[0])){
res = window.location.hash.split('dept=')[1].split('&')[0]
} else {
alert(window.location.hash.split('dept=')[1].split('&')[0]+' n\'est pas un numero de département valide\n\nAbandon')
}
}
}
return res
}
function check_form_for_dept(){
res = false
if (is_valid_dept($('#input_dept')[0].value)){
res = $('#input_dept')[0].value
} else {
alert($('#input_dept')[0].value+' n\'est pas un numero de département valide\n\nAbandon')
}
return res
}
function start(){
document.title = titre
dept = check_url_for_dept()
if (dept){
$('#input_dept').empty()
$('#input_dept')[0].value = dept
requete_population();
}
}
function requete_population(){
if (check_form_for_dept()){
dept = $('#input_dept')[0].value
document.title = titre+' ('+dept+')'
$('body').css('cursor','progress');
$('#wait_ajax').empty()
.css('z-index','20')
.css('opacity','0.8')
.append($('<span>').append('Recherche des communes pas à jour...'));
$.ajax({
url: "requete_par_dept.py?requete=maj_population_2017&dept="+dept,
})
.done(function( data ){
nom_dept = data[0][0][1]
data = data[1]
titre_bandeau = ' communes pas encore à jour'
if (data.length == 1){
titre_bandeau = ' commune pas encore à jour'
}
if (data.length == 0){
titre_bandeau = ' commune restante, bravo !'
}
$('#bandeau h1').empty().append($('<span>').append($('<a>').attr('href','maj_population_2017.html').text('France'))).append($('<span>').text(' > '+nom_dept+' : '+data.length+titre_bandeau))
$('#wait_ajax').append($('<span>').append("Ok"));
$('body').css('cursor','default');
$('#wait_ajax').css('z-index','1').css('opacity','0');
add_header('table_population',true)
$('#table_population').append($('<tbody>'))
table = 'table_population'
for (l=0;l<data.length;l++){
//INSEE
$('#'+table).append($('<tr>').attr('id',l).append($('<td>').text(data[l][1])))
//Nom
$('#'+table+' tr:last').append($('<td>').text(data[l][2]))
//Population
$('#'+table+' tr:last').append($('<td>').text(data[l][3]))
//JOSM
add_josm_link(table,data[l][0],data[l][3])
}
$('#table_population').tablesorter();
})
window.location.hash="#dept="+$('#input_dept')[0].value
}
};
function add_josm_link(table,rel_id,population){
$('#'+table+' tr:last').append($('<td>')
.addClass('zone_click')
.text('JOSM')
.click(function(){
$('<img>').appendTo($('#josm_target')).attr('src','http://127.0.0.1:8111/load_object?new_layer=false&relation_members=true&objects=r'+rel_id+'&addtags=population='+population+'%7Csource:population=INSEE 2020');
$(this).addClass('clicked');
})
)
}
function add_header(table,with_edit_and_map_links){
$('#'+table).empty().append($('<thead>').append($('<tr>').append($('<th>').append('Code INSEE'))))
$('#'+table+' tr').append($('<th>').append('Commune'))
$('#'+table+' tr').append($('<th>').append('Population légale 2017'))
$('#'+table+' tr').append($('<th>').append('Édition'))
}
</script>
</head>
<body onload="start()">
<div id="bandeau">
<form action="javascript:requete_population()" autocomplete="on">
<input type="text" id="input_dept" placeholder="N° de département"></input>
<input type="submit" value="Afficher">
</form>
<h1></h1>
<!-- <h2></h2> -->
</div>
<div id="reponse">
<table id="table_population" class="tablesorter"></table>
<div id="pied_de_page"></div>
</div>
<div id="credits">
Données OpenStreetMap : © les Contributeurs d'OpenStreetMap <a href="http://opendatacommons.org/licenses/odbl/">Licence ODbL</a>
</div>
<div id="josm_target" style="visibility : hidden"></div>
<div id="wait_ajax"></div>
</body>
</html>