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
| import Map from 'ol/Map.js'; import View from 'ol/View.js'; import {OSM, XYZ} from 'ol/source.js'; import {WebGLTile as TileLayer} from 'ol/layer.js';
const variables = {};
function elevation(xOffset, yOffset) { return [ '+', ['*', 256, ['band', 1, xOffset, yOffset]], ['*', 2 * 256, ['band', 2, xOffset, yOffset]], ['*', 3 * 256, ['band', 3, xOffset, yOffset]], ]; }
const dp = ['*', 2, ['resolution']]; const z0x = ['*', ['var', 'vert'], elevation(-1, 0)]; const z1x = ['*', ['var', 'vert'], elevation(1, 0)]; const dzdx = ['/', ['-', z1x, z0x], dp]; const z0y = ['*', ['var', 'vert'], elevation(0, -1)]; const z1y = ['*', ['var', 'vert'], elevation(0, 1)]; const dzdy = ['/', ['-', z1y, z0y], dp]; const slope = ['atan', ['^', ['+', ['^', dzdx, 2], ['^', dzdy, 2]], 0.5]]; const aspect = ['clamp', ['atan', ['-', 0, dzdx], dzdy], -Math.PI, Math.PI]; const sunEl = ['*', Math.PI / 180, ['var', 'sunEl']]; const sunAz = ['*', Math.PI / 180, ['var', 'sunAz']];
const cosIncidence = [ '+', ['*', ['sin', sunEl], ['cos', slope]], ['*', ['*', ['cos', sunEl], ['sin', slope]], ['cos', ['-', sunAz, aspect]]], ]; const scaled = ['*', 255, cosIncidence];
const shadedRelief = new TileLayer({ opacity: 0.3, source: new XYZ({ url: 'https://{a-d}.tiles.mapbox.com/v3/aj.sf-dem/{z}/{x}/{y}.png', }), style: { variables: variables, color: ['color', scaled, scaled, scaled], }, });
const controlIds = ['vert', 'sunEl', 'sunAz']; controlIds.forEach(function (id) { const control = document.getElementById(id); const output = document.getElementById(id + 'Out'); function updateValues() { output.innerText = control.value; variables[id] = Number(control.value); } updateValues(); control.addEventListener('input', function () { updateValues(); shadedRelief.updateStyleVariables(variables); }); });
const map = new Map({ target: 'map', layers: [ new TileLayer({ source: new OSM(), }), shadedRelief, ], view: new View({ extent: [-13675026, 4439648, -13580856, 4580292], center: [-13615645, 4497969], minZoom: 10, maxZoom: 16, zoom: 13, }), });
|