|
| 1 | +<html> |
| 2 | + <head> |
| 3 | + <title>Itowns - 3D Tiles loader (Realistic Lighting)</title> |
| 4 | + |
| 5 | + <script type="importmap"> |
| 6 | + { |
| 7 | + "imports": { |
| 8 | + "itowns": "../dist/itowns.js", |
| 9 | + "debug": "../dist/debug.js", |
| 10 | + "dat": "https://unpkg.com/dat.gui@0.7.9/build/dat.gui.module.js", |
| 11 | + "LoadingScreen": "./jsm/GUI/LoadingScreen.js", |
| 12 | + "three": "https://unpkg.com/three@0.182.0/build/three.module.js" |
| 13 | + } |
| 14 | + } |
| 15 | + </script> |
| 16 | + |
| 17 | + <meta charset="UTF-8"> |
| 18 | + <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 19 | + |
| 20 | + <link rel="stylesheet" type="text/css" href="css/example.css"> |
| 21 | + <link rel="stylesheet" type="text/css" href="css/LoadingScreen.css"> |
| 22 | + |
| 23 | + </head> |
| 24 | + <body> |
| 25 | + <div id="viewerDiv"></div> |
| 26 | + |
| 27 | + |
| 28 | + <script type="module"> |
| 29 | + import * as THREE from 'three'; |
| 30 | + import dat from 'dat'; |
| 31 | + import setupLoadingScreen from 'LoadingScreen'; |
| 32 | + import * as itowns from 'itowns'; |
| 33 | + import * as debug from 'debug'; |
| 34 | + |
| 35 | + import { zoomToLayer } from './jsm/OGC3DTilesHelper.js'; |
| 36 | + |
| 37 | + const { |
| 38 | + WMTSSource, OGC3DTilesSource, |
| 39 | + ColorLayer, ElevationLayer, OGC3DTilesLayer, |
| 40 | + GlobeView, Coordinates, Fetcher, |
| 41 | + } = itowns; |
| 42 | + |
| 43 | + window.gui = new dat.GUI(); |
| 44 | + |
| 45 | + |
| 46 | + // ---- Create a GlobeView ---- |
| 47 | + |
| 48 | + // Define camera initial position |
| 49 | + const placement = { |
| 50 | + coord: new Coordinates('EPSG:4326', 2.351323, 48.856712), |
| 51 | + range: 12500000, |
| 52 | + }; |
| 53 | + |
| 54 | + // `viewerDiv` will contain iTowns' rendering area (`<canvas>`) |
| 55 | + const viewerDiv = document.getElementById('viewerDiv'); |
| 56 | + |
| 57 | + // Create a GlobeView |
| 58 | + const view = new GlobeView(viewerDiv, placement, { |
| 59 | + shadows: true, |
| 60 | + controls: { |
| 61 | + minDistance: 100, |
| 62 | + }, |
| 63 | + realisticLighting: true, |
| 64 | + }); |
| 65 | + |
| 66 | + // Setup loading screen |
| 67 | + setupLoadingScreen(viewerDiv, view); |
| 68 | + |
| 69 | + // ---- Add a basemap ---- |
| 70 | + |
| 71 | + Fetcher.json('./layers/JSONLayers/Ortho.json').then(function _(config) { |
| 72 | + config.source = new WMTSSource(config.source); |
| 73 | + view.addLayer(new ColorLayer('Ortho', config)); |
| 74 | + }); |
| 75 | + |
| 76 | + // ---- Add 3D terrain ---- |
| 77 | + |
| 78 | + // Add two elevation layers: world terrain and a more precise terrain for france |
| 79 | + // These will deform iTowns globe geometry to represent terrain elevation. |
| 80 | + function addElevationLayerFromConfig(config) { |
| 81 | + config.source = new WMTSSource(config.source); |
| 82 | + const elevationLayer = new ElevationLayer(config.id, config); |
| 83 | + view.addLayer(elevationLayer); |
| 84 | + } |
| 85 | + itowns.Fetcher.json('./layers/JSONLayers/IGN_MNT_HIGHRES.json').then(addElevationLayerFromConfig); |
| 86 | + itowns.Fetcher.json('./layers/JSONLayers/WORLD_DTM.json').then(addElevationLayerFromConfig); |
| 87 | + |
| 88 | + // ---------- 3D Tiles loading |
| 89 | + |
| 90 | + function load(url) { |
| 91 | + const source = new OGC3DTilesSource({ url }); |
| 92 | + |
| 93 | + window.layer = new OGC3DTilesLayer('3DTiles', { |
| 94 | + source, |
| 95 | + sseThreshold: 2, |
| 96 | + }); |
| 97 | + |
| 98 | + // Add the layer to our view |
| 99 | + view.addLayer(window.layer).then((layer) => { |
| 100 | + zoomToLayer(view, layer); |
| 101 | + }); |
| 102 | + |
| 103 | + window.layer.whenReady |
| 104 | + .then(() => debug.createOGC3DTilesDebugUI(gui, view, window.layer)); |
| 105 | + } |
| 106 | + |
| 107 | + // ---------- Realistic lighting & DATE/TIME CONTROLS ---------- |
| 108 | + debug.createRealisticLightingDebugUI(gui, view); |
| 109 | + |
| 110 | + window.layer = null; // 3D Tiles layer |
| 111 | + |
| 112 | + // ---------- Load Lille dataset ---------- |
| 113 | + load("https://webimaging.lillemetropole.fr/externe/maillage/2020_mel_5cm/tileset.json"); |
| 114 | + |
| 115 | + window.view = view; |
| 116 | + window.itowns = itowns; |
| 117 | + window.THREE = THREE; |
| 118 | + |
| 119 | + </script> |
| 120 | + </body> |
| 121 | +</html> |
0 commit comments