UNPKG

itowns

Version:

A JS/WebGL framework for 3D geospatial data visualization

151 lines (128 loc) 6.29 kB
<html> <head> <title>Itowns - 3D Tiles Style Widget </title> <script type="importmap"> { "imports": { "itowns": "../dist/itowns.js", "debug": "../dist/debug.js", "dat": "https://unpkg.com/dat.gui@0.7.9/build/dat.gui.module.js", "GuiTools": "./jsm/GUI/GuiTools.js", "LoadingScreen": "./jsm/GUI/LoadingScreen.js", "itowns_widgets": "../dist/itowns_widgets.js", "three": "https://unpkg.com/three@0.170.0/build/three.module.js", "three/addons/": "https://unpkg.com/three@0.170.0/examples/jsm/" } } </script> <meta charset="UTF-8"> <link rel="stylesheet" type="text/css" href="css/example.css"> <link rel="stylesheet" type="text/css" href="css/widgets.css"> <link rel="stylesheet" type="text/css" href="css/LoadingScreen.css"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> </head> <body> <div id="viewerDiv" class="viewer"></div> <script type="module"> import GuiTools from 'GuiTools'; import setupLoadingScreen from 'LoadingScreen'; import * as THREE from 'three'; import * as itowns from 'itowns'; import * as debug from 'debug'; import * as itowns_widgets from 'itowns_widgets'; // Define crs projection that we will use (taken from https://epsg.io/3946, Proj4js section) itowns.CRS.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'); // Define geographic extent: CRS, min/max X, min/max Y const extent = new itowns.Extent( 'EPSG:3946', 1840816.94334, 1843692.32501, 5175036.4587, 5177412.82698); // `viewerDiv` will contain iTowns' rendering area (`<canvas>`) const viewerDiv = document.getElementById('viewerDiv'); // Instanciate PlanarView* const cameraCoord = new itowns.Coordinates('EPSG:3946', 1841980, 5175682, 3000) const view = new itowns.PlanarView(viewerDiv, extent, { placement: { coord: cameraCoord, heading: 30, range: 4000, tilt: 30 } }); setupLoadingScreen(viewerDiv, view); // Add a WMS imagery source const wmsImagerySource = new itowns.WMSSource({ extent: extent, name: 'ortho_latest', url: 'https://imagerie.data.grandlyon.com/wms/grandlyon', version: '1.3.0', crs: 'EPSG:3946', format: 'image/jpeg', }); // Add a WMS imagery layer const wmsImageryLayer = new itowns.ColorLayer('wms_imagery', { updateStrategy: { type: itowns.STRATEGY_DICHOTOMY, options: {}, }, source: wmsImagerySource, }); view.addLayer(wmsImageryLayer); // Add a WMS elevation source const wmsElevationSource = new itowns.WMSSource({ extent: extent, url: 'https://imagerie.data.grandlyon.com/wms/grandlyon', name: 'MNT2018_Altitude_2m', crs: 'EPSG:3946', width: 256, format: 'image/jpeg', }); // Add a WMS elevation layer const wmsElevationLayer = new itowns.ElevationLayer('wms_elevation', { useColorTextureElevation: true, colorTextureElevationMinZ: 144, colorTextureElevationMaxZ: 622, source: wmsElevationSource, }); view.addLayer(wmsElevationLayer); const $3dTilesLayer = new itowns.C3DTilesLayer( 0, { name: 'First Lyon Rounding 2018', source: new itowns.C3DTilesSource({ url: 'https://raw.githubusercontent.com/iTowns/iTowns2-sample-data/master/' + '3DTiles/lyon1_with_surface_type_2018/tileset.json', }) }, view); itowns.View.prototype.addLayer.call(view, $3dTilesLayer); // Lights const dirLight = new THREE.DirectionalLight(0xffffff, 1); dirLight.position.set(-0.9, 0.3, 1); dirLight.updateMatrixWorld(); view.scene.add( dirLight ); const ambLight = new THREE.AmbientLight(0xffffff, 0.2); view.scene.add( ambLight ); // Request redraw view.notifyChange(); // Add 3D Tiles Style Widget const widget = new itowns_widgets.C3DTilesStyle(view); widget.domElement.setAttribute('id', 'widgets-3dtilesstyle'); // Add a box3 to C3DTileFeature onclick const geometry = new THREE.BoxGeometry(); const material = new THREE.MeshBasicMaterial( {color: 0x00ff00, opacity: 0.5, transparent: true} ); const cube = new THREE.Mesh( geometry, material ); view.domElement.onclick = (event) => { const intersects = view.pickObjectsAt(event, 5, [$3dTilesLayer]); const c3DTileFeatureClicked = $3dTilesLayer.getC3DTileFeatureFromIntersectsArray(intersects); if (c3DTileFeatureClicked) { const worldBox3 = c3DTileFeatureClicked.computeWorldBox3(); cube.scale.copy(worldBox3.max.clone().sub(worldBox3.min)); worldBox3.getCenter(cube.position); cube.updateMatrixWorld(); view.scene.add(cube); view.notifyChange(); } } // Add a debug UI const menu = new GuiTools('menuDiv', view); const d = new debug.Debug(view, menu.gui); debug.createTileDebugUI(menu.gui, view, view.tileLayer, d); window.view = view; window.itowns = itowns; window.THREE = THREE; </script> </body> </html>