|
| 1 | +<!DOCTYPE html> |
1 | 2 | <html> |
2 | 3 | <head> |
3 | 4 | <title>Itowns - 6 planes on a cube</title> |
|
12 | 13 | <div id="viewerDiv"></div> |
13 | 14 | <script src="../dist/itowns.js"></script> |
14 | 15 | <script src="js/GUI/LoadingScreen.js"></script> |
15 | | - <script type="text/javascript"> |
16 | | - window.THREE = itowns.THREE; |
| 16 | + |
| 17 | + <script type="importmap"> |
| 18 | + { |
| 19 | + "imports": { |
| 20 | + "three": "https://unpkg.com/[email protected]/build/three.module.js", |
| 21 | + "three/addons/": "https://unpkg.com/[email protected]/examples/jsm/" |
| 22 | + } |
| 23 | + } |
17 | 24 | </script> |
18 | | - <script src=" https://unpkg.com/[email protected]/examples/js/controls/OrbitControls.js" ></script> |
19 | | - <script type="text/javascript"> |
| 25 | + |
| 26 | + <script type="module"> |
| 27 | + // Warning: For now, three is imported twice: in the itowns bundle |
| 28 | + // and from the unpkg CDN. |
| 29 | + import * as THREE from 'three'; |
| 30 | + import { OrbitControls } from 'three/addons/controls/OrbitControls.js'; |
| 31 | + |
| 32 | + var view; |
| 33 | + |
20 | 34 | // Define crs projection that we will use (taken from https://epsg.io/3946, Proj4js section) |
21 | 35 | 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 | 36 | // # Planar (EPSG:3946) viewer |
23 | 37 |
|
24 | | - var extent; |
25 | | - var viewerDiv; |
26 | | - var view; |
27 | | - var controls; |
28 | | - var scale; |
29 | | - var parent; |
30 | | - var index; |
31 | | - var wms; |
32 | | - var wmsUrl; |
33 | | - var obj; |
34 | | - var offset; |
35 | | - var tileLayer; |
36 | | - var config; |
37 | | - |
38 | | - var wmsSources = [ |
| 38 | + const wmsSources = [ |
39 | 39 | { |
40 | 40 | name: 'fpc_fond_plan_communaut.fpcilot', |
41 | 41 | url: 'https://download.data.grandlyon.com/wms/grandlyon', |
|
62 | 62 | }, |
63 | 63 | ]; |
64 | 64 |
|
65 | | - var cubeTransformations = [ |
| 65 | + const cubeTransformations = [ |
66 | 66 | { |
67 | | - position: new itowns.THREE.Vector3(0, 0, 0.5), |
68 | | - rotation: new itowns.THREE.Euler(), |
| 67 | + position: new THREE.Vector3(0, 0, 0.5), |
| 68 | + rotation: new THREE.Euler(), |
69 | 69 | }, |
70 | 70 | { |
71 | | - position: new itowns.THREE.Vector3(0, 0, -0.5), |
72 | | - rotation: new itowns.THREE.Euler().set(Math.PI, 0, 0), |
| 71 | + position: new THREE.Vector3(0, 0, -0.5), |
| 72 | + rotation: new THREE.Euler().set(Math.PI, 0, 0), |
73 | 73 | }, |
74 | 74 | { |
75 | | - position: new itowns.THREE.Vector3(0, 0.5, 0), |
76 | | - rotation: new itowns.THREE.Euler().set(-Math.PI * 0.5, 0, 0), |
| 75 | + position: new THREE.Vector3(0, 0.5, 0), |
| 76 | + rotation: new THREE.Euler().set(-Math.PI * 0.5, 0, 0), |
77 | 77 | }, |
78 | 78 | { |
79 | | - position: new itowns.THREE.Vector3(0, -0.5, 0), |
80 | | - rotation: new itowns.THREE.Euler().set(Math.PI * 0.5, 0, 0), |
| 79 | + position: new THREE.Vector3(0, -0.5, 0), |
| 80 | + rotation: new THREE.Euler().set(Math.PI * 0.5, 0, 0), |
81 | 81 | }, |
82 | 82 | { |
83 | | - position: new itowns.THREE.Vector3(0.5, 0, 0), |
84 | | - rotation: new itowns.THREE.Euler().set(0, Math.PI * 0.5, 0), |
| 83 | + position: new THREE.Vector3(0.5, 0, 0), |
| 84 | + rotation: new THREE.Euler().set(0, Math.PI * 0.5, 0), |
85 | 85 | }, |
86 | 86 | { |
87 | | - position: new itowns.THREE.Vector3(-0.5, 0, 0), |
88 | | - rotation: new itowns.THREE.Euler().set(0, -Math.PI * 0.5, 0), |
| 87 | + position: new THREE.Vector3(-0.5, 0, 0), |
| 88 | + rotation: new THREE.Euler().set(0, -Math.PI * 0.5, 0), |
89 | 89 | }, |
90 | 90 | ]; |
91 | 91 |
|
92 | 92 | // Define geographic extent: CRS, min/max X, min/max Y |
93 | | - extent = new itowns.Extent( |
| 93 | + const extent = new itowns.Extent( |
94 | 94 | 'EPSG:3946', |
95 | 95 | 1837900, 1837900 + 8000, |
96 | 96 | 5170100, 5170100 + 8000); |
97 | 97 |
|
98 | 98 | // `viewerDiv` will contain iTowns' rendering area (`<canvas>`) |
99 | | - viewerDiv = document.getElementById('viewerDiv'); |
| 99 | + const viewerDiv = document.getElementById('viewerDiv'); |
100 | 100 |
|
101 | | - itowns.THREE.Object3D.DEFAULT_UP.set(0, 0, 1); |
| 101 | + THREE.Object3D.DEFAULT_UP.set(0, 0, 1); |
102 | 102 |
|
103 | | - scale = new itowns.THREE.Vector3(1, 1, 1).divideScalar(extent.planarDimensions().x); |
| 103 | + const scale = new THREE.Vector3(1, 1, 1).divideScalar(extent.planarDimensions().x); |
104 | 104 |
|
105 | 105 | // Instanciate View |
106 | 106 | view = new itowns.View(extent.crs, viewerDiv); |
107 | 107 | setupLoadingScreen(viewerDiv, view); |
108 | 108 |
|
109 | 109 | view.mainLoop.gfxEngine.renderer.setClearColor(0x999999); |
110 | 110 |
|
111 | | - parent = new itowns.THREE.Mesh( |
112 | | - new itowns.THREE.BoxGeometry(8000, 8000, 8000), |
113 | | - new itowns.THREE.MeshBasicMaterial({ color: 0xdddddd })); |
| 111 | + const parent = new THREE.Mesh( |
| 112 | + new THREE.BoxGeometry(8000, 8000, 8000), |
| 113 | + new THREE.MeshBasicMaterial({ color: 0xdddddd })); |
114 | 114 | parent.scale.copy(scale); |
115 | 115 | parent.updateMatrixWorld(true); |
116 | 116 |
|
117 | 117 | view.scene.add(parent); |
118 | | - var elevationSource = new itowns.WMSSource({ |
| 118 | + const elevationSource = new itowns.WMSSource({ |
119 | 119 | extent, |
120 | 120 | version: '1.3.0', |
121 | 121 | name: 'MNT2018_Altitude_2m', |
|
125 | 125 | url: 'https://imagerie.data.grandlyon.com/wms/grandlyon', |
126 | 126 | }); |
127 | 127 |
|
128 | | - for (index = 0; index < wmsSources.length; index++) { |
129 | | - wms = wmsSources[index]; |
130 | | - obj = new itowns.THREE.Object3D(); |
131 | | - offset = extent.center().toVector3().negate().applyEuler(cubeTransformations[index].rotation); |
| 128 | + for (let index = 0; index < wmsSources.length; index++) { |
| 129 | + const wms = wmsSources[index]; |
| 130 | + const obj = new THREE.Object3D(); |
| 131 | + const offset = extent.center().toVector3().negate().applyEuler(cubeTransformations[index].rotation); |
132 | 132 | offset.add(cubeTransformations[index].position.divide(scale)); |
133 | 133 | obj.position.copy(offset); |
134 | 134 | obj.rotation.copy(cubeTransformations[index].rotation); |
135 | 135 | parent.add(obj); |
136 | 136 | obj.updateMatrixWorld(true); |
137 | 137 |
|
138 | | - tileLayer = new itowns.PlanarLayer('planar' + wms.name + index, |
| 138 | + const tileLayer = new itowns.PlanarLayer('planar' + wms.name + index, |
139 | 139 | extent, obj, { disableSkirt: true }); |
140 | 140 |
|
141 | 141 | view.addLayer(tileLayer); |
142 | 142 |
|
143 | | - var colorSource = new itowns.WMSSource({ |
| 143 | + const colorSource = new itowns.WMSSource({ |
144 | 144 | url: wms.url, |
145 | 145 | version: '1.3.0', |
146 | 146 | name: wms.name, |
147 | 147 | crs: 'EPSG:3946', |
148 | 148 | format: 'image/jpeg', |
149 | 149 | extent, |
150 | 150 | }); |
151 | | - var colorLayer = new itowns.ColorLayer('wms_imagery' + wms.name + index, { |
| 151 | + const colorLayer = new itowns.ColorLayer('wms_imagery' + wms.name + index, { |
152 | 152 | source: colorSource, |
153 | 153 | }); |
154 | 154 | view.addLayer(colorLayer, tileLayer); |
155 | | - var elevationLayer = new itowns.ElevationLayer('wms_elevation' + wms.name + index, { |
| 155 | + const elevationLayer = new itowns.ElevationLayer('wms_elevation' + wms.name + index, { |
156 | 156 | source: elevationSource, |
157 | 157 | useColorTextureElevation: true, |
158 | 158 | colorTextureElevationMinZ: 144, |
|
166 | 166 | // Position the camera at south-west corner |
167 | 167 | view.camera3D.position.set(3, 2, 3); |
168 | 168 | view.camera3D.updateMatrixWorld(true); |
169 | | - view.camera3D.lookAt(new itowns.THREE.Vector3(0, 0, 0)); |
| 169 | + view.camera3D.lookAt(new THREE.Vector3(0, 0, 0)); |
170 | 170 |
|
171 | | - controls = new itowns.THREE.OrbitControls(view.camera3D, viewerDiv); |
| 171 | + const controls = new OrbitControls(view.camera3D, viewerDiv); |
172 | 172 | controls.minDistance = 1; |
173 | 173 | controls.addEventListener('change', function _() { view.notifyChange(view.camera3D); }); |
174 | 174 |
|
175 | 175 | // Request redraw |
176 | 176 | view.notifyChange(); |
| 177 | + |
| 178 | + |
| 179 | + // Warning: the following code is not part of this example, those |
| 180 | + // variables are only exposed for internal functional test uses. |
| 181 | + window.view = view; |
| 182 | + |
177 | 183 | </script> |
178 | 184 | </body> |
179 | 185 | </html> |
0 commit comments