|
| 1 | +<!DOCTYPE html> |
| 2 | +<html> |
| 3 | +<head> |
| 4 | +<meta charset="utf-8"> |
| 5 | +<title>Mapbox WMS Demo</title> |
| 6 | +<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no"> |
| 7 | +<link href="https://api.mapbox.com/mapbox-gl-js/v3.9.4/mapbox-gl.css" rel="stylesheet"> |
| 8 | +<script src="https://api.mapbox.com/mapbox-gl-js/v3.9.4/mapbox-gl.js"></script> |
| 9 | +<style> |
| 10 | +body { margin: 0; padding: 0; } |
| 11 | +#map { position: absolute; top: 0; bottom: 0; width: 100%; } |
| 12 | + |
| 13 | +.map-overlay { |
| 14 | + font: 12px/20px 'Helvetica Neue', Arial, Helvetica, sans-serif; |
| 15 | + position: absolute; |
| 16 | + width: 200px; |
| 17 | + top: 0; |
| 18 | + left: 0; |
| 19 | + padding: 10px; |
| 20 | +} |
| 21 | + |
| 22 | +.map-overlay-inner { |
| 23 | + background-color: #fff; |
| 24 | + box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1); |
| 25 | + border-radius: 3px; |
| 26 | + padding: 10px; |
| 27 | + margin-bottom: 10px; |
| 28 | +} |
| 29 | + |
| 30 | +.map-overlay-inner label { |
| 31 | + display: block; |
| 32 | + margin: 0 0 10px; |
| 33 | +} |
| 34 | + |
| 35 | +.map-overlay-inner input { |
| 36 | + background-color: transparent; |
| 37 | + display: inline-block; |
| 38 | + width: 100%; |
| 39 | + position: relative; |
| 40 | + margin: 0; |
| 41 | + cursor: ew-resize; |
| 42 | +} |
| 43 | +</style> |
| 44 | +</head> |
| 45 | +<body> |
| 46 | + |
| 47 | +<div id="map"></div> |
| 48 | +<div class="map-overlay top"> |
| 49 | + <div class="map-overlay-inner"> |
| 50 | + <label>森林レイヤー (2020): <span id="forest-opacity-val">60%</span></label> |
| 51 | + <input id="forest-slider" type="range" min="0" max="100" step="1" value="60"> |
| 52 | + <hr> |
| 53 | + <label>ベースマップ (衛星写真): <span id="mapbox-opacity-val">100%</span></label> |
| 54 | + <input id="mapbox-slider" type="range" min="0" max="100" step="1" value="100"> |
| 55 | + </div> |
| 56 | +</div> |
| 57 | + |
| 58 | +<script> |
| 59 | +// IMPORTANT: Please replace this with your own Mapbox Access Token |
| 60 | +// or it will fall back to a public token/error. |
| 61 | +mapboxgl.accessToken = 'YOUR_MAPBOX_ACCESS_TOKEN'; |
| 62 | + |
| 63 | +const map = new mapboxgl.Map({ |
| 64 | + container: "map", |
| 65 | + style: "mapbox://styles/mapbox/satellite-v9", // 衛星写真 |
| 66 | + center: [-79.957141, -2.024311], // [経度, 緯度] |
| 67 | + zoom: 17 |
| 68 | +}); |
| 69 | + |
| 70 | +map.on("load", () => { |
| 71 | + // ソースの追加 |
| 72 | + map.addSource("eufo-wms-source", { |
| 73 | + type: "raster", |
| 74 | + tiles: [ |
| 75 | + "https://ies-ows.jrc.ec.europa.eu/iforce/gft2020/wms.py?" + |
| 76 | + "SERVICE=WMS&" + |
| 77 | + "VERSION=1.3.0&" + |
| 78 | + "REQUEST=GetMap&" + |
| 79 | + "LAYERS=gft2020_v1&" + |
| 80 | + "STYLES=&" + |
| 81 | + "FORMAT=image/png&" + |
| 82 | + "TRANSPARENT=true&" + |
| 83 | + "WIDTH=512&" + |
| 84 | + "HEIGHT=512&" + |
| 85 | + "CRS=EPSG:3857&" + |
| 86 | + "BBOX={bbox-epsg-3857}" |
| 87 | + ], |
| 88 | + tileSize: 512 |
| 89 | + }); |
| 90 | + |
| 91 | + // レイヤーの追加 |
| 92 | + map.addLayer({ |
| 93 | + id: "eufo-wms-layer", |
| 94 | + type: "raster", |
| 95 | + source: "eufo-wms-source", |
| 96 | + paint: { |
| 97 | + "raster-opacity": 0.6, |
| 98 | + "raster-fade-duration": 0 |
| 99 | + } |
| 100 | + }); |
| 101 | + |
| 102 | + // 森林レイヤーのスライダー |
| 103 | + const forestSlider = document.getElementById("forest-slider"); |
| 104 | + forestSlider.addEventListener("input", (e) => { |
| 105 | + const value = parseFloat(e.target.value) / 100; |
| 106 | + map.setPaintProperty("eufo-wms-layer", "raster-opacity", value); |
| 107 | + document.getElementById( |
| 108 | + "forest-opacity-val" |
| 109 | + ).textContent = `${e.target.value}%`; |
| 110 | + }); |
| 111 | + |
| 112 | + // Mapbox ベースマップ(衛星写真)のスライダー |
| 113 | + const mapboxSlider = document.getElementById("mapbox-slider"); |
| 114 | + mapboxSlider.addEventListener("input", (e) => { |
| 115 | + const value = parseFloat(e.target.value) / 100; |
| 116 | + // Mapbox公式スタイル 'satellite-v9' 内のレイヤーIDは通常 'satellite' です |
| 117 | + if (map.getLayer("satellite")) { |
| 118 | + map.setPaintProperty("satellite", "raster-opacity", value); |
| 119 | + } |
| 120 | + document.getElementById( |
| 121 | + "mapbox-opacity-val" |
| 122 | + ).textContent = `${e.target.value}%`; |
| 123 | + }); |
| 124 | +}); |
| 125 | + |
| 126 | +// 座標表示のデバッグ |
| 127 | +map.on("click", (e) => { |
| 128 | + window.alert( |
| 129 | + `クリック座標: ${e.lngLat.lng.toFixed(6)}, ${e.lngLat.lat.toFixed(6)}` |
| 130 | + ); |
| 131 | +}); |
| 132 | +</script> |
| 133 | + |
| 134 | +</body> |
| 135 | +</html> |
0 commit comments