-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.html
431 lines (296 loc) · 12.2 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
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Wikimapia Export</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<link href="css/stylish-portfolio.css" rel="stylesheet">
<link rel="stylesheet" href="src/leaflet/leaflet.css" />
<link rel="stylesheet" href="src/bootstrap-3.3.6-dist/css/bootstrap.min.css" />
<link rel="stylesheet" href="src/leaflet-search-master/dist/leaflet-search.min.css" />
<link rel="stylesheet" href="css/main.css" />
</head>
<body>
<script src="src/categories.js"></script>
<script src="src/leaflet/leaflet.js"></script>
<script src='src/jquery/jquery-1.11.3.min.js'></script>
<script src="src/bootstrap-3.3.6-dist/js/bootstrap.min.js"></script>
<script src="src/turf/turf.min.js"></script>
<script src="src/spin/spin.min.js"></script>
<script src="src/bootstrap3-typeahead.js"></script>
<script src="src/leaflet-search-master/dist/leaflet-search.min.js"></script>
<div class="container-fluid">
<div class="alert alert-info alert-dismissible fade in" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>Welcome to the Wikimapia export tool ! This application simplifies the use of the <a href="http://wikimapia.org/api">Wikimapia API</a> and allows you to query and export (in GeoJSON) this rich geographical database.
</div>
<div class="row">
<div class="col-md-4">
<form class="form">
<div class="form-group">
<label for="key" >Wikimapia API Key</label>
<span class="glyphicon glyphicon-question-sign" data-toggle="tooltip" data-placement="right" title="You can let "example", it will work but you will have to wait a few time between each query, or you can request your own key on the Wikimapia website" aria-hidden="true"></span>
<input type="text" class="form-control" id="key" placeholder="example" >
</div>
<div class="form-group">
<label for="categoryId">Category </label> | <a href="#" data-toggle="modal" data-target="#myModal">See full list</a>
<input type="text" class="form-control" id="categoryId" placeholder="" data-provide="typeahead" data-items="4">
</div>
<div class="form-group col-xs-3">
</div>
<div class="form-group col-xs-6 pagination-centered text-center">
<label for="ex1">Top</label>
<input disabled class="form-control inputsm" id="top" type="text">
</div>
<br>
<br>
<br>
<br>
<div class="form-group col-xs-6 pagination-centered text-center">
<label for="ex1">Left</label>
<input disabled class="form-control inputsm" id="left" type="text">
</div>
<div class="form-group col-xs-6 pagination-centered text-center">
<label for="ex1">Right</label>
<input disabled class="form-control inputsm" id="right" type="text">
</div>
<div class="form-group col-xs-3">
</div>
<div class="form-group col-xs-6 pagination-centered text-center">
<label for="ex1">Bottom</label>
<input disabled class="form-control inputsm" id="bottom" type="text">
</div>
<div>
<button type="button" class="btn btn-success" onclick="run()">Run query</button><br>
</div>
</form>
</div>
<div class="col-md-8">
<div id="map">
<div id="shadow">
</div>
<div id="spin_div">
</div>
</div>
<em id="warningzoom" style="color:red"></em>
</div>
</div>
<br>
<div id="alertsucess" class="alert alert-success">
<b id="number_returned"><strong>Success!</strong> The query returned 10 features.</b> | <a id="export_points" ></a> | <a id="export_poly" ></a>
</div>
<div id="alert100" class="alert alert-warning">
<strong>Warning!</strong> The query returned the maximum number of features (100). Try to reduce your area of interest or divide it in several queries.
</div>
</div>
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Category List</h4>
</div>
<div class="modal-body">
<table id="category_table" class="table table-striped">
<thead>
<tr>
<th>#</th>
<th>Category name</th>
<th>Id</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<script>
$(function () {
$('[data-toggle="tooltip"]').tooltip()
})
$("#alert100").hide();
$("#alertsucess").hide();
$("#spin_div").hide();
$("#shadow").hide();
for (var i in dict){
var row ='<tr><td>'+dict[i].use+'</td><td>'+dict[i].Name+'</td><td>'+dict[i].Id+'</td></tr>';
$("#category_table").append(row);
}
var type_choices =[];
for (var i in dict){type_choices.push(dict[i].Name)}
$("#categoryId").typeahead({
source: type_choices
});
var poly = [];
var poly_geojson = L.geoJson();
var centro = [];
var centro_geojson = L.geoJson();
var map = L.map('map').setView([45.588866,5.92363 ], 2);
var OpenStreetMap_HOT = L.tileLayer('https://{s}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png', {
maxZoom: 19,
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a>, Tiles courtesy of <a href="http://hot.openstreetmap.org/" target="_blank">Humanitarian OpenStreetMap Team</a>'
}).addTo(map);
var Esri_WorldImagery = L.tileLayer('https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}', {
attribution: 'Tiles © Esri — Source: Esri, i-cubed, USDA, USGS, AEX, GeoEye, Getmapping, Aerogrid, IGN, IGP, UPR-EGP, and the GIS User Community'
});
var baseMaps = {
"OSM HOT": OpenStreetMap_HOT,
"Esri World Imagery": Esri_WorldImagery
};
L.control.layers(baseMaps).addTo(map);
var mapbounds = map.getBounds();
document.getElementById("key").value = "example";
//document.getElementById("categoryId").value = "hospital";
document.getElementById("top").value = mapbounds._northEast.lat;
document.getElementById("right").value = mapbounds._northEast.lng;
document.getElementById("bottom").value = mapbounds._southWest.lat;
document.getElementById("left").value = mapbounds._southWest.lng;
map.on('move', function(e) {
var mapbounds = map.getBounds();
document.getElementById("top").value = mapbounds._northEast.lat;
document.getElementById("right").value = mapbounds._northEast.lng;
document.getElementById("bottom").value = mapbounds._southWest.lat;
document.getElementById("left").value = mapbounds._southWest.lng;
});
map.on('zoomend', function(e) {
var mapzoom = map.getZoom();
if (mapzoom < 7){warningzoom.innerHTML = "Area too big, the query will probably not work or return 0 features"}
else{warningzoom.innerHTML = ""}
console.log(mapzoom);
})
function run() {
if (document.getElementById("categoryId").value == '') {alert("Please enter a category")}
else {
$("#spin_div").show();
$("#shadow").show();
$("#alertsucess").hide();
$("#alert100").hide();
export_points.innerHTML = "";
export_poly.innerHTML = "";
poly = [];
poly_fc = [];
poly_geojson.clearLayers();
centro = [];
centro_fc = [];
centro_geojson.clearLayers();
var key = document.getElementById("key").value;
var categoryId = document.getElementById("categoryId").value;
var categoryId_number;
var top = document.getElementById("top").value;
var right = document.getElementById("right").value;
var bottom = document.getElementById("bottom").value;
var left = document.getElementById("left").value;
for (var i in dict) {
if(categoryId == dict[i].Name){categoryId_number = dict[i].Id}
else{}
}
var queryUrl = "http://api.wikimapia.org/?key="+key+"&function=box&coordsby=bbox&bbox="+left+"%2C"+bottom+"%2C"+right+"%2C"+top+"&category="+categoryId_number+"&count=100&format=json";
console.log(queryUrl)
$.getJSON( queryUrl, function( data ) {
console.log(data);
if (!data.folder) {
if(data.debug[0]){
alert(data.debug[0].message);
$("#spin_div").hide();
$("#shadow").hide();
}
else{alert(data.debug.message);
$("#spin_div").hide();
$("#shadow").hide();}
} else{
$("#alertsucess").show();
if (data.folder.length == 1) {number_returned.innerHTML = "<strong>Success!</strong> The query returned "+data.folder.length+" feature.";}
else {number_returned.innerHTML = "<strong>Success!</strong> The query returned "+data.folder.length+" features.";}
if (data.folder.length == 100) { $("#alert100").show(); } else{$("#alert100").hide();}
for ( var i in data.folder){
var item = data.folder[i];
var coordinates = [];
item.polygon[item.polygon.length] = item.polygon[0];
for (var y in item.polygon){
item2 = item.coordinates;
coordinates.push([item.polygon[y].x,item.polygon[y].y]);
}
var sourceLang = item.language_iso;
var transUrl = "https://translate.google.fr/?hl=en#"+sourceLang+"/en/"+encodeURI(item.name)+""
poly.push(turf.polygon([coordinates],{"name":item.name, "type":categoryId, "sourceLang": sourceLang,"transUrl": transUrl}));
}
for (var i in poly) {
centro.push(turf.centroid(poly[i]));
centro[i].properties.name = poly[i].properties.name;
centro[i].properties.transUrl = poly[i].properties.transUrl;
centro[i].properties.sourceLang = poly[i].properties.sourceLang;
centro[i].properties.type = categoryId;
}
poly_geojson = L.geoJson(poly,{
onEachFeature(feature, layer) {
if (feature.properties.sourceLang == "en") {layer.bindPopup("<h4>"+feature.properties.name+"</h4>")}
else {layer.bindPopup("<h4>"+feature.properties.name+"</h4>")}
}
}).addTo(map);
centro_geojson = L.geoJson(centro,{
onEachFeature(feature, layer) {
if (feature.properties.sourceLang == "en") {layer.bindPopup("<h4>"+feature.properties.name+"</h4>")}
else {layer.bindPopup("<h4>"+feature.properties.name+"</h4>")}
}
}).addTo(map);
var centro_fc = turf.featurecollection(centro);
var poly_fc = turf.featurecollection(poly);
var data_centro = "text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(centro_fc));
var data_poly = "text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(poly_fc));
$('<a href="data:' + data_centro + '" download="'+categoryId+'_points.geojson">Export as points</a>').appendTo('#export_points');
$('<a href="data:' + data_poly + '" download="'+categoryId+'_poly.geojson">Export as polygons</a>').appendTo('#export_poly');
$("#spin_div").hide();
$("#shadow").hide();
}})
.fail(function() {
alert( "error, please retry later" );
})
}
}
var opts = {
lines: 13 // The number of lines to draw
, length: 28 // The length of each line
, width: 14 // The line thickness
, radius: 42 // The radius of the inner circle
, scale: 1 // Scales overall size of the spinner
, corners: 1 // Corner roundness (0..1)
, color: '#fff' // #rgb or #rrggbb or array of colors
, opacity: 0.25 // Opacity of the lines
, rotate: 0 // The rotation offset
, direction: 1 // 1: clockwise, -1: counterclockwise
, speed: 1 // Rounds per second
, trail: 60 // Afterglow percentage
, fps: 20 // Frames per second when using setTimeout() as a fallback for CSS
, zIndex: 2e9 // The z-index (defaults to 2000000000)
, className: 'spinner' // The CSS class to assign to the spinner
, top: '50%' // Top position relative to parent
, left: '50%' // Left position relative to parent
, shadow: false // Whether to render a shadow
, hwaccel: false // Whether to use hardware acceleration
, position: 'absolute' // Element positioning
}
var target = document.getElementById('spin_div')
var spinner = new Spinner(opts).spin(target);
map.addControl( new L.Control.Search({
url: 'http://nominatim.openstreetmap.org/search?format=json&q={s}',
jsonpParam: 'json_callback',
propertyName: 'display_name',
propertyLoc: ['lat','lon'],
circleLocation: false,
markerLocation: false,
autoType: false,
autoCollapse: true,
minLength: 2,
zoom:10
}) );
//var translate = doGet(sourceText, sourceLang, targetLang);
</script>
</body>
</html>