UNPKG

dem2terrain

Version:

使用 GDAL 制作 DEM 栅格的地形瓦片

70 lines (59 loc) 1.59 kB
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Query terrain elevation</title> <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no"> <link href="./mapbox-gl.css" rel="stylesheet"> <script src="./mapbox-gl.js"></script> <style> body { margin: 0; padding: 0; } #map { position: absolute; top: 0; bottom: 0; width: 100%; } </style> </head> <body> <div id="map"></div> <script> // 注意,请写自己的token运行 mapboxgl.accessToken = 'pk.eyJ1IjoiYm9ibzlvayIsImEiOiJja3cxZjU1Z2UwMnFnMzBvajh4Y29iZTBiIn0.NcOkYbGRCj-C-gm1my6NZg'; const map = new mapboxgl.Map({ container: 'map', zoom: 8, center: [103.98464635299729, 30.69244825172305], pitch: 76, // Choose from Mapbox's core styles, or make your own style with Mapbox Studio style: 'mapbox://styles/mapbox/satellite-streets-v12', hash: false }); map.on('load', (e) => { // Set custom fog map.setFog({ 'range': [-0.5, 2], 'color': '#def', 'high-color': '#def', 'space-color': '#def' }); // Add terrain source, with slight exaggeration map.addSource('mapbox-dem', { 'type': 'raster-dem', 'tiles': ['./terrain/{z}/{x}/{y}.png'], tileSize: 256, 'maxzoom': 14, 'minzoom': 5 }); map.setTerrain({ 'source': 'mapbox-dem', 'exaggeration': 1.5 }); }); map.on('click', function (e) { console.log(e); }) </script> </body> </html>