-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.html
438 lines (391 loc) · 14.3 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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=500px, initial-scale=0.6">
<link rel="manifest" href="/manifest.json">
<link rel="apple-touch-icon" sizes="57x57" href="/apple-touch-icon-57x57.png">
<link rel="apple-touch-icon" sizes="114x114" href="/apple-touch-icon-114x114.png">
<link rel="icon" type="image/png" href="/android-chrome-192x192.png" sizes="192x192">
<meta name="apple-mobile-web-app-title" content="OpenSolarMap">
<meta name="application-name" content="OpenSolarMap">
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.css" />
<link rel="shortcut icon" href="./favicon.ico" type="image/x-icon">
<link rel="icon" href="./favicon.ico" type="image/x-icon">
<script src="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js" charset="utf-8"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/queue-async/1.0.7/queue.min.js"></script>
<script src="js/leaflet-hash.js"></script>
<style>
html, body {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
#map {
width: 100%;
height: 100%;
}
#location {
position: absolute;
top: 0px;
z-index: 7;
right: 0px;
font-size: 18;
color: black;
text-align: right;
background-color: white;
opacity: 0.8;
padding: 10px 10px;
}
#logo {
position: absolute;
z-index: 10;
top: 8px;
left: 8px;
}
#orient {
position: absolute;
z-index: 9;
bottom: 0%;
opacity: 0.8;
background-color: white;
width: 100%;
}
#orient svg {
width: 125px;
margin-left: auto;
margin-right: auto;
cursor:pointer;
cursor:hand;
opacity: 0.5;
}
#orient svg:hover {
opacity: 1.0;
}
#orient1 {
margin-left: auto;
margin-right: auto;
margin-top: 15px;
margin-bottom: 15px;
height: 150px;
width: 500px;
}
#plusone {
position: absolute;
left: 100px;
top: 130px;
z-index: 100;
font-size: 40px;
display: none;
color: #0f0
}
#stats {
position: absolute;
left: 8px;
top: 116px;
background-color: white;
opacity: 0.8;
padding: 10px 10px;
transition: width 1s;
-webkit-transition: width 2s;
}
#social {
position: absolute;
bottom: 8px;
left: 8px;
z-index: 10;
}
</style>
</head>
<body>
<div id="map" style=""></div>
<div id="location"></div>
<div id="logo"><a href="https://cquest.hackpad.com/OpenSolarMap-9oMiYswLksF" target="_blank" title="OpenSolarMap : le projet"><img src="img/opensolarmap.png" width=25%></a></div>
<div id="plusone">+1 !</div>
<div id="stats">
<img src="img//user.png" alt="Vos informations collectées" title="Vos contributions"><div id="count_ip">----</div>
<img src="img/building.png" alt="Bâtiments identifiés" title="Bâtiments identifiés"><div id="count_buildings">----</div>
<img src="img/users.png" alt="Total des informations collectées" title="Total des contributions"><div id="count_total">----</div>
</div>
<div id="social">
<a href="http://www.github.com/opensolarmap" title="Voir le code source sur GitHub"><img src="img/git.png"></a>
<a href="https://www.facebook.com/opensolarmap" title="Page Facebook d'OpenSolarMap"><img src="img/facebook.png"></a>
<a href="http://twitter.com/opensolarmap" title="Compte Twitter d'OpenSolarMap"><img src="img/twitter.png"></a>
<a href="mailto:[email protected]" title="Nous envoyer un email"><img src="img/email.png"></a>
<a href="http://www.votreenergiepourlafrance.fr/1planete-tous-ensemble-pour-le-climat-/" target="_blank"><img src="img/Smile_305x305.png" height=32></a>
</div>
<div id="orient">
<div id="orient1">
<div alt="Ligne de faîte orientée est-ouest" title="Ligne de faîte orientée est-ouest (touche 1)">
<svg style="float: left; display: inline-block" id="rooftype1">
<rect
style="fill:#ffffff;fill-opacity:1;stroke:#000000;stroke-width:4;stroke-linecap:round;stroke-opacity:1;stroke-dasharray:none"
width="90"
height="21"
x="5"
y="-23.5"
transform="matrix(0,1,-1,0,0,0)" />
<path
style="fill:#ffffff;stroke:#000000;stroke-width:4px;stroke-linecap:round;stroke-linejoin:round;stroke-opacity:1"
d="m 100,0 10,50 -10,50 -90,0 L 20,50 10,0 z" />
<path
style="fill:none;stroke:#000000;stroke-width:3px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 20,50 90,0"/>
</svg></div>
<div alt="Ligne de faîte orientée nord-sud" title="Ligne de faîte orientée nord-sud (touche 2)">
<svg style="float: left; display: inline-block" id="rooftype2">
<rect
style="fill:#ffffff;fill-opacity:1;stroke:#000000;stroke-width:4;stroke-linecap:round;stroke-opacity:1;stroke-dasharray:none"
id="rect2993"
width="90"
height="21"
x="5"
y="85" />
<path
style="fill:#ffffff;stroke:#000000;stroke-width:4px;stroke-linecap:round;stroke-linejoin:round;stroke-opacity:1"
d="M 0,10 50,0 100,10 100,100 50,90 0,100 z" />
<path
style="fill:none;stroke:#000000;stroke-width:3px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 50,90 50,0" />
</svg></div>
<div alt="Toit plat" title="Toit plat (touche 3)">
<svg style="float: left; display: inline-block" id="rooftype3">
<path
style="fill:none;stroke:#000000;stroke-width:3px;stroke-linecap:round;stroke-linejoin:round;stroke-opacity:1"
d="M 10,0 0,10 0,110 90,110 100,100 100,0 z" />
<path
style="fill:none;stroke:#000000;stroke-width:3px;stroke-linecap:round;stroke-linejoin:round;stroke-opacity:1"
d="m 10,0 0,100 90,0"/>
<path
style="fill:none;stroke:#000000;stroke-width:3px;stroke-linecap:round;stroke-linejoin:round;stroke-opacity:1"
d="M 10,100 0,110"/>
</svg></div>
<div alt="Forme de toit inconnue ou complexe" title="Forme de toit inconnue ou complexe (touche 4 ou 0)">
<svg style="float: left; display: inline-block" id="rooftype4">
<rect
style="fill:#ffffff;fill-opacity:1;stroke-width:3px;stroke:#000000;stroke-opacity:1"
id="rect2985"
width="100"
height="100"
x="0"
y="0" />
<text
xml:space="preserve"
style="font-size:40px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;font-family:Sans"
x="50"
y="70"
id="text3816"><tspan id="tspan3818" x="50" y="60" style="font-size:56px;text-align:center;text-anchor:middle">?</tspan></text>
</svg></div>
</div>
</div>
<script>
var buildings, building;
var stats_total=0, stats_user=0;
var gJson, mark;
var map = L.map('map',{ zoomControl:false }).setView([30, 0], 3);
var hash = new L.Hash(map);
var api = 'http://api.opensolarmap.org/';
if (window.location.hostname != 'opensolarmap.org') {
L.tileLayer('http://{s}.tiles.mapbox.com/v4/openstreetmap.map-inh7ifmo/{z}/{x}/{y}.png?access_token=pk.eyJ1Ijoib3BlbnN0cmVldG1hcCIsImEiOiJncjlmd0t3In0.DmZsIeOW-3x-C5eX-wAqTw', {
maxZoom: 19,
minZoom: 3,
attribution: 'Imagery © <a href="https://www.mapbox.com/satellite/">Mapbox/DigitalGlobe</a> - Map data © <a href="http://osm.org/copyright">OpenStreetMap contributors</a>'
}).addTo(map);
}
else {
L.tileLayer('http://proxy-ign.openstreetmap.fr/bdortho/{z}/{x}/{y}.jpg', {
maxZoom: 19,
minZoom: 3,
attribution: 'Imagery © BDOrtho IGN - Map data © <a href="http://osm.org/copyright">OpenStreetMap contributors</a>'
}).addTo(map);
}
function getNext(lat, lon) {
if (buildings != undefined && buildings.length>1) {
// get next closest building in the array
best_distance = 1000000;
best_building = 0;
for (b = buildings.length-1; b > 0; b--) {
db = (lon-buildings[b].properties.lon)*(lon-buildings[b].properties.lon) + (lat-buildings[b].properties.lat)*(lat-buildings[b].properties.lat);
if (db==0) {
buildings.splice(b,1);
}
else if (db<best_distance) {
best_distance = db;
best_building = b;
}
}
building = buildings[best_building];
buildings.splice(best_building,1);
showBuilding();
// update statistics locally
stats_total++;
stats_user++;
d3.select("#count_ip").text(stats_user);
d3.select("#count_total").text(stats_total);
}
// get first buildings or more...
if (buildings==undefined || buildings.length<5) {
getStats(); // update statistics
// get buildings to classify...
api_get_building = api+'building?limit=20';
if (lat != undefined && lon != undefined)
api_get_building = api_get_building + '&lat='+lat+'&lon='+lon
queue()
.defer(d3.json, api_get_building)
.await(gotBuilding);
}
}
getNext(); // get first batch of buildings
// get statistics
function getStats() {
queue()
.defer(d3.json, api+'stats')
.await(gotStats);
}
// display statistics when received
function gotStats(error, stats) {
d3.select("#count_total").text(stats.count_total);
d3.select("#count_ip").text(stats.count_ip);
d3.select("#count_buildings").text(stats.count_buildings);
stats_user = stats.count_ip;
stats_total = stats.count_total;
}
// display reverse geocoding result when received
function gotAddr(error, geocode) {
d3.select("#location")
.text(!error && geocode.features && geocode.features.length
? (geocode.features[0].properties.street != undefined
? geocode.features[0].properties.street
: ( geocode.features[0].properties.locality != undefined
? geocode.features[0].properties.locality
: "" )
)
+ " " + geocode.features[0].properties.postcode
+ " " + geocode.features[0].properties.city
: "");
}
// display reverse geocoding result when received
function gotAddrNominatim(error, geocode) {
d3.select("#location")
.text(!error && geocode.address
? (geocode.address.road != undefined
? geocode.address.road
: ( geocode.address.locality != undefined
? geocode.address.locality
: "" )
)
+ " " + geocode.address.postcode
+ " " + (geocode.address.village != undefined ? geocode.address.village : "")
+ " " + (geocode.address.state != undefined ? geocode.address.state : "")
: "");
}
// function to deduplicate any array
Array.prototype.unique = function() {
var a = this.concat();
for(var i=0; i<a.length; ++i) {
for(var j=i+1; j<a.length; ++j) {
if(a[i] === a[j])
a.splice(j--, 1);
}
}
return a;
};
function gotBuilding(error, gjson) {
if (buildings != undefined) {
// on complete la liste en dédupliquant
buildings = buildings.concat(gjson.features).unique();
}
else {
// premier chargement de liste, on affiche le premier batiment
buildings = gjson.features;
building = buildings[0];
buildings.splice(0,1);
showBuilding();
}
}
function pushbutton(that, evt) {
var roof_id = building.properties.id;
if (evt == 'clickevt'){
var rooftype_number = that.id.replace('rooftype', '');
}
else {
var rooftype_number = that;
}
d3.select('#rooftype'+rooftype_number)
.style('opacity', '1')
// POST the user selection to the API
var xhr = new XMLHttpRequest();
xhr.open('POST', api+'building?next=false&id='+building.properties.id+'&type='+rooftype_number);
xhr.onreadystatechange = function() {
if(xhr.readyState == 4 && xhr.status == 200) {
};
};
xhr.send('type=' + rooftype_number + '&id=' + roof_id);
getNext(building.properties.lat, building.properties.lon);
// button back to normal grey
d3.select('#rooftype'+rooftype_number)
.transition()
.duration(1000)
.style('opacity', '0.5');
// +1 animation
d3.select('div#plusone')
.style('font-size', '40px')
.style('display', 'block')
.style('opacity', '1')
.transition()
.duration(1500)
.style('font-size', '200px')
.style('opacity', '0')
.transition().duration(0)
.style('display', 'none');
};
function showBuilding() {
// reverse geocoding query to get location name
if (true) {
queue()
.defer(d3.json, 'http://api-adresse.data.gouv.fr/reverse/?lon='+building.properties.lon+'&lat='+building.properties.lat)
.await(gotAddr);
}
else {
queue()
.defer(d3.json, 'http://nominatim.openstreetmap.org/reverse.php?format=json&lon='+building.properties.lon+'&lat='+building.properties.lat)
.await(gotAddrNominatim);
}
// remove last circle/building footprint
if (mark != undefined) { map.removeLayer(mark); }
if (gJson != undefined) { map.removeLayer(gJson); }
// adjust zoom on building size
zoom = 19;
if (building.properties.radius>50) { zoom=18; }
map.setView(new L.LatLng(building.properties.lat, building.properties.lon), zoom);
// show the building as a dashed footprint
gJson = L.geoJson(building, {style: function (feature) { return {color: 'white', opacity: 0.75, fillOpacity: 0, dashArray: '0.1,10'};},}).addTo(map);
// circle around with additionnal 5m margin
mark = L.circle([building.properties.lat, building.properties.lon], building.properties.radius+10, {color: 'yellow', opacity: 0.75, fillColor: 'yellow', fillOpacity: 0}).addTo(map);
d3.selectAll('#orient svg')
.on('click', function(){pushbutton(this,'clickevt');});
// set keyboard events (1,2,3,4+0) corresponding on rooftype
d3.select("body")
.on("keydown", function() {
if (d3.event.keyCode == 49 || d3.event.keyCode == 97){
pushbutton(1,'keyevt');
}
else if (d3.event.keyCode == 50 || d3.event.keyCode == 98){
pushbutton(2,'keyevt');
}
else if (d3.event.keyCode == 51 || d3.event.keyCode == 99){
pushbutton(3,'keyevt');
}
else if (d3.event.keyCode == 52 || d3.event.keyCode == 100){
pushbutton(4,'keyevt');
}
else if (d3.event.keyCode == 48 || d3.event.keyCode == 96){ // '0' behaves like '4'
pushbutton(4,'keyevt');
};
});
};
</script>
</body>
</html>