|
| 1 | +<html> |
| 2 | + <head> |
| 3 | + <title>Itowns - 3D Tiles Style Widget </title> |
| 4 | + |
| 5 | + <meta charset="UTF-8"> |
| 6 | + <link rel="stylesheet" type="text/css" href="css/example.css"> |
| 7 | + <link rel="stylesheet" type="text/css" href="css/widgets.css"> |
| 8 | + <link rel="stylesheet" type="text/css" href="css/LoadingScreen.css"> |
| 9 | + <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 10 | + <script src="https://cdnjs.cloudflare.com/ajax/libs/dat-gui/0.7.6/dat.gui.min.js"></script> |
| 11 | + </head> |
| 12 | + <body> |
| 13 | + <div id="viewerDiv" class="viewer"></div> |
| 14 | + <script src="../dist/itowns.js"></script> |
| 15 | + <script src="../dist/itowns_widgets.js"></script> |
| 16 | + <script src="js/GUI/LoadingScreen.js"></script> |
| 17 | + <script src="../dist/debug.js"></script> |
| 18 | + <script src="js/GUI/GuiTools.js"></script> |
| 19 | + <script type="text/javascript"> |
| 20 | + // Define crs projection that we will use (taken from https://epsg.io/3946, Proj4js section) |
| 21 | + itowns.proj4.defs('EPSG:3946', '+proj=lcc +lat_1=45.25 +lat_2=46.75 +lat_0=46 +lon_0=3 +x_0=1700000 +y_0=5200000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs'); |
| 22 | + |
| 23 | + // Define geographic extent: CRS, min/max X, min/max Y |
| 24 | + const extent = new itowns.Extent( 'EPSG:3946', |
| 25 | + 1840816.94334, 1843692.32501, |
| 26 | + 5175036.4587, 5177412.82698); |
| 27 | + |
| 28 | + // `viewerDiv` will contain iTowns' rendering area (`<canvas>`) |
| 29 | + const viewerDiv = document.getElementById('viewerDiv'); |
| 30 | + |
| 31 | + // Instanciate PlanarView* |
| 32 | + const cameraCoord = new itowns.Coordinates('EPSG:3946', 1841980, |
| 33 | + 5175682, 3000) |
| 34 | + const view = new itowns.PlanarView(viewerDiv, extent, { placement: { |
| 35 | + coord: cameraCoord, heading: 30, range: 4000, tilt: 30 } }); |
| 36 | + |
| 37 | + setupLoadingScreen(viewerDiv, view); |
| 38 | + |
| 39 | + // Add a WMS imagery source |
| 40 | + const wmsImagerySource = new itowns.WMSSource({ |
| 41 | + extent: extent, |
| 42 | + name: 'Ortho2009_vue_ensemble_16cm_CC46', |
| 43 | + url: 'https://download.data.grandlyon.com/wms/grandlyon', |
| 44 | + version: '1.3.0', |
| 45 | + crs: 'EPSG:3946', |
| 46 | + format: 'image/jpeg', |
| 47 | + }); |
| 48 | + |
| 49 | + // Add a WMS imagery layer |
| 50 | + const wmsImageryLayer = new itowns.ColorLayer('wms_imagery', { |
| 51 | + updateStrategy: { |
| 52 | + type: itowns.STRATEGY_DICHOTOMY, |
| 53 | + options: {}, |
| 54 | + }, |
| 55 | + source: wmsImagerySource, |
| 56 | + }); |
| 57 | + |
| 58 | + view.addLayer(wmsImageryLayer); |
| 59 | + |
| 60 | + // Add a WMS elevation source |
| 61 | + const wmsElevationSource = new itowns.WMSSource({ |
| 62 | + extent: extent, |
| 63 | + url: 'https://download.data.grandlyon.com/wms/grandlyon', |
| 64 | + name: 'MNT2012_Altitude_10m_CC46', |
| 65 | + crs: 'EPSG:3946', |
| 66 | + width: 256, |
| 67 | + format: 'image/jpeg', |
| 68 | + }); |
| 69 | + |
| 70 | + // Add a WMS elevation layer |
| 71 | + const wmsElevationLayer = new itowns.ElevationLayer('wms_elevation', { |
| 72 | + useColorTextureElevation: true, |
| 73 | + colorTextureElevationMinZ: 144, |
| 74 | + colorTextureElevationMaxZ: 622, |
| 75 | + source: wmsElevationSource, |
| 76 | + }); |
| 77 | + |
| 78 | + view.addLayer(wmsElevationLayer); |
| 79 | + |
| 80 | + const $3dTilesLayer = new itowns.C3DTilesLayer( |
| 81 | + 0, { |
| 82 | + name: 'First Lyon Rounding 2018', |
| 83 | + source: new itowns.C3DTilesSource({ |
| 84 | + url: 'https://raw.githubusercontent.com/iTowns/iTowns2-sample-data/master/' + |
| 85 | + '3DTiles/lyon1_with_surface_type_2018/tileset.json', |
| 86 | + }) |
| 87 | + }, view); |
| 88 | + itowns.View.prototype.addLayer.call(view, $3dTilesLayer); |
| 89 | + |
| 90 | + // Lights |
| 91 | + const dirLight = new itowns.THREE.DirectionalLight(0xffffff, 1); |
| 92 | + dirLight.position.set(-0.9, 0.3, 1); |
| 93 | + dirLight.updateMatrixWorld(); |
| 94 | + view.scene.add( dirLight ); |
| 95 | + |
| 96 | + const ambLight = new itowns.THREE.AmbientLight(0xffffff, 0.2); |
| 97 | + view.scene.add( ambLight ); |
| 98 | + |
| 99 | + // Request redraw |
| 100 | + view.notifyChange(); |
| 101 | + |
| 102 | + // Add 3D Tiles Style Widget |
| 103 | + const widget = new itowns_widgets.C3DTilesStyle(view); |
| 104 | + widget.domElement.setAttribute('id', 'widgets-3dtilesstyle'); |
| 105 | + |
| 106 | + // Add a box3 to C3DTileFeature onclick |
| 107 | + const geometry = new itowns.THREE.BoxGeometry(); |
| 108 | + const material = new itowns.THREE.MeshBasicMaterial( {color: 0x00ff00, opacity: 0.5, transparent: true} ); |
| 109 | + const cube = new itowns.THREE.Mesh( geometry, material ); |
| 110 | + view.domElement.onclick = (event) => { |
| 111 | + const intersects = view.pickObjectsAt(event, 0, [$3dTilesLayer]); |
| 112 | + const c3DTileFeatureClicked = $3dTilesLayer.getC3DTileFeatureFromIntersectsArray(intersects); |
| 113 | + |
| 114 | + if (c3DTileFeatureClicked) { |
| 115 | + const worldBox3 = $3dTilesLayer.computeWorldBox3(c3DTileFeatureClicked); |
| 116 | + cube.scale.copy(worldBox3.max.clone().sub(worldBox3.min)); |
| 117 | + worldBox3.getCenter(cube.position); |
| 118 | + cube.updateMatrixWorld(); |
| 119 | + view.scene.add(cube); |
| 120 | + view.notifyChange(); |
| 121 | + } |
| 122 | + } |
| 123 | + |
| 124 | + // Add a debug UI |
| 125 | + const menu = new GuiTools('menuDiv', view); |
| 126 | + const d = new debug.Debug(view, menu.gui); |
| 127 | + debug.createTileDebugUI(menu.gui, view, view.tileLayer, d); |
| 128 | + </script> |
| 129 | + </body> |
| 130 | +</html> |
0 commit comments