-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
950 lines (875 loc) · 33.8 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
<html>
<head>
<title>産総研 シームレス標高タイル(統合DEM)+CS立体図</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script src="https://unpkg.com/maplibre-gl@4.7.1/dist/maplibre-gl.js"></script>
<link href="https://unpkg.com/maplibre-gl@4.7.1/dist/maplibre-gl.css" rel="stylesheet" />
<script src="https://unpkg.com/pmtiles@2.11.0/dist/index.js"></script>
<script src="https://unpkg.com/@maplibre/maplibre-gl-geocoder@1.2.0/dist/maplibre-gl-geocoder.min.js"></script>
<link rel="stylesheet" href="https://unpkg.com/@maplibre/maplibre-gl-geocoder@1.2.0/dist/maplibre-gl-geocoder.css"
type="text/css" />
<style>
body {
margin: 0;
}
#map {
height: 100%;
width: 100%;
}
.map-overlay {
font: bold 12px/14px "Helvetica Neue", Arial, Helvetica, sans-serif;
position: absolute;
width: 180px;
bottom: 20px;
left: 0;
padding: 10px;
}
.map-overlay .map-overlay-inner {
background-color: #fff;
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
border-radius: 3px;
padding: 10px;
margin-bottom: 10px;
}
.map-overlay label {
display: block;
margin: 0 0 0px;
font-size: 12px;
top: 100px;
left: 10px;
display: block;
margin-bottom: 5px;
}
.map-overlay input {
background-color: transparent;
display: inline-block;
width: 100%;
position: relative;
margin: 0;
cursor: ew-resize;
}
.maplibregl-popup .maplibregl-popup-content {
padding: 8px 10px;
font: 12px/14px Arial, Helvetica, sans-serif;
color: black;
background: white;
background: rgba(255, 255, 255, 0.8);
box-shadow: 0 0 15px rgba(0, 0, 0, 0.4);
border-radius: 5px;
width: 280px;
height: auto;
/*overflow: scroll;*/
}
.maplibregl-ctrl-geocoder {
font-size: 14px;
line-height: 12px;
font-family: "Open Sans", "Helvetica Neue", Arial, Helvetica, sans-serif;
position: relative;
background-color: #fff;
width: 80%;
min-width: 100px;
z-index: 1;
border-radius: 5px;
transition: width 0.25s, min-width 0.25s;
box-shadow: 0 0 15px rgba(0, 0, 0, 0.2);
}
.maplibregl-ctrl-geocoder .suggestions {
font-size: 14px;
}
#info {
padding: 6px 8px;
font: 12px/14px Arial, Helvetica, sans-serif;
color: navy;
background: rgba(255, 255, 255, 0.8);
box-shadow: 0 0 15px rgba(0, 0, 0, 0.2);
border-radius: 5px;
width: fit-content;
position: absolute;
top: 10px;
left: 10px;
z-index: 10;
}
.yubi {
cursor: pointer;
z-index: 10;
}
.checkbox-button-container {
display: flex;
flex-direction: column;
justify-content: start;
}
.column {
display: flex;
flex-direction: column;
margin-right: 20px;
}
.map-center-marker {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
font-size: 30px;
pointer-events: none;
}
.coords-display {
position: absolute;
font: bold 12px/14px "Helvetica Neue", Arial, Helvetica, sans-serif;
bottom: 125px;
left: 0px;
margin: 10px;
padding: 5px;
background: rgba(255, 255, 255, 1);
border-radius: 5px;
font-size: 12px;
z-index: 1;
}
</style>
</head>
<body>
<div id="map"></div>
<div class="map-center-marker">+</div>
<div class="coords-display" id="coords"></div>
<div id="info">
<details>
<summary class="yubi">
<strong>CS立体図</strong>
</summary>
<fieldset>
<div class="checkbox-button-container">
<div class="column">
<div>
<input type="checkbox" id="fukushima-cs" value="fukushima-cs" />
<label for="fukushima-cs">福島県CS立体図</label>
</div>
<div>
<input type="checkbox" id="tochigi-cs" value="tochigi-cs" />
<label for="tochigi-cs">栃木県CS立体図</label>
</div>
<div>
<input type="checkbox" id="tokyo-23ku-cs" value="tokyo-23ku-cs" />
<label for="toyko-23ku-cs">東京都(区部)CS立体図</label>
</div>
<div>
<input type="checkbox" id="tokyo-tama-cs" value="tokyo-tama-cs" />
<label for="toyko-tama-cs">東京都(多摩地域)CS立体図</label>
</div>
<div>
<input type="checkbox" id="tokyo-shima-cs" value="tokyo-shima-cs" />
<label for="toyko-shima-cs">東京都(島しょ地域)CS立体図</label>
</div>
<div>
<input type="checkbox" id="kanagawa-cs" value="kanagawa-cs" checked />
<label for="kanagawa-cs">神奈川県CS立体図</label>
</div>
<div>
<input type="checkbox" id="noto-cs" value="noto-cs" />
<label for="noto-cs">能登(石川県)CS立体図(林野庁)</label>
</div>
<div>
<input type="checkbox" id="noto-cs-test" value="noto-test" />
<label for="noto-cs-test">能登(石川県)CS立体図(個人)</label>
</div>
<div>
<input type="checkbox" id="nagano-cs" value="nagano-cs" />
<label for="nagano-cs">長野県CS立体図</label>
</div>
<div>
<input type="checkbox" id="gifu-cs" value="gifu-cs" />
<label for="gifu-cs">岐阜県CS立体図</label>
</div>
<div>
<input type="checkbox" id="shizuoka-cs" value="shizuoka-cs" />
<label for="shizuoka-cs">静岡県CS立体図</label>
</div>
<div>
<input type="checkbox" id="osaka-cs" value="osaka-cs" />
<label for="osaka-cs">大阪府CS立体図</label>
</div>
<div>
<input type="checkbox" id="hyogo-cs" value="hyogo-cs" />
<label for="hyogo-cs">兵庫県CS立体図</label>
</div>
<div>
<input type="checkbox" id="wakayama-cs" value="wakayama-cs" />
<label for="wakayama-cs">和歌山県CS立体図</label>
</div>
<div>
<input type="checkbox" id="okayama-cs" value="okayama-cs" />
<label for="okayama-cs">岡山県CS立体図</label>
</div>
<div>
<input type="checkbox" id="hiroshima-cs" value="hiroshima-cs" />
<label for="hiroshima-cs">広島県CS立体図(林野庁0.5m)</label>
</div>
<div>
<input type="checkbox" id="hiroshima-05m-cs" value="hiroshima-05m-cs" />
<label for="hiroshima-05m-cs">広島県CS立体図(広島県0.5m)</label>
</div>
<div>
<input type="checkbox" id="hiroshima-1m-cs" value="hiroshima-1m-cs" />
<label for="hiroshima-1m-cs">広島県CS立体図(広島県1m)</label>
</div>
<div>
<input type="checkbox" id="ehime-cs" value="ehime-cs" />
<label for="ehime-cs">愛媛県CS立体図</label>
</div>
<div>
<input type="checkbox" id="kochi-cs" value="kochi-cs" />
<label for="kochi-cs">高知県CS立体図</label>
</div>
<div>
<input type="checkbox" id="kumamoto-oita-cs" value="kumamoto-oita-cs" />
<label for="kumamoto-oita-cs">熊本県・大分県CS立体図</label>
</div>
</div>
</div>
</fieldset>
<summary class="yubi">
<strong>各種レイヤー</strong>
</summary>
<fieldset>
<div class="checkbox-button-container">
<div class="column">
<div>
<input type="checkbox" id="landslide" value="landslide" />
<label for="landslide">地すべり地形分布図</label>
<label id="open-legend-landslide" style="text-decoration: underline; cursor: pointer">凡例</label>
</div>
<div>
<input type="checkbox" id="moj-xml" value="moj-xml" />
<label for="moj-xml">法務省地図XML(2024年)</label>
</div>
<div>
<input type="checkbox" id="plateau-lod1" value="plateau-lod1" />
<label for="plateau-lod1">3D都市モデルPLATEAU建築物LOD1(123都市)</label>
</div>
</div>
</div>
</fieldset>
</details>
</div>
<div class="map-overlay top">
<div class="map-overlay-inner">
<label>CS立体図 不透明度:
<span id="cs-slider-opacity-value">80%</span></label>
<input id="cs-slider-opacity" type="range" min="0" max="100" step="1" value="80" />
<label>陰影起伏図 不透明度:
<span id="hillshade-slider-opacity-value">0%</span></label>
<input id="hillshade-slider-opacity" type="range" min="0" max="100" step="1" value="0" />
</div>
</div>
<script type="module">
// Protocolの設定
let protocol = new pmtiles.Protocol();
maplibregl.addProtocol('pmtiles', (request) => {
return new Promise((resolve, reject) => {
const callback = (err, data) => {
if (err) {
reject(err);
} else {
resolve({ data });
}
};
protocol.tile(request, callback);
});
});
// マップの初期化
const map = new maplibregl.Map({
container: "map",
style: "./style/mono.json",
zoom: 9.92,
minZoom: 1,
maxZoom: 17.99,
pitch: 0,
bearing: 0,
maxPitch: 85,
center: [139.359, 35.3965],
hash: true,
attributionControl: false,
});
//ジオコーダー(国土地理院 地名検索API)
var geocoder_api = {
forwardGeocode: async (config) => {
const features = [];
const Text_Prefix = config.query.substr(0, 3);
try {
let request =
"https://msearch.gsi.go.jp/address-search/AddressSearch?q=" +
config.query;
const response = await fetch(request);
const geojson = await response.json();
for (var i = 0; i < geojson.length; i++) {
if (geojson[i].properties.title.indexOf(Text_Prefix) !== -1) {
let point = {
type: "Feature",
geometry: {
type: "Point",
coordinates: geojson[i].geometry.coordinates,
},
place_name: geojson[i].properties.title,
properties: geojson[i].properties,
text: geojson[i].properties.title,
place_type: ["place"],
center: geojson[i].geometry.coordinates,
};
features.push(point);
}
}
} catch (e) {
console.error(`Failed to forwardGeocode with error: ${e}`);
}
return {
features: features,
};
},
};
map.addControl(
new MaplibreGeocoder(geocoder_api, { maplibregl: maplibregl }),
"top-right"
);
// ズーム・回転
map.addControl(new maplibregl.NavigationControl());
// フルスクリーンモードのオンオフ
map.addControl(new maplibregl.FullscreenControl());
// 現在位置表示
map.addControl(
new maplibregl.GeolocateControl({
positionOptions: {
enableHighAccuracy: false,
},
fitBoundsOptions: { maxZoom: 18 },
trackUserLocation: true,
showUserLocation: true,
})
);
// スケール表示
map.addControl(
new maplibregl.ScaleControl({
maxWidth: 200,
unit: "metric",
})
);
// Attributionを折りたたみ表示
map.addControl(
new maplibregl.AttributionControl({
compact: true,
customAttribution:
'(<a href="https://twitter.com/shi__works" target="_blank">X(旧Twitter)</a> | <a href="https://github.com/shiwaku/aist-dem-with-cs-map-on-maplibre" target="_blank">Github</a>) ',
})
);
// 3D地形コントロール表示
map.addControl(
new maplibregl.TerrainControl({
source: 'aist-dem-terrain-rgb',
exaggeration: 1 // 標高を強調する倍率
})
);
map.on("load", () => {
// 産総研 シームレス標高タイルソース
map.addSource("aist-dem-terrain-rgb", {
type: 'raster-dem',
tiles: ["https://gbank.gsj.jp/seamless/elev/terrainRGB/mixed/{z}/{y}/{x}.png"],
attribution: '<a href="https://tiles.gsj.jp/tiles/elev/tiles.html" target="_blank">産総研 シームレス標高タイル(統合DEM)</a>',
tileSize: 256
});
// 産総研 シームレス標高タイルセット
// map.setTerrain({ 'source': 'aist-dem-terrain-rgb', 'exaggeration': 1 });
// 法務省地図XML(PMTiles)ソース
map.addSource("moj-xml", {
type: "vector",
url: "pmtiles://https://data.source.coop/smartmaps/amx-2024-04/MojMap_amx_2024.pmtiles",
// url: "pmtiles://https://pmtiles-data.s3.ap-northeast-1.amazonaws.com/moj-xml/MojMap_amx_2024.pmtiles",
attribution: '<a href="https://github.com/amx-project">法務省地図XML(amx-project)</a>'
});
// 筆レイヤ(ポリゴン)
map.addLayer({
"id": "fude-polygon",
"source": "moj-xml",
"source-layer": "fude",
"type": "fill",
"layout": {
"visibility": "none",
},
"paint": {
'fill-color': '#FFF2CC',
'fill-opacity': 0.2
}
});
// 筆レイヤ(ライン)
map.addLayer({
"id": "fude-line",
"source": "moj-xml",
"source-layer": "fude",
"type": "line",
"layout": {
"visibility": "none",
},
"paint": {
'line-color': '#FF3232',
'line-width': 1
}
});
// 3D都市モデルPLATEAU建築物モデル(PMTiles)ソース
map.addSource("plateau-lod1", {
type: "vector",
url: "pmtiles://https://shiworks.xsrv.jp/pmtiles-data/plateau/PLATEAU_2022_LOD1.pmtiles",
// url: "pmtiles://https://pmtiles-data.s3.ap-northeast-1.amazonaws.com/plateau/PLATEAU_2022_LOD1.pmtiles",
minzoom: 16,
maxzoom: 16,
attribution:
'<a href="https://www.geospatial.jp/ckan/dataset/plateau">国土交通省 3D都市モデルPLATEAU(建築物LOD1)</a>',
});
// 3D都市モデルPLATEAU建築物モデル(PMTiles)レイヤ
map.addLayer({
id: "plateau-lod1",
source: "plateau-lod1",
"source-layer": "PLATEAU",
minzoom: 14,
maxzoom: 23,
type: "fill-extrusion",
layout: {
visibility: "none",
},
paint: {
"fill-extrusion-color": "#FFFFFF",
"fill-extrusion-opacity": 0.7,
"fill-extrusion-height": ["get", "measuredHeight"],
},
});
// スライダーCS立体図の不透明度を制御
const cs_sliderOpactiy = document.getElementById("cs-slider-opacity");
const cs_sliderOpactiyValue = document.getElementById(
"cs-slider-opacity-value"
);
cs_sliderOpactiy.addEventListener("input", (e) => {
map.setPaintProperty(
"nagano-cs",
"raster-opacity",
parseInt(e.target.value, 10) / 100
);
map.setPaintProperty(
"hiroshima-cs",
"raster-opacity",
parseInt(e.target.value, 10) / 100
);
map.setPaintProperty(
"hiroshima-05m-cs",
"raster-opacity",
parseInt(e.target.value, 10) / 100
);
map.setPaintProperty(
"hiroshima-1m-cs",
"raster-opacity",
parseInt(e.target.value, 10) / 100
);
map.setPaintProperty(
"okayama-cs",
"raster-opacity",
parseInt(e.target.value, 10) / 100
);
map.setPaintProperty(
"ehime-cs",
"raster-opacity",
parseInt(e.target.value, 10) / 100
);
map.setPaintProperty(
"kochi-cs",
"raster-opacity",
parseInt(e.target.value, 10) / 100
);
map.setPaintProperty(
"fukushima-cs",
"raster-opacity",
parseInt(e.target.value, 10) / 100
);
map.setPaintProperty(
"kumamoto-oita-cs",
"raster-opacity",
parseInt(e.target.value, 10) / 100
);
map.setPaintProperty(
"hyogo-cs",
"raster-opacity",
parseInt(e.target.value, 10) / 100
);
map.setPaintProperty(
"tochigi-cs",
"raster-opacity",
parseInt(e.target.value, 10) / 100
);
map.setPaintProperty(
"shizuoka-cs",
"raster-opacity",
parseInt(e.target.value, 10) / 100
);
map.setPaintProperty(
"gifu-cs",
"raster-opacity",
parseInt(e.target.value, 10) / 100
);
map.setPaintProperty(
"osaka-cs",
"raster-opacity",
parseInt(e.target.value, 10) / 100
);
map.setPaintProperty(
"noto-cs",
"raster-opacity",
parseInt(e.target.value, 10) / 100
);
map.setPaintProperty(
"noto-cs-test",
"raster-opacity",
parseInt(e.target.value, 10) / 100
);
map.setPaintProperty(
"tokyo-23ku-cs",
"raster-opacity",
parseInt(e.target.value, 10) / 100
);
map.setPaintProperty(
"tokyo-tama-cs",
"raster-opacity",
parseInt(e.target.value, 10) / 100
);
map.setPaintProperty(
"tokyo-shima-01-cs",
"raster-opacity",
parseInt(e.target.value, 10) / 100
);
map.setPaintProperty(
"tokyo-shima-02-cs",
"raster-opacity",
parseInt(e.target.value, 10) / 100
);
map.setPaintProperty(
"tokyo-shima-03-cs",
"raster-opacity",
parseInt(e.target.value, 10) / 100
);
map.setPaintProperty(
"tokyo-shima-04-cs",
"raster-opacity",
parseInt(e.target.value, 10) / 100
);
map.setPaintProperty(
"tokyo-shima-05-cs",
"raster-opacity",
parseInt(e.target.value, 10) / 100
);
map.setPaintProperty(
"tokyo-shima-06-cs",
"raster-opacity",
parseInt(e.target.value, 10) / 100
);
map.setPaintProperty(
"wakayama-cs",
"raster-opacity",
parseInt(e.target.value, 10) / 100
);
map.setPaintProperty(
"kanagawa-cs",
"raster-opacity",
parseInt(e.target.value, 10) / 100
);
cs_sliderOpactiyValue.textContent = e.target.value + "%";
});
// スライダーで陰影起伏図の不透明度を制御
const hillshade_sliderOpactiy = document.getElementById(
"hillshade-slider-opacity"
);
const hillshade_sliderOpactiyValue = document.getElementById(
"hillshade-slider-opacity-value"
);
hillshade_sliderOpactiy.addEventListener("input", (e) => {
map.setPaintProperty(
"hillshade",
"raster-opacity",
parseInt(e.target.value, 10) / 100
);
hillshade_sliderOpactiyValue.textContent = e.target.value + "%";
});
// Skyレイヤ
map.setSky({
"sky-color": "#199EF3",
"sky-horizon-blend": 0.7,
"horizon-color": "#f0f8ff",
"horizon-fog-blend": 0.8,
"fog-color": "#2c7fb8",
"fog-ground-blend": 0.9,
"atmosphere-blend": ["interpolate", ["linear"], ["zoom"], 0, 1, 12, 0]
});
updateCoordsDisplay(); // 初期座標を表示
map.showTileBoundaries = true; // タイル境界
});
// 地図の中心座標と標高を表示する関数
/*
function updateCoordsDisplay() {
let center = map.getCenter();
let lat = center.lat.toFixed(5);
let lng = center.lng.toFixed(5);
// let elevTile = 'https://tiles.gsj.jp/tiles/elev/mixed/{z}/{y}/{x}.png' // 統合DEM
let elevTile = 'https://tiles.gsj.jp/tiles/elev/land/{z}/{y}/{x}.png' // 陸域統合DEM
getNumericalValue(elevTile, lat, lng, Math.trunc(map.getZoom()), 0.01, 0, -(2 ** 23)).then(function (v) {
document.getElementById("coords").innerHTML =
"中心座標: " + lat + ", " + lng + "<br>" +
"標高(ZL=15以下): " + ((isNaN(v)) ? '取得できません' : v.toFixed(2) + 'm') + "<br>" +
'<a href="https://www.google.com/maps?q=' + lat + "," + lng + '&hl=ja" target="_blank">🌎GoogleMaps</a>' +
" " + '<a href="https://www.google.com/maps/@?api=1&map_action=pano&viewpoint=' + lat + "," + lng + '&hl=ja" target="_blank">📷StreetView</a>';
});
}
*/
function updateCoordsDisplay() {
let center = map.getCenter();
let lat = center.lat.toFixed(5);
let lng = center.lng.toFixed(5);
let zoomLevel = Math.trunc(map.getZoom());
let elevTile = 'https://tiles.gsj.jp/tiles/elev/mixed/{z}/{y}/{x}.png'; // 統合DEM
// let elevTile = 'https://tiles.gsj.jp/tiles/elev/land/{z}/{y}/{x}.png'; // 陸域統合DEM
if (zoomLevel > 15) {
document.getElementById("coords").innerHTML =
"中心座標: " + lat + ", " + lng + "<br>" +
"ズームレベル: " + map.getZoom().toFixed(2) + "<br>" +
"標高(ZL15以下): 取得できません<br>" +
'<a href="https://www.google.com/maps?q=' + lat + "," + lng + '&hl=ja" target="_blank">🌎GoogleMaps</a>' +
" " + '<a href="https://www.google.com/maps/@?api=1&map_action=pano&viewpoint=' + lat + "," + lng + '&hl=ja" target="_blank">📷StreetView</a>';
} else {
getNumericalValue(elevTile, lat, lng, zoomLevel, 0.01, 0, -(2 ** 23)).then(function (v) {
document.getElementById("coords").innerHTML =
"中心座標: " + lat + ", " + lng + "<br>" +
"ズームレベル: " + map.getZoom().toFixed(2) + "<br>" +
"標高(ZL15以下):" + ((isNaN(v)) ? '取得できません' : v.toFixed(2) + 'm') + "<br>" +
'<a href="https://www.google.com/maps?q=' + lat + "," + lng + '&hl=ja" target="_blank">🌎GoogleMaps</a>' +
" " + '<a href="https://www.google.com/maps/@?api=1&map_action=pano&viewpoint=' + lat + "," + lng + '&hl=ja" target="_blank">📷StreetView</a>';
});
}
}
// 地図が移動したら中心の座標を更新
map.on("move", function () {
updateCoordsDisplay(); // 座標を更新
});
// ============================== レイヤの表示・非表示切り替え制御 ==============================
// レイヤ表示・非表示切り替え関数
function toggleMapLayerVisibility(checkboxId, layerId) {
// 特殊な処理が必要なチェックボックスIDを配列で定義
const specialCheckboxIds = ["tokyo-shima-cs", "moj-xml"];
if (!specialCheckboxIds.includes(checkboxId)) {
// 通常の処理
document
.getElementById(checkboxId)
.addEventListener("change", function (e) {
map.setLayoutProperty(
layerId,
"visibility",
e.target.checked ? "visible" : "none"
);
});
} else {
// 特殊な処理
document
.getElementById(checkboxId)
.addEventListener("change", function (e) {
let relatedLayers = [];
// チェックボックスIDに応じて関連レイヤーを設定
if (checkboxId === "tokyo-shima-cs") {
relatedLayers = [
"tokyo-shima-01-cs",
"tokyo-shima-02-cs",
"tokyo-shima-03-cs",
"tokyo-shima-04-cs",
"tokyo-shima-05-cs",
"tokyo-shima-06-cs"
];
} else if (checkboxId === "moj-xml") {
relatedLayers = ["fude-line", "fude-polygon"];
}
// すべての関連レイヤーの visibility を設定
relatedLayers.forEach(layer => {
map.setLayoutProperty(
layer,
"visibility",
e.target.checked ? "visible" : "none"
);
});
});
}
}
// レイヤ表示・非表示切り替え制御
// CS立体図
toggleMapLayerVisibility("fukushima-cs", "fukushima-cs");
toggleMapLayerVisibility("tochigi-cs", "tochigi-cs");
toggleMapLayerVisibility("tokyo-23ku-cs", "tokyo-23ku-cs");
toggleMapLayerVisibility("tokyo-tama-cs", "tokyo-tama-cs");
toggleMapLayerVisibility("tokyo-shima-cs", "tokyo-shima-cs");
toggleMapLayerVisibility("kanagawa-cs", "kanagawa-cs");
toggleMapLayerVisibility("noto-cs", "noto-cs");
toggleMapLayerVisibility("noto-cs-test", "noto-cs-test");
toggleMapLayerVisibility("nagano-cs", "nagano-cs");
toggleMapLayerVisibility("gifu-cs", "gifu-cs");
toggleMapLayerVisibility("shizuoka-cs", "shizuoka-cs");
toggleMapLayerVisibility("osaka-cs", "osaka-cs");
toggleMapLayerVisibility("hyogo-cs", "hyogo-cs");
toggleMapLayerVisibility("wakayama-cs", "wakayama-cs");
toggleMapLayerVisibility("okayama-cs", "okayama-cs");
toggleMapLayerVisibility("hiroshima-cs", "hiroshima-cs");
toggleMapLayerVisibility("hiroshima-05m-cs", "hiroshima-05m-cs");
toggleMapLayerVisibility("hiroshima-1m-cs", "hiroshima-1m-cs");
toggleMapLayerVisibility("ehime-cs", "ehime-cs");
toggleMapLayerVisibility("kochi-cs", "kochi-cs");
toggleMapLayerVisibility("kumamoto-oita-cs", "kumamoto-oita-cs");
// CS立体図以外
toggleMapLayerVisibility("plateau-lod1", "plateau-lod1");
toggleMapLayerVisibility("moj-xml", "moj-xml");
toggleMapLayerVisibility("landslide", "landslide");
// 地すべり地形分布図凡例
// イベントリスナーを追加
document.addEventListener("DOMContentLoaded", () => {
document
.getElementById("open-legend-landslide")
.addEventListener("click", OpenLegendRoad);
});
function OpenLegendRoad() {
// 凡例の内容を含むウェブページのURL
var legendUrl = "./PNG/legend-landslide.png";
// 新しいウィンドウを開く
window.open(legendUrl, "Legend", "width=1800,height=1200");
}
// クリック時にポップアップ表示
map.on('click', (e) => {
const features = map.queryRenderedFeatures(e.point); // クリック地点のフィーチャを取得
if (features.length === 0) return; // フィーチャがなければ何もしない
let popupContent = '';
const uniqueLayers = []; // 処理済みレイヤーIDを記録
features.forEach((feature) => {
const layerId = feature.layer ? feature.layer.id : null; // レイヤーIDを取得
if (!layerId) {
console.warn('レイヤーIDが見つかりません:', feature);
return; // レイヤーIDがない場合はスキップ
}
if (!uniqueLayers.includes(layerId)) {
uniqueLayers.push(layerId); // 処理済みレイヤーを記録
// レイヤーごとのポップアップ内容を追加
const properties = feature.properties; // フィーチャのプロパティを取得
if (layerId === 'plateau-lod1') {
popupContent += `
<div><strong>建築物モデルLOD1:</strong></div>
<div>id: ${properties['id']}</div>
<div>source: ${properties['source']}</div>
<div>type: ${properties['type']}</div>
<div>lod: ${properties['lod']}</div>
<div>measuredHeight: ${properties['measuredHeight']}</div>
<div>address: ${properties['address']}</div>
<div>buildingID: ${properties['buildingID']}</div>
<div>prefecture: ${properties['prefecture']}</div>
<div>city: ${properties['city']}</div>
<div>lod1HeightType: ${properties['lod1HeightType']}</div>
<br>
`;
} else if (layerId === 'fude-polygon') {
popupContent += `
<div><strong>法務省地図XML:</strong></div>
<div>座標系: ${properties['座標系']}</div>
<div>測地系判別: ${properties['測地系判別']}</div>
<div>地図名: ${properties['地図名']}</div>
<div>縮尺分母: ${properties['縮尺分母']}</div>
<div>地番区域: ${properties['地番区域']}</div>
<div>地番: ${properties['地番']}</div>
<div>座標値種別: ${properties['座標値種別']}</div>
<br>
`;
}
}
});
// ポップアップを作成して表示
if (popupContent) {
new maplibregl.Popup()
.setLngLat(e.lngLat) // クリック位置にポップアップを設定
.setHTML(popupContent.trim()) // ポップアップの内容を設定
.addTo(map); // ポップアップを地図に追加
}
});
/// ****************
// latLngToTile 緯度経度をタイル座標に変換する関数
// latLng: 緯度経度オブジェクト(lat,lngフィールドを持ちます)
// z: ズームレベル
// 戻り値: タイル座標オブジェクト(x, yフィールドを持ちます)
// ※通常,地図ライブラリ内に同様の関数が用意されています.
/// ****************
/*
function latLngToTile(lat, lng, z) {
console.log("z=" + z + " " + "lat=" + lat + " " + "lng=" + lng);
const
w = Math.pow(2, (z === undefined) ? 0 : z) / 2, // 世界全体のピクセル幅
yrad = Math.log(Math.tan(Math.PI * (90 + lat) / 360));
return { x: (lng / 180 + 1) * w, y: (1 - yrad / Math.PI) * w };
};
*/
function latLngToTile(lat, lng, z) {
// ズームレベル z におけるタイルの総数
const n = Math.pow(2, z);
// 経度 lng → タイル X 座標
const x = ((lng / 180 + 1) * n) / 2;
// 緯度 lat → タイル Y 座標
// (メルカトル投影による変換)
const latRad = lat * Math.PI / 180; // 緯度をラジアンに変換
const y = n * (
1 - Math.log(
Math.tan(latRad) + 1 / Math.cos(latRad)
) / Math.PI
) / 2;
return { x, y };
}
/// ****************
// getNumericalValue タイルURL,座標,ズームレベルを指定して数値を取得する関数
// url: タイル画像のURLテンプレート.
// ズームレベル,X, Y座標をそれぞれ{z},{x},{y}として埋め込む
// ll: 緯度経度オブジェクト(lat,lngフィールドを持ちます)
// z: ズームレベル
// factor: 数値を求めるときに使用する係数,デフォルト1
// offset: 数値を求めるときに使用するオフセット,デフォルト0
// invalid: 追加無効値を相当する数値で指定.デフォルトは指定なし
// 戻り値: 成功時に数値を受け取るプロミス.無効値の場合はNaNを受け取ります
/// ****************
function getNumericalValue(url, lat, lng, z, factor = 1, offset = 0, invalid = undefined) {
console.log("z=" + z + " " + "lat=" + lat + " " + "lng=" + lng);
return new Promise(function (resolve, reject) {
const
p = latLngToTile(lat, lng, z),
x = Math.floor(p.x), // タイルX座標
y = Math.floor(p.y), // タイルY座標
i = (p.x - x) * 256, // タイル内i座標
j = (p.y - y) * 256, // タイル内j座標
img = new Image();
console.log("タイルURL=" + url);
// console.log("z=" + z + " " + "lat=" + lat + " " + "lng=" + lng);
console.log("タイルX座標=" + x + " " + "タイルY座標=" + y);
img.crossOrigin = 'anonymous'; // 画像ファイルからデータを取り出すために必要です
img.onload = function () {
const
canvas = document.createElement('canvas'),
context = canvas.getContext('2d');
let
r2,
v,
data;
canvas.width = 1;
canvas.height = 1;
context.drawImage(img, i, j, 1, 1, 0, 0, 1, 1);
data = context.getImageData(0, 0, 1, 1).data;
r2 = (data[0] < 2 ** 7) ? data[0] : data[0] - 2 ** 8;
v = r2 * 2 ** 16 + data[1] * 2 ** 8 + data[2];
if (data[3] !== 255 || (invalid != undefined && v == invalid)) {
v = NaN;
}
resolve(v * factor + offset);
}
img.onerror = function () {
reject(null);
}
img.src = url.replace('{z}', z).replace('{y}', y).replace('{x}', x);
});
};
</script>
</body>
</html>