-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
975 lines (842 loc) · 37.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
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
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>教会と駅ー未伝道地が見える宣教地図 : インフォグラフィックス : クリスチャントゥデイ</title>
<meta name="description" content="「教会と駅」は、全国の教会が近くにない駅を可視化し、開拓宣教の候補地を考える際の参考情報を提供するために考案されたインターネット上の地図です。">
<meta name="news_keywords" content="教会,開拓,開拓宣教,日本宣教,宣教学,宣教地図,GIS,駅,乗降者数,データジャーナリズム,キリスト教データジャーナリズム,クリスチャントゥデイ"/>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta property="fb:app_id" content="1625923791071391"/>
<meta rel="canonical" href="https://www.christiantoday.co.jp/infographics/church-station/"/>
<meta property="og:type" content="website">
<meta property="og:site_name" content="クリスチャントゥデイ"/>
<meta property="og:title" content="教会と駅ー未伝道地が見える宣教地図:クリスチャントゥデイ"/>
<meta property="og:description" content="「教会と駅」は、全国の教会が近くにない駅を可視化し、開拓宣教の候補地を考える際の参考情報を提供するために考案されたインターネット上の地図です。"/>
<meta property="og:url" content="https://www.christiantoday.co.jp/infographics/church-station/"/>
<meta property="og:image" content="https://www.christiantoday.co.jp/infographics/church-station/social-card.jpg"/>
<meta name="twitter:site" content="chtodayjp"/>
<meta name="twitter:card" content="summary_large_image"/>
<meta name="twitter:image" content="https://www.christiantoday.co.jp/infographics/church-station/social-card.jpg"/>
<meta property="twitter:title" content="教会と駅ー未伝道地が見える宣教地図:クリスチャントゥデイ"/>
<meta property="syndication-source"
content="https://www.christiantoday.co.jp/infographics/church-station/"/>
<meta name="robots" content="index, follow"/>
<meta name="Googlebot-news" content="index, follow"/>
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no"/>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-2400048-12"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag('js', new Date());
gtag('config', 'UA-2400048-12');
</script>
<script src="https://api.mapbox.com/mapbox-gl-js/v2.0.1/mapbox-gl.js"></script>
<link href="https://api.mapbox.com/mapbox-gl-js/v2.0.1/mapbox-gl.css" rel="stylesheet"/>
<!--<script src='https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-language/v0.10.1/mapbox-gl-language.js'></script>-->
<script src='mapbox-gl-language.js'></script>
<script src="https://cdn.jsdelivr.net/npm/sharer.js@latest/sharer.min.js"></script>
<style>
body {
margin: 0;
padding: 0;
}
#map {
position: absolute;
top: 0;
bottom: 0;
width: 100%;
z-index: 1;
}
/* menu start */
#menu {
position: absolute;
background: #000;
color: #fff;
padding: 10px 10px 20px 5px;
opacity: 0.6;
font-family: 'Open Sans', sans-serif;
font-size: 13px;
z-index: 2;
}
img { /* CTJ Logo */
margin-top: 10px;
}
#title-text { /* Church & Station */
text-align: center;
}
ul { /* distance switcher */
list-style: none;
padding: 0;
margin: 0;
}
.button { /* language switcher */
cursor: pointer;
margin-top: 10px;
margin-left: 10px;
}
.tooltip #tooltiptext { /* user guide text */
visibility: hidden;
width: 120px;
background-color: black;
color: #fff;
text-align: center;
border-radius: 6px;
padding: 5px 0;
/* Position the tooltip */
position: absolute;
z-index: 1;
top: 100px;
left: 105%;
}
.tooltip:hover #tooltiptext {
visibility: visible;
}
/* social button start */
.social-share-buttons {
margin: 18px 0px 0px 4px;
}
svg {
display: inline-block;
justify-content: space-evenly;
height: 18px;
}
path {
fill: white;
}
/* social button end */
/* menu end */
#info {
top: 0;
right: 50px;
position: absolute;
background: #fff;
color: #000;
padding: 0 10px 0 10px;
opacity: 0.6;
font-family: 'Open Sans', sans-serif;
font-size: 9px;
z-index: 2;
}
/* bottom bar start */
.atribution #miltatribution {
visibility: hidden;
/*width: 300px;*/
background-color: black;
color: #fff;
text-align: center;
border-radius: 6px;
padding: 5px 5px;
/* Position the tooltip */
position: absolute;
z-index: 1;
bottom: 12px;
left: 1px;
}
.atribution:hover #miltatribution {
visibility: visible;
}
/* bottom bar end */
</style>
</head>
<body>
<div id="map">
<div id="menu">
<a href="https://www.christiantoday.co.jp">
<img id="logo" src="https://www.christiantoday.co.jp/views/img/logo-small.png">
</a>
<h3>
<div id="title-text"></div>
</h3>
<div class="tooltip">
<ul>
<li><input id="500" type="radio" name="rtoggle" value="streets" checked="checked"/>
<label for="500">500m</label></li>
<li><input id="1000" type="radio" name="rtoggle" value="light"/>
<label for="1000">1000m</label></li>
<li><input id="1500" type="radio" name="rtoggle" value="dark"/>
<label for="1500">1500m</label></li>
<li><input id="2000" type="radio" name="rtoggle" value="outdoors"/>
<label for="2000">2000m</label></li>
<li><input id="2500" type="radio" name="rtoggle" value="satellite"/>
<label for="2500">2500m</label></li>
<li><input id="3000" type="radio" name="rtoggle" value="satellite"/>
<label for="3000">3000m</label></li>
</ul>
<span id="tooltiptext"></span>
</div>
<ul class="language" id="buttons">
<li id='button-ja' class='button'>日本語</li>
<li id='button-ko' class='button'>한국어</li>
<li id='button-en' class='button'>English</li>
</ul>
<div class="social-share-buttons">
<svg id="facebook-share" data-sharer="facebook"
data-url="https://www.christiantoday.co.jp/infographics/church-station/#map=5.48/37.165/137/-40/60&wd=500"
role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
<title id="facebook-share-text"></title>
<path d="M24 12.073c0-6.627-5.373-12-12-12s-12 5.373-12 12c0 5.99 4.388 10.954 10.125 11.854v-8.385H7.078v-3.47h3.047V9.43c0-3.007 1.792-4.669 4.533-4.669 1.312 0 2.686.235 2.686.235v2.953H15.83c-1.491 0-1.956.925-1.956 1.874v2.25h3.328l-.532 3.47h-2.796v8.385C19.612 23.027 24 18.062 24 12.073z"/>
</svg>
<svg id="twitter-share" data-sharer="twitter"
data-url="https://www.christiantoday.co.jp/infographics/church-station/#map=5.48/37.165/137/-40/60&wd=500"
role="img" viewBox="0 0 24 24"
xmlns="http://www.w3.org/2000/svg">
<title id="twitter-share-text"></title>
<path d="M23.953 4.57a10 10 0 01-2.825.775 4.958 4.958 0 002.163-2.723c-.951.555-2.005.959-3.127 1.184a4.92 4.92 0 00-8.384 4.482C7.69 8.095 4.067 6.13 1.64 3.162a4.822 4.822 0 00-.666 2.475c0 1.71.87 3.213 2.188 4.096a4.904 4.904 0 01-2.228-.616v.06a4.923 4.923 0 003.946 4.827 4.996 4.996 0 01-2.212.085 4.936 4.936 0 004.604 3.417 9.867 9.867 0 01-6.102 2.105c-.39 0-.779-.023-1.17-.067a13.995 13.995 0 007.557 2.209c9.053 0 13.998-7.496 13.998-13.985 0-.21 0-.42-.015-.63A9.935 9.935 0 0024 4.59z"/>
</svg>
<svg id="line-share" data-sharer="line" data-title=""
data-url="https://www.christiantoday.co.jp/infographics/church-station/#map=5.48/37.165/137/-40/60&wd=500"
role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
<title id="line-share-text"></title>
<path d="M19.365 9.863c.349 0 .63.285.63.631 0 .345-.281.63-.63.63H17.61v1.125h1.755c.349 0 .63.283.63.63 0 .344-.281.629-.63.629h-2.386c-.345 0-.627-.285-.627-.629V8.108c0-.345.282-.63.63-.63h2.386c.346 0 .627.285.627.63 0 .349-.281.63-.63.63H17.61v1.125h1.755zm-3.855 3.016c0 .27-.174.51-.432.596-.064.021-.133.031-.199.031-.211 0-.391-.09-.51-.25l-2.443-3.317v2.94c0 .344-.279.629-.631.629-.346 0-.626-.285-.626-.629V8.108c0-.27.173-.51.43-.595.06-.023.136-.033.194-.033.195 0 .375.104.495.254l2.462 3.33V8.108c0-.345.282-.63.63-.63.345 0 .63.285.63.63v4.771zm-5.741 0c0 .344-.282.629-.631.629-.345 0-.627-.285-.627-.629V8.108c0-.345.282-.63.63-.63.346 0 .628.285.628.63v4.771zm-2.466.629H4.917c-.345 0-.63-.285-.63-.629V8.108c0-.345.285-.63.63-.63.348 0 .63.285.63.63v4.141h1.756c.348 0 .629.283.629.63 0 .344-.282.629-.629.629M24 10.314C24 4.943 18.615.572 12 .572S0 4.943 0 10.314c0 4.811 4.27 8.842 10.035 9.608.391.082.923.258 1.058.59.12.301.079.766.038 1.08l-.164 1.02c-.045.301-.24 1.186 1.049.645 1.291-.539 6.916-4.078 9.436-6.975C23.176 14.393 24 12.458 24 10.314"/>
</svg>
</div>
</div>
<div id="info">
<div>
<strong><span id="mesh-population-box-label"></span> </strong>
<strong>2010:</strong> <span id='2010'></span>
<strong>2025:</strong> <span id='2025'></span>
<strong>2040:</strong> <span id='2040'></span>
</div>
</div>
</div>
<script>
var layerList = document.getElementById('menu');
function detectBrowserLocale() {
return navigator.languages ? navigator.languages[0] : (navigator.language || navigator.userLanguage);
}
function detectBrowserLanguage(browserLocale) {
var language = browserLocale;
var parts = language.split('-');
var languageCode = language;
if (parts.length > 1) {
languageCode = parts[0];
}
if (['ar', 'en', 'es', 'fr', 'de', 'ja', 'ko', 'mul', 'pt', 'ru', 'zh'].indexOf(languageCode) > -1) {
return languageCode;
}
return 'ja';
}
const socialPlatforms = ["facebook", "twitter", "line"];
function capitalize(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
function switchLanguage(languageToSwitch) {
var titleText = document.getElementById('title-text');
var logo = document.getElementById('logo');
var toolTip = document.getElementById('tooltiptext');
var miltAttribution = document.getElementById('miltatribution');
var meshPopulationBoxLabel = document.getElementById('mesh-population-box-label');
switch (languageToSwitch) {
case 'ja':
titleText.innerText = "教会と駅";
logo.setAttribute("title", "クリスチャントゥデイ");
let jaDesc = "教会と駅ー未伝道地が見える宣教地図";
document.title = jaDesc + " : インフォグラフィックス : クリスチャントゥデイ";
toolTip.innerText = "1日あたり乗降者数1000人以上で、教会が指定した範囲にない駅を青の四角柱で、ある駅をオレンジの四角柱で表示しています。四角柱の高さは乗降者数を表しています。";
meshPopulationBoxLabel.innerText = "100mメッシュ人口";
miltAttribution.innerText = "国土交通省国土数値情報駅別乗降客数データを加工して作成";
socialPlatforms.forEach(function (item, index) {
document.querySelector(`#${item}-share-text`).textContent = `${capitalize(item)}で共有`;
});
document.getElementById("line-share").setAttribute("data-title", jaDesc);
break;
case 'ko':
titleText.innerText = "교회와역";
logo.setAttribute("title", "일본크리스천투데이");
let koDesc = "교회와역ー미전도 지역이 보이는 선교지도";
document.title = koDesc + " : 인포 그래픽 : 일본크리스천투데이";
meshPopulationBoxLabel.innerText = "100m메시 인구";
toolTip.innerText = "하루 승강 자수 1000 명 이상 교회가 지정한 범위에없는 역을 파란색 사각형 기둥에있는 역 오렌지색 직사각형 기둥으로 표시하고 있습니다. 사각 기둥의 높이가 승강 인원을 나타냅니다.";
miltAttribution.innerText = "일본 정부 국토 교통성 국토 수치 정보 역 별 승강 객수 데이터를 가공하여 만든";
socialPlatforms.forEach(function (item, index) {
document.querySelector(`#${item}-share-text`).textContent = `${capitalize(item)}에서 공유`;
});
document.getElementById("line-share").setAttribute("data-title", koDesc);
break;
case 'en':
titleText.innerHTML = "Church<br><span>&</span><br>Station"
logo.setAttribute("title", "Christian Today Japan");
let enDesc = "Church and Station - Mission Map Visualizing Unreached Area";
document.title = enDesc + " : Infographics : Christian Today Japan";
meshPopulationBoxLabel.innerText = "100m grid square population";
toolTip.innerText = "Stations with more than 1000 passengers per day without church(es) in the specified distance are represented as blue square pillars, stations with churches are in orange. Heights are the number of passengers.";
miltAttribution.innerText = "Station Data powered by National Land Information Division, National Spatial Planning and Regional Policy Bureau, Ministry of Land, Infrastructure and Tourism of Japan";
socialPlatforms.forEach(function (item, index) {
document.querySelector(`#${item}-share-text`).textContent = `Share with ${capitalize(item)}`;
});
document.getElementById("line-share").setAttribute("data-title", enDesc);
break;
}
}
var browserLocale = detectBrowserLocale();
var labels = layerList.getElementsByTagName("label");
// localization for distance unit widely used only in United States
if (browserLocale === "en-US") {
console.log("browser locale is en-US");
for (var i = 0; i < labels.length; i++) {
let inMeters = labels[i].getAttribute("for");
let inMiles = inMeters * 0.000621371;
labels[i].innerText = inMiles.toFixed(2) + "mi";
}
}
var detectedBrowserLanguage = detectBrowserLanguage(browserLocale);
console.log("browser language is " + detectedBrowserLanguage);
let hash = window.location.hash;
var hasHash = false;
var walkingDistanceInHash = 500;
var needsToAddHashWalkingDistanceParameter = true;
if (hash) {
hasHash = true;
if (hash.includes("&wd=")) {
walkingDistanceInHash = parseInt(hash.split("&wd=")[1]);
console.log("hash found and custom walking distance detected as " + walkingDistanceInHash);
needsToAddHashWalkingDistanceParameter = true;
} else {
console.log("hash found but custom walking distance NOT detected, defaults to " + walkingDistanceInHash);
}
} else {
console.log("hash NOT found walking distance defaults to " + walkingDistanceInHash);
}
//ref: https://stackoverflow.com/questions/56760727/how-to-observe-a-change-in-the-url-using-javascript
(function () {
var rs = history.replaceState;
history.replaceState = function () {
rs.apply(history, arguments); // preserve normal functionality
console.log("Hash change detected. Updating social share uri to ", arguments[2]); // do something extra here; raise an event
for (const platform of socialPlatforms) {
let shareButton = document.getElementById(`${platform}-share`);
var url = arguments[2];
if (!url.includes("http")) {
url = "https://www.christiantoday.co.jp/infographics/church-station/" + url;
}
shareButton.setAttribute("data-url", url);
}
};
}());
// default variables for vertical viewports
var mapPitch = 60;
var mapBearing = 30;
var mapBoundary = [
[129, 29], // okinawa, south west corner of Japan
[138, 38] // hokkaido, north east corner of Japan
];
if (window.innerWidth > window.innerHeight) {
console.log("viewport is horizontal, fit pitch and bearing");
mapPitch = 60;
mapBearing = -40;
mapBoundary = [
[132, 32],
[142, 42]
];
} else {
console.log("viewport is vertical, keep current pitch and bearing")
}
mapboxgl.accessToken = 'pk.eyJ1IjoibmVoZW1pYWhhcmNoaXZlIiwiYSI6ImNramp6OXN2bDF0OGgyeHRnMjB6ZmdianYifQ.ixrqFAV8JKIMyO5Pz8cvJw';
var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/light-v10', //streets-v11 //dark-v9
center: [138, 36],
zoom: 5.5,
pitch: mapPitch,
antialias: true,
attributionControl: false,
hash: "map"
});
let hashinoriginalurl = window.location.hash
if (hasHash) {
console.log("Hash fragment exists, do not fit bounds " + hashinoriginalurl);
} else {
console.log("Hash fragment doesn't exist, fit bounds to default " + hashinoriginalurl);
map.fitBounds(mapBoundary);
}
var mapboxLanguage = new MapboxLanguage();
map.addControl(mapboxLanguage);
var distanceToHide = "NOT_SELECTED";
const base_url = 'https://raw.githubusercontent.com/nehemiaharchives/cpsd/master/data/japan/';
const bottomLayerId = 'road-label';
map.on('load', function () {
if (hasHash) {
console.log("Hash fragment exists, do not ease");
} else {
console.log("Hash fragment doesn't exist, ease to default");
map.easeTo({
bearing: mapBearing,
duration: 5000
});
}
if (detectedBrowserLanguage != "en") {
console.log("browser language is not English, switching to browser language");
map.setStyle(mapboxLanguage.setLanguage(map.getStyle(), detectedBrowserLanguage));
}
map.addControl(new mapboxgl.AttributionControl({
compact: false,
customAttribution: [
"<a href=\"https://www.christiantoday.co.jp/\">© Christian Today Japan</a>",
"<a href=\"https://home.csis.u-tokyo.ac.jp/~nishizawa/teikyo/index.html\" target=\"_blank\" >© Akira Nishizawa</a>",
"<a href=\"http://agu-econ.maps.arcgis.com/apps/webappviewer/index.html?id=00804e1e1beb45e1864c5f24a65fd40d\" target=\"_blank\" >© Takashi Inoue</a>",
"<span class=\"atribution\"><a href=\"https://nlftp.mlit.go.jp/ksj/gml/datalist/KsjTmplt-S12-v2_3.html\" target=\"_blank\" >© MLIT of Japan</a><span id=\"miltatribution\"></span></div>"
]
}));
map.addControl(new mapboxgl.NavigationControl());
map.addControl(new mapboxgl.FullscreenControl());
map.addSource('1000m-mesh', {
'type': 'vector',
'url': 'mapbox://nehemiaharchive.1000m-mesh-points'
});
map.addLayer({
'id': '1000m-mesh',
'source': '1000m-mesh',
'source-layer': '1000m-mesh-points',
"minzoom": 3,
"maxzoom": 9,
'type': 'circle',
'paint': {
'circle-color': "#53d8fd",
'circle-pitch-alignment': 'map',
'circle-radius': [
'interpolate',
['linear'],
['zoom'],
// zoom, radius
6, 1,
7, 1.5,
8, 2.5,
9, 3
],
'circle-opacity': [
'interpolate',
['linear'],
['zoom'],
// zoom, opacity
5, 0.3,
7.99, 0.4,
8, 0.2,
9, 0.1
]
}
}, bottomLayerId);
map.addSource('500m-mesh', {
'type': 'vector',
'url': 'mapbox://nehemiaharchive.500m-mesh-points'
});
map.addLayer({
'id': '500m-mesh',
'source': '500m-mesh',
'source-layer': '500m-mesh-points',
"minzoom": 8,
"maxzoom": 11,
'type': 'circle',
'paint': {
'circle-color': "#53d8fd",
'circle-pitch-alignment': 'map',
'circle-radius': [
'interpolate',
['linear'],
['zoom'],
// zoom, radius
8, 3,
9, 4,
10, 6,
11, 7
],
'circle-opacity': [
'interpolate',
['linear'],
['zoom'],
// zoom, opacity
8, 0.1,
9.5, 0.2,
10, 0.13,
10.5, 0.14,
11, 0.1
]
}
}, bottomLayerId);
map.addSource('all-church', {
'type': 'geojson',
'data': `${base_url}all-church.json`
});
map.addLayer({
'id': 'all-church',
'type': 'circle',
'source': 'all-church',
'paint': {
'circle-color': '#f89c2a',
'circle-pitch-alignment': 'map',
'circle-radius': 2,
'circle-opacity': [
'interpolate',
['linear'],
['zoom'],
// zoom, opacity
8, 0.6,
9.9, 0.6,
10, 0.3,
14, 0.6,
16, 0.8,
18, 1
]
}
}, bottomLayerId);
map.addSource("mapbox-transit", {
"url": "mapbox://mapbox.transit-v2",
"type": "vector"
});
map.addLayer({
"id": "transit_line_line",
"source": "mapbox-transit",
"source-layer": "transit_line",
"type": "line",
"filter": [
"==",
"$type",
"LineString"
],
"paint": {
"line-width": [
'interpolate',
['linear'],
['zoom'],
// zoom, radius
9, 2,
11, 2.5,
13, 3,
15, 3.5,
17, 5,
19, 7
],
"line-color": "rgba(66,100,251, 0.3)"
}
});
map.addLayer({
'id': 'train_station_names',
'type': 'symbol',
'source': {
type: 'vector',
url: 'mapbox://mapbox.mapbox-streets-v8'
},
'source-layer': 'transit_stop_label',
"minzoom": 11,
layout: {
"text-field": ["coalesce", ["get", `name_${detectedBrowserLanguage}`], ["get", "name"]]
},
filter: ["==", "stop_type", "station"]
})
switchLanguage(detectedBrowserLanguage);
if (needsToAddHashWalkingDistanceParameter) {
let hashToBeReplaced = window.location.hash + "&wd=" + walkingDistanceInHash;
history.replaceState(undefined, undefined, hashToBeReplaced)
}
renderChurchesAndStations(walkingDistanceInHash);
});
function renderChurchesAndStations(distanceToShow) {
let hashHead = window.location.hash.split("&wd=")[0];
history.replaceState(undefined, undefined, `${hashHead}&wd=${distanceToShow.toString()}`);
if (map.getLayer(walkingDistanceInHash + "-station-polygon-without-church") === undefined) {
console.log("default layer not found, nothing to un-hide, initial loading");
if (walkingDistanceInHash != 500) {
console.log("default walking distance is NOT 500, switch checked input box to " + walkingDistanceInHash);
document.getElementById("500").checked = false;
document.getElementById(walkingDistanceInHash.toString()).checked = true;
} else {
console.log("default walking distance is 500, keep checked input box");
}
fetchGeoJson(walkingDistanceInHash);
distanceToHide = walkingDistanceInHash;
} else {
hideLayer(distanceToHide);
console.log("500 found, already initiated, checking if distanceToShow already loaded");
if (map.getLayer(`${distanceToShow}-station-polygon-without-church`) === undefined) {
console.log(distanceToShow + " was not loaded yet, loading");
fetchGeoJson(distanceToShow);
} else {
console.log(distanceToShow + " was already loaded, showing");
showLayer(distanceToShow);
}
distanceToHide = distanceToShow;
}
console.log("renderChurchesAndStations finished")
renderMeshPopulation(distanceToShow)
map.setPaintProperty('all-church', 'circle-radius', [
'interpolate',
['linear'],
['zoom'],
// zoom, radius
5, 2,
6, 3,
8, ["*", (distanceToShow * 0.002), 2],
8.5, ["*", (distanceToShow * 0.002), 2.6],
9, ["*", (distanceToShow * 0.002), 3.7],
9.5, ["*", (distanceToShow * 0.002), 5.1],
10, ["*", (distanceToShow * 0.002), 7.5],
10.5, ["*", (distanceToShow * 0.002), 10.8],
10.6, 5,
11, 7,
13, 9,
15, 11,
17, 13,
19, 15
]);
map.moveLayer("train_station_names")
let layers = map.getStyle().layers
console.log("all layers rendered")
}
const minZoomValue100mMeshPolygonLayer = 14;
function renderMeshPopulation(reach) {
if (typeof reach === 'string') {
reach = parseInt(reach);
}
let meshPopulationColor = ["case",
["==", ['get', 'reach'], null], "#53d8fd",
["<=", ['get', 'reach'], reach], "#fd853a",
"#53d8fd"];
if (map.getLayer('100m-mesh') === undefined) {
console.log("mesh layer not found, initial loading for reach:" + reach);
let meshPopulationYear = 2025;
map.addSource('100m-mesh', {
'type': 'vector',
'url': 'mapbox://nehemiaharchive.100m-mesh-population-reach'
});
map.addLayer({
'id': '100m-mesh',
'source': '100m-mesh',
'source-layer': '100m-mesh-population-reach',
"minzoom": minZoomValue100mMeshPolygonLayer,
'type': 'fill-extrusion',
'paint': {
'fill-extrusion-color': meshPopulationColor,
'fill-extrusion-height': ["*", ["sqrt", ['get', 'P' + meshPopulationYear + 'TT']], 10], //['get', 'P2010TT']
'fill-extrusion-opacity': 0.4
}
}, bottomLayerId);
map.addSource('100m-mesh-points', {
'type': 'vector',
'url': 'mapbox://nehemiaharchive.100m-mesh-points-reach'
});
map.addLayer({
'id': '100m-mesh-points',
'source': '100m-mesh-points',
'source-layer': '100m-mesh-points-reach',
"minzoom": 10,
"maxzoom": 15,
'type': 'circle',
'paint': {
'circle-color': meshPopulationColor,
'circle-pitch-alignment': 'map',
'circle-radius': [
'interpolate',
['linear'],
['zoom'],
// zoom, radius
10, 1.5,
11, 2,
12, 5,
13, 7,
14, 12,
14.5, 17,
15, 20
],
'circle-opacity': [
'interpolate',
['linear'],
['zoom'],
// zoom, opacity
10, 0.4,
11, 0.5,
12, 0.4,
14, 0.5,
14.5, 0.2,
15, 0.1
]
}
}, bottomLayerId);
} else {
console.log("mesh layer found, setting layer paint properties for reach:" + reach);
map.setPaintProperty('100m-mesh', 'fill-extrusion-color', meshPopulationColor);
map.setPaintProperty('100m-mesh-points', 'circle-color', meshPopulationColor);
}
console.log("renderMeshPopulation finished")
}
function fetchGeoJson(distance) {
//500-station-polygon-without-church.json
map.addSource(`${distance}-station-polygon-without-church`, {
'type': 'geojson',
'data': `${base_url}${distance}-station-polygon-without-church.json`
});
map.addLayer({
'id': `${distance}-station-polygon-without-church`,
'type': 'fill-extrusion',
'source': `${distance}-station-polygon-without-church`,
'paint': {
'fill-extrusion-color': "#53d8fd",
'fill-extrusion-height': ["*", ["sqrt", ['get', 'passengers']], 10],
'fill-extrusion-opacity': 0.53
}
}, bottomLayerId);
//500-station-polygon-with-church.json
map.addSource(`${distance}-station-polygon-with-church`, {
'type': 'geojson',
'data': `${base_url}${distance}-station-polygon-with-church.json`
})
map.addLayer({
'id': `${distance}-station-polygon-with-church`,
'type': 'fill-extrusion',
'source': `${distance}-station-polygon-with-church`,
'paint': {
'fill-extrusion-color': "#fd853a",
'fill-extrusion-height': ["*", ["sqrt", ['get', 'passengers']], 10],
'fill-extrusion-opacity': 0.53
}
}, bottomLayerId)
//500-route.json
map.addSource(`${distance}-route`, {
'type': 'geojson',
'data': `${base_url}${distance}-route.json`
});
map.addLayer({
'id': `${distance}-route`,
'type': 'line',
'source': `${distance}-route`,
'paint': {
'line-color': '#fc8b45',
'line-width': [
'interpolate',
['linear'],
['zoom'],
// zoom, radius
9, 2,
11, 2.5,
13, 3,
15, 3.5,
17, 5,
19, 7
],
'line-opacity': 0.58
}
}, bottomLayerId);
//500-church.json
map.addSource(`${distance}-church`, {
'type': 'geojson',
'data': `${base_url}${distance}-church.json`
});
map.addLayer({
'id': `${distance}-church`,
'type': 'circle',
'source': `${distance}-church`,
'paint': {
'circle-color': '#f89c2a',
'circle-radius': 3,
'circle-opacity': 0.5
}
}, bottomLayerId);
//500-station-point-without-church.json
map.addSource(`${distance}-station-point-without-church`, {
'type': 'geojson',
'data': `${base_url}${distance}-station-point-without-church.json`
});
map.addLayer({
'id': `${distance}-station-point-without-church`,
'type': 'circle',
'source': `${distance}-station-point-without-church`,
'paint': {
'circle-color': '#425bfa',
'circle-radius': [
'interpolate',
['linear'],
['zoom'],
// zoom, radius
3, 1,
6, 2
],
'circle-opacity': 0.4
}
}, bottomLayerId)
}
const layerPostFixList = [
'-station-point-without-church',
'-church',
'-route',
'-station-polygon-with-church',
'-station-polygon-without-church'
];
function hideLayer(distanceToHide) {
layerPostFixList.forEach(postFix => {
map.setLayoutProperty(`${distanceToHide}${postFix}`, 'visibility', 'none');
});
}
function showLayer(distanceToShow) {
layerPostFixList.forEach(postFix => {
map.setLayoutProperty(`${distanceToShow}${postFix}`, 'visibility', 'visible');
});
}
function switchLayer(layer) {
var layerId = layer.target.id;
console.log("calling renderChurchesAndStations with " + layerId);
renderChurchesAndStations(layerId);
}
var reachChangerInputCheckBoxes = layerList.getElementsByTagName('input');
for (var i = 0; i < reachChangerInputCheckBoxes.length; i++) {
reachChangerInputCheckBoxes[i].onclick = switchLayer;
}
document.getElementById('buttons').addEventListener('click', function (event) {
var targetLanguage = event.target.id.substr('button-'.length);
map.setStyle(mapboxLanguage.setLanguage(map.getStyle(), targetLanguage));
map.setLayoutProperty('train_station_names', 'text-field', ["coalesce", ["get", `name_${targetLanguage}`], ["get", "name"]]);
switchLanguage(targetLanguage);
});
// configure information box on the right top corner to show mesh population
function showOrHideMeshPopulationBox() {
let infoBox = document.getElementById('info')
if (map.getZoom() >= minZoomValue100mMeshPolygonLayer) {
infoBox.style.display = "block";
} else {
infoBox.style.display = "none";
}
}
// for initial loading in case shared by link
showOrHideMeshPopulationBox();
map.on('zoom', () => {
showOrHideMeshPopulationBox();
});
let meshID = null;
map.on('mousemove', '100m-mesh', (event) => {
map.getCanvas().style.cursor = 'pointer';
const p2010TT = event.features[0].properties.P2010TT;
const p2025TT = event.features[0].properties.P2025TT;
const p2040TT = event.features[0].properties.P2040TT;
// Check whether features exist
if (event.features.length === 0) return;
// Display population in the sidebar
document.getElementById('2010').textContent = (Math.round(p2010TT * 10) / 10).toString();
document.getElementById('2025').textContent = (Math.round(p2025TT * 10) / 10).toString();
document.getElementById('2040').textContent = (Math.round(p2040TT * 10) / 10).toString();
// If meshID for the hovered feature is not null,
// use removeFeatureState to reset to the default behavior
if (meshID) {
map.removeFeatureState({
id: meshID,
source: '100m-mesh',
sourceLayer: '100m-mesh-population-reach'
});
}
meshID = event.features[0].id;
// When the mouse moves over the 100m-mesh layer, update the
// feature state for the feature under the mouse
map.setFeatureState(
{
id: meshID,
source: '100m-mesh',
sourceLayer: '100m-mesh-population-reach'
},
{
hover: true
}
);
});
</script>
</body>
</html>