|
| 1 | +<!DOCTYPE html> |
| 2 | +<html> |
| 3 | +<head> |
| 4 | + <title>Mapbox GL JS debug page</title> |
| 5 | + <meta charset='utf-8'> |
| 6 | + <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"> |
| 7 | + <link rel='stylesheet' href='../dist/mapbox-gl.css' /> |
| 8 | + <style> |
| 9 | + body { margin: 0; padding: 0; } |
| 10 | + html, body, #map { height: 100%; } |
| 11 | + #controls { position: absolute; top: 0; left: 0; } |
| 12 | + </style> |
| 13 | +</head> |
| 14 | + |
| 15 | +<body> |
| 16 | +<div id='map'></div> |
| 17 | +<div id='controls'> |
| 18 | + <button id="animate">Animate</button><br /> |
| 19 | + <label><input id='terrain-checkbox' type='checkbox'> terrain</label><br /> |
| 20 | + <div> |
| 21 | + <label>Projection:</label> |
| 22 | + <select id="projName"> |
| 23 | + <option value="mercator" selected>Mercator</option> |
| 24 | + <option value="globe">Globe</option> |
| 25 | + <option value="albers">Albers USA</option> |
| 26 | + <option value="equalEarth">Equal Earth</option> |
| 27 | + <option value="equirectangular">Equirectangular</option> |
| 28 | + <option value="lambertConformalConic">Lambert Conformal Conic</option> |
| 29 | + <option value="naturalEarth">Natural Earth</option> |
| 30 | + <option value="winkelTripel">Winkel Tripel</option> |
| 31 | + </select> |
| 32 | + </div> |
| 33 | +</div> |
| 34 | +<script src='../dist/mapbox-gl-dev.js'></script> |
| 35 | +<script src='../debug/access_token_generated.js'></script> |
| 36 | +<script> |
| 37 | + |
| 38 | +var map = window.map = new mapboxgl.Map({ |
| 39 | + container: 'map', |
| 40 | + devtools: true, |
| 41 | + zoom: 12.5, |
| 42 | + center: [-77.01866, 38.888], |
| 43 | + style: 'mapbox://styles/mapbox/streets-v9', |
| 44 | + hash: true |
| 45 | +}); |
| 46 | + |
| 47 | +let lngLatArr = []; |
| 48 | +const spinningMarkers = []; |
| 49 | +['auto', 'map', 'viewport', 'horizon'].forEach((rotationAlignment, i) => { |
| 50 | + ['auto', 'map', 'viewport'].forEach((pitchAlignment, j) => { |
| 51 | + var bounds = map.getBounds(); |
| 52 | + var s = bounds.getSouth(); |
| 53 | + var n = bounds.getNorth(); |
| 54 | + var w = bounds.getWest(); |
| 55 | + var e = bounds.getEast(); |
| 56 | + |
| 57 | + var lng = w + (e - w) * ((i + .5) / 4); |
| 58 | + var lat = s + (n - s) * ((j + .5) / 3); |
| 59 | + |
| 60 | + var height = (i * 2000 + j*2000) * (e - w); |
| 61 | + // var height = 0.0; |
| 62 | + |
| 63 | + |
| 64 | + // if(!(i===2 && j===0))return |
| 65 | + |
| 66 | + const popupHtml = `<div> |
| 67 | + Pitch Alignment: ${pitchAlignment}<br> |
| 68 | + Rotation Alignment: ${rotationAlignment}<br> |
| 69 | + lng:${lng}<br> |
| 70 | + lat:${lat}<br> |
| 71 | + height:${height}<br> |
| 72 | + </div>` |
| 73 | + |
| 74 | + var popup = new mapboxgl.Popup().setHTML(popupHtml); |
| 75 | + |
| 76 | + var r = Math.round(Math.random() * 255); |
| 77 | + var g = Math.round(Math.random() * 255); |
| 78 | + var b = Math.round(Math.random() * 255); |
| 79 | + |
| 80 | + var sc = Math.random() * 2.5 + 0.5; |
| 81 | + |
| 82 | + var marker = new mapboxgl.Marker({ |
| 83 | + color: `rgb(${r}, ${g}, ${b})`, |
| 84 | + scale: sc, |
| 85 | + draggable: true, |
| 86 | + rotationAlignment, |
| 87 | + pitchAlignment, |
| 88 | + altitude:height, |
| 89 | + }) |
| 90 | + .setLngLat([lng, lat]) |
| 91 | + .setPopup(popup) |
| 92 | + .addTo(map); |
| 93 | + |
| 94 | + marker.togglePopup(); |
| 95 | + |
| 96 | + lngLatArr.push({ |
| 97 | + lngLat:[lng, lat], |
| 98 | + lngOffset:(e - w), |
| 99 | + latOffset:(n - s), |
| 100 | + height |
| 101 | + }) |
| 102 | + |
| 103 | + spinningMarkers.push(marker); |
| 104 | + }); |
| 105 | +}); |
| 106 | + |
| 107 | + |
| 108 | +map.on('style.load',()=>{ |
| 109 | + addFillExtrusionLayer(lngLatArr) |
| 110 | +}) |
| 111 | + |
| 112 | + |
| 113 | + |
| 114 | +function addFillExtrusionLayer(data=[]){ |
| 115 | + |
| 116 | + const dataArr = data.map(a=>{ |
| 117 | + let {lngOffset,latOffset} = a; |
| 118 | + lngOffset = lngOffset/100; |
| 119 | + latOffset = latOffset/100; |
| 120 | + const [lng, lat] = a.lngLat; |
| 121 | + const aObj = { |
| 122 | + ...a, |
| 123 | + "type": "Feature", |
| 124 | + "properties": { |
| 125 | + "height": a.height, |
| 126 | + "color": `rgba(${a.height%255},${a.height%150},${255 - a.height%255},1)`, |
| 127 | + }, |
| 128 | + lngLatArr:[ |
| 129 | + [lng-lngOffset,lat+latOffset], |
| 130 | + [lng+lngOffset,lat+latOffset], |
| 131 | + [lng+lngOffset,lat-latOffset], |
| 132 | + [lng-lngOffset,lat-latOffset], |
| 133 | + ] |
| 134 | + } |
| 135 | + |
| 136 | + aObj.geometry = { |
| 137 | + "type": "Polygon", |
| 138 | + "coordinates": [aObj.lngLatArr] |
| 139 | + } |
| 140 | + |
| 141 | + return aObj |
| 142 | + }); |
| 143 | + |
| 144 | + let layer = { |
| 145 | + id:'FillExtrusionLayerId', |
| 146 | + 'type': 'fill-extrusion', |
| 147 | + 'source': { |
| 148 | + type: 'geojson', |
| 149 | + data: { |
| 150 | + "type": "FeatureCollection", |
| 151 | + "features":dataArr, |
| 152 | + } |
| 153 | + }, |
| 154 | + |
| 155 | + 'paint': { |
| 156 | + 'fill-extrusion-opacity':0.6, |
| 157 | + // 'fill-extrusion-color': 'rgba(255,10,10,0.8)', |
| 158 | + 'fill-extrusion-color': ["get", "color"], |
| 159 | + 'fill-extrusion-height': ["get", "height"], |
| 160 | + 'fill-extrusion-base': 0, |
| 161 | + } |
| 162 | + |
| 163 | + |
| 164 | + |
| 165 | + |
| 166 | + } |
| 167 | + |
| 168 | + map.addLayer(layer); |
| 169 | + |
| 170 | +} |
| 171 | + |
| 172 | +let animate = false; |
| 173 | +document.getElementById('animate').addEventListener('click', () => { |
| 174 | + animate = !animate; |
| 175 | + if (animate) { |
| 176 | + spinMarkers(); |
| 177 | + } |
| 178 | +}); |
| 179 | + |
| 180 | +let rotation = 0; |
| 181 | +function spinMarkers() { |
| 182 | + rotation++; |
| 183 | + spinningMarkers.forEach((marker) => { |
| 184 | + marker.setRotation(rotation); |
| 185 | + }); |
| 186 | + if (animate) { |
| 187 | + window.requestAnimationFrame(spinMarkers); |
| 188 | + } |
| 189 | +} |
| 190 | +window.requestAnimationFrame(spinMarkers); |
| 191 | + |
| 192 | +map.addControl(new mapboxgl.NavigationControl()); |
| 193 | + |
| 194 | +map.on('load', function() { |
| 195 | + map.addSource('mapbox-dem', { |
| 196 | + "type": "raster-dem", |
| 197 | + "url": "mapbox://mapbox.mapbox-terrain-dem-v1", |
| 198 | + "tileSize": 512, |
| 199 | + "maxzoom": 14 |
| 200 | + }); |
| 201 | + |
| 202 | + map.setFog({}); |
| 203 | +}); |
| 204 | + |
| 205 | +document.getElementById('terrain-checkbox').onclick = function() { |
| 206 | + map.setTerrain(this.checked ? {"source": "mapbox-dem", "exaggeration": 10} : null); |
| 207 | +}; |
| 208 | + |
| 209 | +document.getElementById('projName').addEventListener('change', (e) => { |
| 210 | + const el = document.getElementById('projName'); |
| 211 | + map.setProjection(el.options[el.selectedIndex].value); |
| 212 | +}); |
| 213 | +</script> |
| 214 | + |
| 215 | +</body> |
| 216 | +</html> |
0 commit comments