-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
646 lines (562 loc) · 21.6 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
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Show It To Me</title>
<style>
* {
margin: 0;
padding: 0;
}
html, body {
width: 100%;
height: 100%;
}
#map {
width: 50%;
height: 90%;
float: left;
}
#tabs {
float: left;
margin: 5px;
width: 400px;
}
#commonsquery {
//float: left;
//margin: 5px;
//width: 400px;
}
#commonsimage {
position: fixed;
display:block;
top: 2em;
right: 2em;
}
.list {
font-size: 9pt;
font-family: sans-serif;
padding-left: 10px;
}
.selected {
font-weight: bold;
}
#overpass-out-debug {
font-size: 10pt;
}
</style>
<script src="jquery.min.js"></script>
<link rel="stylesheet" href="leaflet.css">
<script src="leaflet.js"></script>
<script src="leaflet.restoreview.js"></script>
<script src="leaflet.hash.js"></script>
<link rel="stylesheet" href="leaflet.history.css">
<script src="leaflet.history.js"></script>
<link href="http://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
<link rel="stylesheet" href="leaflet.locate.min.css">
<!--[if lt IE 9]>
<link rel="stylesheet" href="leaflet.locate.ie.min.css">
<![endif]-->
<script src="leaflet.locate.min.js"></script>
<link rel="stylesheet" href="leaflet.geocoder.css">
<script src="leaflet.geocoder.js"></script>
<link rel="stylesheet" href="leaflet.measure.css">
<script src="leaflet.measure.js"></script>
<link rel="stylesheet" href="leaflet.editinosm.css">
<script src="leaflet.editinosm.js"></script>
<link rel="stylesheet" href="jquery-ui.min.css">
<link rel="stylesheet" href="jquery-ui.structure.min.css">
<link rel="stylesheet" href="jquery-ui.theme.min.css">
<script src="jquery-ui.min.js"></script>
</head>
<body>
<div id="map"></div>
<div id="tabs">
<ul>
<li><a href="#tabs-1">Image Query</a></li>
<li><a href="#tabs-2">Commons CatSearch</a></li>
<li><a href="#tabs-3">Overpass API</a></li>
</ul>
<div id="tabs-1">
<div id="#commonsquery">
Lat: <span id="lat"></span><br/>
Lng: <span id="lng"></span><br/>
<input type="text" id="radius" value="500"><br/>
<input type="button" id="query_commons" value="query Commons for images"/><br/>
<input type="button" id="query_mapillary" value="query mapillary for images"/>
<div id="imagelist"></div>
</div>
</div>
<div id="tabs-2">
<input type="button" id="queryCategories" value="Query"/> categories for selected image
<div id="categorylist">(no query yet)</div>
<div id="imagesincategory">
<input type="button" id="queryImagesInCategory" value="Query"/> images in selected category
<div id="imagesincategorylist"></div>
</div>
</div>
<div id="tabs-3">
<input type="button" id="overpassQuery" value="Query"/> Overpass query
<select id="overpass-keys">
<option value="natural">natural</option>
<option value="highway">highway</option>
<option value="amenity">amenity</option>
<option value="leisure">leisure</option>
<option value="landuse">landuse</option>
<!--
<option value=""></option>
-->
</select>
<div id="overpass-out">
<p id="overpass-out-debug"> </p>
<a id="overpass-turbo-link" href="#">[ot]</a>
</div>
</div>
</div>
<div id="commonsimage">(no image yet)</div>
<script>
L.QuadKeyTileLayer = L.TileLayer.extend({
getTileUrl: function (tilePoint) {
this._adjustTilePoint(tilePoint);
return L.Util.template(this._url, {
s: this._getSubdomain(tilePoint),
q: this._quadKey(tilePoint.x, tilePoint.y, this._getZoomForUrl())
});
},
_quadKey: function (x, y, z) {
var quadKey = [];
for (var i = z; i > 0; i--) {
var digit = '0';
var mask = 1 << (i - 1);
if ((x & mask) != 0) {
digit++;
}
if ((y & mask) != 0) {
digit++;
digit++;
}
quadKey.push(digit);
}
return quadKey.join('');
}
});
// from https://www.mapbox.com/mapbox.js/example/v1.0.0/rotating-controlling-marker/
L.RotatedMarker = L.Marker.extend({
options: { angle: 0 },
_setPos: function(pos) {
L.Marker.prototype._setPos.call(this, pos);
if (L.DomUtil.TRANSFORM) {
// use the CSS transform rule if available
this._icon.style[L.DomUtil.TRANSFORM] += ' rotate(' + this.options.angle + 'deg)';
} else if (L.Browser.ie) {
// fallback for IE6, IE7, IE8
var rad = this.options.angle * L.LatLng.DEG_TO_RAD,
costheta = Math.cos(rad),
sintheta = Math.sin(rad);
this._icon.style.filter += ' progid:DXImageTransform.Microsoft.Matrix(sizingMethod=\'auto expand\', M11=' +
costheta + ', M12=' + (-sintheta) + ', M21=' + sintheta + ', M22=' + costheta + ')';
}
}
});
L.rotatedMarker = function(pos, options) {
return new L.RotatedMarker(pos, options);
};
var osmMapnik = new L.TileLayer(
'//{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
{
minZoom: 3,
maxZoom: 19,
attribution: 'Map data © OpenStreetMap contributors'
}
);
var osmOpenTopoMap = new L.TileLayer(
'//server.opentopomap.org/{z}/{x}/{y}.png',
{
minZoom: 3,
maxZoom: 16,
maxNativeZoom: 15,
attribution: 'Kartendaten: © <a href="https://openstreetmap.org/copyright">OpenStreetMap</a>-Mitwirkende, <a href="http://viewfinderpanoramas.org">SRTM</a> | Kartendarstellung: © <a href="https://opentopomap.org">OpenTopoMap</a> (<a href="https://creativecommons.org/licenses/by-sa/3.0/">CC-BY-SA</a>)'
}
);
var bingAerial = new L.QuadKeyTileLayer(
'//ecn.t{s}.tiles.virtualearth.net/tiles/a{q}?g=737&n=z',
{
subdomains: "0123",
minZoom: 3,
maxZoom: 19,
attribution: "<a href=\'http://maps.bing.com/\'>Bing</a> map data copyright Microsoft and its suppliers"
}
);
var hillshading = new L.TileLayer(
'//c.tiles.wmflabs.org/hillshading/{z}/{x}/{y}.png',
{
attribution: "Hillshading by ??? from NASA SRTM data",
minZoom: 3,
maxZoom: 16,
overlay: true
}
);
var map = L.map('map', {
layers: [osmMapnik],
editInOSMControlOptions: {
position: "bottomright",
zoomThreshold: 16,
widget: "attributionBox",
editors: ["josm"]
},
});
var baseMaps = {
"OpenStreetMap": osmMapnik,
"OpenTopoMap": osmOpenTopoMap,
"Bing Aerial View": bingAerial
};
var overlayMaps = {
"Hillshading": hillshading
};
if (!map.restoreView()) {
map.setView([53, 11], 7); // Somewhere in Europe
}
new L.Hash(map);
new L.HistoryControl({
maxMovesToSave: 100
}).addTo(map);
L.control.layers(baseMaps, overlayMaps).addTo(map);
L.control.scale().addTo(map);
L.control.locate({
icon: 'fa fa-location-arrow',
showPopup: false
}).addTo(map);
new L.Control.Measure({
position: 'topleft',
measureUnit: 'km'
}).addTo(map);
var geocoder = new L.Control.Geocoder({
position: "topleft"
}).addTo(map);
//XXX
$( "#tabs" ).tabs();
$("#imagesincategory").hide();
var GEOQUERY_RADIUS = 250;
var LIMIT_RESULTS_TO = 500;
var CIRCLE_OPACITY = 0.5;
var CIRCLE_FILL = 0.5;
var commonsImages;
var commonsCategories;
var selectedImage;
var selectedCategory;
var mapillaryLayer;
var queryCircle = L.circle([0,0],0, { opacity: CIRCLE_OPACITY, fill: CIRCLE_FILL } );
queryCircle.addTo(map);
var queryRect = L.rectangle([[0,0],[0,0]], {color: "darkgrey", fill: false, opacity: 0, clickable: false});
queryRect.addTo(map);
var imageMarker = L.marker([0,0]).addTo(map);
map.on('click', function(e) {
mapclick(e.latlng);
});
$("#radius").on('keyup', function() {
GEOQUERY_RADIUS = $("#radius").val();
queryCircle.setRadius(GEOQUERY_RADIUS);
queryRect.setBounds(queryCircle.getBounds());
updateOverpassQuery();
});
$("#overpass-keys").on('change', function() {
updateOverpassQuery();
});
var imageNameClicked = function() {
// clear previous image
if (selectedImage != undefined) {
// reset css
$("#imagelist li:contains('"+selectedImage.title+"')").removeClass("selected");
$("#imagesincategorylist li:contains('"+selectedImage.title+"')").removeClass("selected");
// remove category list of previous image
$("#categorylist").html("(no query yet)");
}
//hide images in category panel
//$("#imagesincategory").hide();
//enable query categories button
$("#queryCategories").prop("disabled",false);
//set selected image
selectedImage = commonsImages[$(this).text()];
//XXX fails with " in name
$('#imagelist li:contains("'+selectedImage.title+'")').addClass("selected");
$('#imagesincategorylist li:contains("'+selectedImage.title+'")').addClass("selected");
//display thumb
var i = "<a href='"+selectedImage.descpage+"'><img src='"+selectedImage.thumb+"'/></a><p><small>"+selectedImage.artist+"</small></p>";
$("#commonsimage").html(i);
//set marker
var ll = selectedImage.latlng;
if (ll != undefined) {
imageMarker.setLatLng(ll);
} else {
$(this).css("color","red");
}
};
var categoryNameClicked = function() {
// clear previous category
if (selectedCategory != undefined) {
// reset css
$("#categorylist li:contains('"+selectedCategory.title+"')").removeClass("selected");
} else {
// no previously selected category->enable query for images in category
$("#imagesincategory").toggle("blind");
}
selectedCategory = commonsCategories[$(this).text()];
$('#categorylist li:contains("'+selectedCategory.title+'")').addClass("selected");
$("#imagesincategorylist").html("(no query yet)");
};
var mapclick = function(latlng) {
var lat = latlng.lat;
var lng = latlng.lng;
$("#lat").text(lat.toFixed(6));
$("#lng").text(lng.toFixed(6));
queryCircle.setLatLng(latlng);
queryCircle.setRadius(GEOQUERY_RADIUS);
queryRect.setBounds(queryCircle.getBounds());
//$("#overpass-out-debug").text(queryCircle.getBounds()lat+","+);
//$("#overpass-out-debug").text(
updateOverpassQuery();
}
var updateOverpassQuery = function() {
var ot_bbox = "("+
queryCircle.getBounds().getSouthWest().lat.toFixed(6) +"," + queryCircle.getBounds().getSouthWest().lng.toFixed(6) + ","
+ queryCircle.getBounds().getNorthEast().lat.toFixed(6) +"," + queryCircle.getBounds().getNorthEast().lng.toFixed(6)
+")";
var ot_query = "[out:json][timeout:25];(";
// objects with name and chosen key
["node","way","relation"].forEach( function(osmtype) {
ot_query += osmtype+"[\"name\"][\""+$("#overpass-keys").val()+"\"]"+ot_bbox+";";
});
// objects with image tag
["node","way","relation"].forEach( function(osmtype) {
ot_query += osmtype+"[\"image\"]"+ot_bbox+";";
});
ot_query += ");out tags;";
$("#overpass-out-debug").text(ot_query);
$("#overpass-turbo-link").attr("href","http://overpass-turbo.eu?R=1&Q=" + ot_query.replace(/out (ids|tags);/,"/*recurse for display*/(._;>;);out body;"));
}
var queryImageInformation = function(imageArray) {
var imagesString = imageArray.join("|");
console.log(imagesString);
$.ajax( {
url: "https://commons.wikimedia.org/w/api.php",
data: { action:'query',
titles: imagesString,
prop:'imageinfo|coordinates',
iilimit:LIMIT_RESULTS_TO,
iiprop:'url|extmetadata',
iiurlwidth:200,
iiurlheight:200,
colimit:LIMIT_RESULTS_TO,
coprimary: 'all',
format:'json',
},
jsonp: 'callback',
dataType: 'jsonp',
success: function(data,status,xhr) {
var txt = "";
if (data.query == undefined) {
// should not be reached
console.log("Barf! No images???");
} else {
$.each(data.query.pages,
function(i,v) {
fillImageInfo(v);
}
); // end each
}
}, // end success
}) // end ajax
}
// stores in global commonsImages hash
var fillImageInfo = function(apiResultForPage) {
var ll,a;
var thumburl = "images/crystal_error.png";
var descurl = "https://commons.wikimedia.org";
if (apiResultForPage.coordinates != undefined) {
ll = new L.LatLng(apiResultForPage.coordinates[0].lat, apiResultForPage.coordinates[0].lon)
}
if (apiResultForPage.imageinfo != undefined) {
thumburl = apiResultForPage.imageinfo[0].thumburl;
descurl = apiResultForPage.imageinfo[0].descriptionurl;
if (apiResultForPage.imageinfo[0].extmetadata != undefined) {
if (ll == undefined) {
// no camera location given -> use location from extmetadata if exists
if (apiResultForPage.imageinfo[0].extmetadata.GPSLatitude != undefined) {
ll = new L.LatLng(apiResultForPage.imageinfo[0].extmetadata.GPSLatitude.value, apiResultForPage.imageinfo[0].extmetadata.GPSLongitude.value);
} else {
ll = [0,0];
}
}
if (apiResultForPage.imageinfo[0].extmetadata.Artist != undefined) {
a = apiResultForPage.imageinfo[0].extmetadata.Artist.value;
} else {
a = "undefined, see description page";
}
}
}
commonsImages[apiResultForPage.title] = { title: apiResultForPage.title, thumb: thumburl, descpage: descurl, latlng: ll, artist: a};
};
$("#query_commons").on('click', function() {
imageMarker.setLatLng([0,0]);
$("#imagelist").html('<img src="images/throbber.gif">');
$("#imagesincategorylist").html('(no query yet)');
$.ajax( {
url: "https://commons.wikimedia.org/w/api.php",
data: { action:'query',
generator:'geosearch',
ggsprimary:'all',
ggsnamespace:'6',
ggsradius:GEOQUERY_RADIUS,
ggscoord:$("#lat").text() + '|'+$("#lng").text(),
ggslimit:LIMIT_RESULTS_TO,
prop:'imageinfo|coordinates',
iilimit:LIMIT_RESULTS_TO,
iiprop:'url|extmetadata',
iiurlwidth:200,
iiurlheight:200,
colimit:LIMIT_RESULTS_TO,
coprimary: 'all',
format:'json',
},
jsonp: 'callback',
dataType: 'jsonp',
success: function(data,status,xhr) {
var txt = "";
if (data.query == undefined) {
$("#imagelist").html("<i>no images found</i>");
} else {
txt += "<ul class='list'>";
commonsImages = {};
$.each(data.query.pages,
function(i,v) {
fillImageInfo(v);
// append title to list
txt += "<li>"+v.title+"</li>";
}
); // end each
txt += "</ul>";
$("#imagelist").html(txt);
$("#imagelist li").on('click', imageNameClicked);
}
},
}) // end ajax
}); // end onclick handler
$("#queryCategories").on('click', function() {
$("#categorylist").html('<img src="images/throbber.gif">');
var txt = "<ul class='list'>";
$.ajax( {
//api.php?action=query&titles=Image:Commons-logo.svg&prop=categories
url: "https://commons.wikimedia.org/w/api.php",
data: {
action:'query',
titles:selectedImage.title,
prop:'categories',
clshow:'!hidden',
format:'json',
},
jsonp: 'callback',
dataType: 'jsonp',
success: function(data,status,xhr) {
// disable
$("#queryCategories").prop("disabled",true);
commonsCategories = {}
$.each(data.query.pages, function(i,page) {
$.each(page.categories, function(ii,cat) {
txt += "<li>"+cat.title+"</li>";
commonsCategories[cat.title] = { title: cat.title,};
});
}); // end each pages
txt += "</ul>";
$("#categorylist").html(txt);
$("#categorylist li").on('click', categoryNameClicked);
} // end success
}); // end ajax
}); // end onclick
$("#queryImagesInCategory").on('click', function() {
$("#imagesincategorylist").html('<img src="images/throbber.gif">');
var txt = "<ul class='list'>";
$.ajax( {
//action=query&list=categorymembers&cmtype=file|subcat&cmtitle=%s&format=json&cmlimit=%d
url: "https://commons.wikimedia.org/w/api.php",
data: {
action:'query',
list:'categorymembers',
cmtype: 'file|subcat',
cmtitle:selectedCategory.title,
format:'json',
},
jsonp: 'callback',
dataType: 'jsonp',
success: function(data,status,xhr) {
leftoverImages = Array()
$.each(data.query.categorymembers, function(i,categorymember) {
txt += "<li>"+categorymember.title+"</li>";
if (commonsImages[categorymember.title] == undefined) {
leftoverImages = leftoverImages.concat(categorymember.title);
}
}); // end each categorymember
txt += "</ul>";
queryImageInformation(leftoverImages);
$("#imagesincategorylist").html(txt);
$("#imagesincategorylist li").on('click', imageNameClicked);
} // end success
}); // end ajax
}); // end onclick
$("#query_mapillary").on('click', function() {
$.ajax({
url: "https://a.mapillary.com/v3/images",
data: {
client_id: "d3VjeGg1aGdZLVVTUjU1SjBwbmN2dzo4MjA2ZDYwMzg4NzJiMGQz",
closeto: [$("#lng").text(),$("#lat").text()],
radius: GEOQUERY_RADIUS
},
success: function(data,status,xhr) {
if (map.hasLayer(mapillaryLayer)) {
map.removeLayer(mapillaryLayer);
}
var geojsonMarkerOptions = {
radius: 8,
fillColor: "#ff7800",
color: "#000",
weight: 1,
opacity: 1,
fillOpacity: 0.8
};
var micon = L.icon({
iconUrl: 'images/Dark_Green_Arrow_Up_16.png',
iconSize: [16, 16],
iconAnchor: [8, 8],
});
mapillaryLayer = L.geoJson(data, {
pointToLayer: function (feature, latlng) {
//return L.circleMarker(latlng, geojsonMarkerOptions);
return L.rotatedMarker(latlng, {icon:micon, angle: feature.properties.ca});
},
onEachFeature: function(feature,layer) {
layer.on('click', function() {
var i = feature.properties.key;
var i = '<a href="https://www.mapillary.com/app/?pKey='+ feature.properties.key +'&focus=photo"><img src="https://d1cuyjsrcm0gby.cloudfront.net/'+feature.properties.key+'/thumb-320.jpg"/></a>';
i += '<p>Image by '+feature.properties.username+' @ '+feature.properties.captured_at+'</p>';
$("#commonsimage").html(i);
});
}
});
mapillaryLayer.addTo(map)
} // end success
}); // end ajax
}); // end onclick query_mapillary
$("#tabs").on('tabsactivate', function(evt,ui) {
if (ui.newTab.text() == "Overpass API") {
// Overpass-Tab aktiv
queryRect.setStyle({opacity: 1});
queryCircle.setStyle({fill: false, opacity: 0});
} else {
// anderer Tab aktiv
queryRect.setStyle({opacity: 0});
queryCircle.setStyle({fill: true, opacity: CIRCLE_OPACITY});
}
});
//https://commons.wikimedia.org/w/api.php?action=query&generator=search&gsrsearch=Steinberg&gsrnamespace=6&prop=info&gsrlimit=30
</script>
</body>
</html>