UNPKG

itowns

Version:

A JS/WebGL framework for 3D geospatial data visualization

186 lines (158 loc) 7.43 kB
<!DOCTYPE html> <html> <head> <title>Itowns - 6 planes on a cube</title> <meta charset="UTF-8"> <link rel="stylesheet" type="text/css" href="css/example.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"></div> <script src="../dist/itowns.js"></script> <script src="js/GUI/LoadingScreen.js"></script> <script type="importmap"> { "imports": { "three": "https://cdn.jsdelivr.net/npm/three@0.170.0/build/three.module.js", "three/addons/": "https://cdn.jsdelivr.net/npm/three@0.170.0/examples/jsm/" } } </script> <script type="module"> // Warning: For now, three is imported twice: in the itowns bundle // and from the unpkg CDN. import * as THREE from 'three'; import { OrbitControls } from 'three/addons/controls/OrbitControls.js'; var view; // Define crs projection that we will use (taken from https://epsg.io/3946, Proj4js section) 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'); // # Planar (EPSG:3946) viewer const wmsSources = [ { name: 'fpc_fond_plan_communaut.fpcilot', url: 'https://download.data.grandlyon.com/wms/grandlyon', }, { name: 'pvo_patrimoine_voirie.pvochausseetrottoir', url: 'https://download.data.grandlyon.com/wms/grandlyon', }, { name: 'ortho_latest', url: 'https://imagerie.data.grandlyon.com/wms/grandlyon', }, { name: 'pos_opposable.poshauvoi', url: 'https://download.data.grandlyon.com/wms/grandlyon', }, { name: 'MNT2015_Ombrage_2m', url: 'https://download.data.grandlyon.com/wms/grandlyon', }, { name: 'cad_cadastre.cadilot', url: 'https://download.data.grandlyon.com/wms/grandlyon', }, ]; const cubeTransformations = [ { position: new THREE.Vector3(0, 0, 0.5), rotation: new THREE.Euler(), }, { position: new THREE.Vector3(0, 0, -0.5), rotation: new THREE.Euler().set(Math.PI, 0, 0), }, { position: new THREE.Vector3(0, 0.5, 0), rotation: new THREE.Euler().set(-Math.PI * 0.5, 0, 0), }, { position: new THREE.Vector3(0, -0.5, 0), rotation: new THREE.Euler().set(Math.PI * 0.5, 0, 0), }, { position: new THREE.Vector3(0.5, 0, 0), rotation: new THREE.Euler().set(0, Math.PI * 0.5, 0), }, { position: new THREE.Vector3(-0.5, 0, 0), rotation: new THREE.Euler().set(0, -Math.PI * 0.5, 0), }, ]; // Define geographic extent: CRS, min/max X, min/max Y const extent = new itowns.Extent( 'EPSG:3946', 1837900, 1837900 + 8000, 5170100, 5170100 + 8000); // `viewerDiv` will contain iTowns' rendering area (`<canvas>`) const viewerDiv = document.getElementById('viewerDiv'); THREE.Object3D.DEFAULT_UP.set(0, 0, 1); const scale = new THREE.Vector3(1, 1, 1).divideScalar(extent.planarDimensions().x); // Instanciate View view = new itowns.View(extent.crs, viewerDiv); setupLoadingScreen(viewerDiv, view); view.mainLoop.gfxEngine.renderer.setClearColor(0x999999); const parent = new THREE.Mesh( new THREE.BoxGeometry(8000, 8000, 8000), new THREE.MeshBasicMaterial({ color: 0xdddddd })); parent.scale.copy(scale); parent.updateMatrixWorld(true); view.scene.add(parent); const elevationSource = new itowns.WMSSource({ extent, version: '1.3.0', name: 'MNT2018_Altitude_2m', crs: 'EPSG:3946', width: 256, format: 'image/jpeg', url: 'https://imagerie.data.grandlyon.com/wms/grandlyon', }); for (let index = 0; index < wmsSources.length; index++) { const wms = wmsSources[index]; const obj = new THREE.Object3D(); const offset = extent.center().toVector3().negate().applyEuler(cubeTransformations[index].rotation); offset.add(cubeTransformations[index].position.divide(scale)); obj.position.copy(offset); obj.rotation.copy(cubeTransformations[index].rotation); parent.add(obj); obj.updateMatrixWorld(true); const tileLayer = new itowns.PlanarLayer('planar' + wms.name + index, extent, obj, { disableSkirt: true }); view.addLayer(tileLayer); const colorSource = new itowns.WMSSource({ url: wms.url, version: '1.3.0', name: wms.name, crs: 'EPSG:3946', format: 'image/jpeg', extent, }); const colorLayer = new itowns.ColorLayer('wms_imagery' + wms.name + index, { source: colorSource, }); view.addLayer(colorLayer, tileLayer); const elevationLayer = new itowns.ElevationLayer('wms_elevation' + wms.name + index, { source: elevationSource, useColorTextureElevation: true, colorTextureElevationMinZ: 144, colorTextureElevationMaxZ: 622, }); view.addLayer(elevationLayer, tileLayer); } // Since PlanarView doesn't create default controls, we manipulate directly three.js camera // Position the camera at south-west corner view.camera3D.position.set(3, 2, 3); view.camera3D.updateMatrixWorld(true); view.camera3D.lookAt(new THREE.Vector3(0, 0, 0)); const controls = new OrbitControls(view.camera3D, viewerDiv); controls.minDistance = 1; controls.addEventListener('change', function _() { view.notifyChange(view.camera3D); }); // Request redraw view.notifyChange(); // Warning: the following code is not part of this example, those // variables are only exposed for internal functional test uses. window.view = view; </script> </body> </html>