itowns 2.36.2 → 2.37.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/CONTRIBUTING.md +30 -17
  2. package/changelog.md +52 -0
  3. package/dist/debug.js +1 -1
  4. package/dist/debug.js.LICENSE.txt +1 -1
  5. package/dist/debug.js.map +1 -1
  6. package/dist/itowns.js +1 -1
  7. package/dist/itowns.js.map +1 -1
  8. package/dist/itowns_widgets.js +2 -0
  9. package/dist/itowns_widgets.js.map +1 -0
  10. package/examples/config.json +25 -6
  11. package/examples/css/widgets.css +248 -0
  12. package/examples/geoid_geoidLayer.html +102 -0
  13. package/examples/images/compass.svg +60 -0
  14. package/examples/images/widget-logo.svg +66 -0
  15. package/examples/itowns-potree.html +252 -0
  16. package/examples/js/GUI/GuiTools.js +17 -0
  17. package/examples/js/Scale.js +1 -0
  18. package/examples/source_file_from_fetched_data.html +90 -0
  19. package/examples/source_file_from_format.html +85 -0
  20. package/examples/source_file_from_methods.html +87 -0
  21. package/examples/source_file_from_parsed_data.html +104 -0
  22. package/examples/source_file_geojson_raster.html +21 -45
  23. package/examples/source_file_gpx_raster.html +28 -36
  24. package/examples/source_file_kml_raster.html +1 -4
  25. package/examples/source_file_shapefile.html +39 -34
  26. package/examples/source_stream_wfs_25d.html +21 -13
  27. package/examples/source_stream_wfs_3d.html +21 -12
  28. package/examples/source_stream_wfs_raster.html +20 -20
  29. package/examples/view_immersive.html +13 -14
  30. package/examples/widgets_minimap.html +122 -0
  31. package/examples/widgets_navigation.html +119 -0
  32. package/lib/Controls/GlobeControls.js +13 -0
  33. package/lib/Controls/PlanarControls.js +1 -1
  34. package/lib/Converter/convertToTile.js +5 -1
  35. package/lib/Core/3DTiles/C3DTBoundingVolume.js +4 -1
  36. package/lib/Core/Deprecated/Undeprecator.js +1 -1
  37. package/lib/Core/Feature.js +3 -4
  38. package/lib/Core/Geographic/Extent.js +1 -1
  39. package/lib/Core/Geographic/GeoidGrid.js +143 -0
  40. package/lib/Core/MainLoop.js +1 -1
  41. package/lib/Core/Math/Ellipsoid.js +1 -1
  42. package/lib/Core/Prefab/Globe/SkyShader.js +3 -1
  43. package/lib/Core/Prefab/Planar/PlanarLayer.js +3 -1
  44. package/lib/Core/Style.js +1 -1
  45. package/lib/Core/TileGeometry.js +3 -1
  46. package/lib/Core/TileMesh.js +11 -17
  47. package/lib/Core/View.js +40 -2
  48. package/lib/Layer/ElevationLayer.js +6 -2
  49. package/lib/Layer/FeatureGeometryLayer.js +3 -1
  50. package/lib/Layer/GeoidLayer.js +131 -0
  51. package/lib/Layer/InfoLayer.js +1 -1
  52. package/lib/Layer/Layer.js +1 -1
  53. package/lib/Layer/LayerUpdateStrategy.js +1 -1
  54. package/lib/Layer/PotreeLayer.js +3 -1
  55. package/lib/Layer/TiledGeometryLayer.js +3 -1
  56. package/lib/Main.js +214 -174
  57. package/lib/MainBundle.js +1 -1
  58. package/lib/Parser/B3dmParser.js +2 -1
  59. package/lib/Parser/GDFParser.js +118 -0
  60. package/lib/Parser/GTXParser.js +92 -0
  61. package/lib/Parser/ISGParser.js +121 -0
  62. package/lib/Parser/LASParser.js +3 -1
  63. package/lib/Parser/XbilParser.js +1 -1
  64. package/lib/Process/3dTilesProcessing.js +2 -2
  65. package/lib/Process/FeatureProcessing.js +3 -1
  66. package/lib/Process/LayeredMaterialNodeProcessing.js +7 -4
  67. package/lib/Provider/URLBuilder.js +1 -1
  68. package/lib/Renderer/LayeredMaterial.js +2 -2
  69. package/lib/Renderer/OBB.js +18 -25
  70. package/lib/Renderer/PointsMaterial.js +5 -6
  71. package/lib/Renderer/RasterTile.js +1 -1
  72. package/lib/Renderer/Shader/ShaderUtils.js +4 -2
  73. package/lib/Source/C3DTilesSource.js +3 -1
  74. package/lib/Source/EntwinePointTileSource.js +3 -1
  75. package/lib/Source/PotreeSource.js +3 -1
  76. package/lib/Source/Source.js +15 -10
  77. package/lib/Source/WMTSSource.js +3 -1
  78. package/lib/ThreeExtended/loaders/GLTFLoader.js +85 -35
  79. package/lib/Utils/CameraUtils.js +11 -1
  80. package/lib/Utils/DEMUtils.js +1 -1
  81. package/lib/Utils/FeaturesUtils.js +8 -4
  82. package/package.json +25 -25
@@ -0,0 +1,252 @@
1
+ <html>
2
+ <head>
3
+ <title>iTowns - Potree</title>
4
+
5
+ <meta charset="UTF-8">
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
+
8
+ <link rel="stylesheet" type="text/css" href="css/example.css">
9
+ <link rel="stylesheet" type="text/css" href="css/LoadingScreen.css">
10
+
11
+ <link rel="stylesheet" type="text/css" href="../potree/build/potree/potree.css">
12
+ <link rel="stylesheet" type="text/css" href="../potree/libs/jquery-ui/jquery-ui.min.css">
13
+ <link rel="stylesheet" type="text/css" href="../potree/libs/spectrum/spectrum.css">
14
+ <link rel="stylesheet" type="text/css" href="../potree/libs/jstree/themes/mixed/style.css">
15
+
16
+ <style type="text/css">
17
+ tr { color: white; }
18
+ </style>
19
+ </head>
20
+ <body>
21
+
22
+ <div class="potree_container" style="position: absolute; width: 100%; height: 100%; left: 0px; top: 0px; ">
23
+ <div id="potree_render_area"></div>
24
+ <div id="potree_sidebar_container"></div>
25
+ </div>
26
+
27
+ <!-- Import iTowns source code -->
28
+ <script src="../dist/itowns.js"></script>
29
+ <script src="../dist/debug.js"></script>
30
+ <!-- Import iTowns LoadingScreen pluggin -->
31
+ <script src="js/GUI/LoadingScreen.js"></script>
32
+
33
+ <!-- Define THREE and proj4 constants so that Potree may access them. Otherwise, we would need to access them
34
+ with `itowns.THREE` or `itowns.proj4`. -->
35
+ <script type="text/javascript">
36
+ const THREE = itowns.THREE;
37
+ THREE.Object3D.DefaultUp.set(0, 0, 1);
38
+
39
+ const proj4 = itowns.proj4;
40
+ </script>
41
+
42
+ <!-- Import Potree source code -->
43
+ <script src="../potree/libs/jquery/jquery-3.1.1.min.js"></script>
44
+ <script src="../potree/libs/i18next/i18next.js"></script>
45
+ <script src="../potree/libs/jstree/jstree.min.js"></script>
46
+ <script src="../potree/libs/plasio/js/laslaz.js"></script>
47
+ <script src="../potree/build/potree/potree.js"></script>
48
+
49
+ <script type="text/javascript">
50
+
51
+
52
+
53
+ // `viewerDiv` contains both iTowns and Potree rendering area (`<canvas>`)
54
+ const viewerDiv = document.getElementById('potree_render_area');
55
+
56
+
57
+
58
+ // ---------- CREATE A POTREE VIEWER FOR SUPPORTING POINT CLOUD VISUALIZATION : ----------
59
+
60
+ const coordinates = new itowns.Coordinates('EPSG:4978');
61
+
62
+ // Define crs projection of the point cloud data (taken from https://epsg.io/2154, Proj4js section)
63
+ proj4.defs(
64
+ 'EPSG:2154',
65
+ '+proj=lcc +lat_1=49 +lat_2=44 +lat_0=46.5 +lon_0=3 +x_0=700000 +y_0=6600000 +ellps=GRS80'
66
+ + ' towgs84=0,0,0,0,0,0,0 +units=m +no_defs'
67
+ );
68
+ const pointCloudCRS = 'EPSG:2154';
69
+
70
+ Potree.setTHREEShaderChunk(itowns.ShaderChunk.target);
71
+
72
+ // Create a Potree Viewer to support point cloud visualization
73
+ const potreeViewer = new Potree.Viewer(viewerDiv, {
74
+ dynamicNearFar: false,
75
+ isGeocentric: true,
76
+ crs: pointCloudCRS,
77
+
78
+ // Callback to transform coordinates displayed by Potree `Point measurement` in `EPSG:2154`
79
+ measureCoordinateCallback: (position) => {
80
+ return coordinates.setFromVector3(position).as(pointCloudCRS).toVector3();
81
+ },
82
+ });
83
+
84
+ potreeViewer.setEDLEnabled(true);
85
+ potreeViewer.setControls(null);
86
+ potreeViewer.setBackground('black');
87
+ potreeViewer.loadGUI();
88
+
89
+ // Override Potree area measure method. The original Potree method gives a planar area delimited from given
90
+ // points (summits of the area). The area returned by the method is computed from `x` and `y` components of
91
+ // the points coordinates.
92
+ //
93
+ // By default, the points coordinates passed to the method are in iTowns viewer CRS, which is geocentric.
94
+ // Therefore, computing an area over the `x` and `y` components of these coordinates is incorrect - it
95
+ // actualy computes its orthogonal projection on the equatorial plane.
96
+ //
97
+ // To fix this, we transform each coordinates of the area summits in the point cloud CRS, which is
98
+ // geographic. We store each transformed coordinates in an array. Finally we override Potree area measure
99
+ // method so that it computes area from this array.
100
+ potreeViewer.scene.addEventListener('measurement_added', (e) => {
101
+ const { measurement } = e;
102
+
103
+ if(measurement.name === "Area") {
104
+ // Array containing the geographic coordinates of each area summits
105
+ const areaPoints = [new itowns.Coordinates(pointCloudCRS)];
106
+
107
+ // Add a Coordinates to the array when an area summit is created.
108
+ measurement.addEventListener('marker_added', () => {
109
+ areaPoints.push(new itowns.Coordinates(pointCloudCRS));
110
+ }, false)
111
+ // Translate the area summit coordinates from itowns viewer CRS to geographic CRS when the summit is
112
+ // moved. It also happens when the summit is created.
113
+ measurement.addEventListener('marker_moved', (event) => {
114
+ coordinates.setFromVector3(event.position).as(pointCloudCRS, areaPoints[event.index]);
115
+ }, false);
116
+ // Clear the coordinates array when we remove an area summit.
117
+ measurement.addEventListener('marker_removed', () => {
118
+ areaPoints.splice(areaPoints.length - 1, 1);
119
+ }, false);
120
+
121
+ // Override potree `Measure.getArea` method to use projected coordinates to compute area
122
+ measurement.getArea = () => {
123
+ let area = 0;
124
+ let j = areaPoints.length - 1;
125
+
126
+ for (let i = 0; i < areaPoints.length; i++) {
127
+ let p1 = areaPoints[i];
128
+ let p2 = areaPoints[j];
129
+ area += (p2.x + p1.x) * (p1.y - p2.y);
130
+ j = i
131
+ }
132
+
133
+ return Math.abs(area / 2);
134
+ };
135
+ }
136
+ });
137
+
138
+
139
+
140
+ // ---------- CREATE A GlobeView FOR SUPPORTING ORTHO-PHOTOGRAPHIES AND DEM VISUALIZATION : ----------
141
+
142
+ // Define camera initial position.
143
+ const placement = {
144
+ heading: -35,
145
+ tilt: 30,
146
+ }
147
+
148
+ // Create a GlobeView.
149
+ const itownsViewer = new itowns.GlobeView(viewerDiv, placement, {
150
+ renderer: potreeViewer.renderer,
151
+ scene3D: potreeViewer.scene.scene,
152
+ });
153
+
154
+ // Setup loading screen.
155
+ setupLoadingScreen(viewerDiv, itownsViewer);
156
+
157
+ // Make atmosphere realistic.
158
+ itownsViewer.getLayerById('atmosphere').setRealisticOn(true);
159
+
160
+ // Controls and camera specific setting.
161
+ itownsViewer.controls.minDistanceCollision = 0.01;
162
+ itownsViewer.controls.minDistance = 20;
163
+ itownsViewer.camera.camera3D.near = 0.1;
164
+
165
+
166
+
167
+ // ---------- TWEAK ITOWNS VIEWER TO SUPPORT POTREE VISUALIZATION : ----------
168
+
169
+ itownsViewer.render = () => {};
170
+
171
+ // Force iTowns viewer to resize when changing #potree_render_area div size.
172
+ // This allows the viewer resizing when toggling potree menu.
173
+ new ResizeObserver(() => itownsViewer.resize()).observe(viewerDiv);
174
+
175
+ // Disable iTowns controls when hovering Potree tool (such as a vertex of a displayed polygon).
176
+ // This prevents iTowns camera from moving when we want to displace a Potree tool marker.
177
+ viewerDiv.addEventListener('mousemove', () => {
178
+ itownsViewer.controls.states.enabled = potreeViewer.inputHandler.hoveredElements.length === 0;
179
+ })
180
+
181
+ // Set Potree viewer camera as iTowns viewer camera.
182
+ const camera = itownsViewer.camera.camera3D;
183
+ camera.zoomTo = () => {};
184
+ potreeViewer.scene.cameraP = camera;
185
+
186
+ // TODO : should be moved to Label2DRenderer constructor
187
+ itownsViewer.mainLoop.gfxEngine.label2dRenderer.domElement.style.pointerEvents = 'none';
188
+
189
+
190
+
191
+ // ---------- DISPLAY CONTEXTUAL DATA USING ITOWNS : ----------
192
+
193
+ // Add one imagery layer to the scene. This layer's properties are defined in a json file, but it could be
194
+ // defined as a plain js object. See `Layer` documentation for more info.
195
+ itowns.Fetcher.json('./layers/JSONLayers/Ortho.json').then(function _(config) {
196
+ config.source = new itowns.WMTSSource(config.source);
197
+ config.source.zoom = { max: 19, min: 3 };
198
+ itownsViewer.addLayer(
199
+ new itowns.ColorLayer(config.id, config),
200
+ );
201
+ });
202
+
203
+ // Add two elevaion layers, each with a different level of detail. Here again, each layer's properties are
204
+ // defined in a json file.
205
+ function addElevationLayerFromConfig(config) {
206
+ config.source = new itowns.WMTSSource(config.source);
207
+ itownsViewer.addLayer(
208
+ new itowns.ElevationLayer(config.id, config),
209
+ );
210
+ }
211
+ itowns.Fetcher.json('layers/JSONLayers/WORLD_DTM.json').then(addElevationLayerFromConfig);
212
+ itowns.Fetcher.json('layers/JSONLayers/IGN_MNT_HIGHRES.json').then(addElevationLayerFromConfig);
213
+
214
+
215
+
216
+ // ---------- DISPLAY POINT CLOUD DATA USING POTREE : ----------
217
+
218
+ const pointcloudUrl = `${location.protocol}//lidarhd.pocgpf.ovh/data/`;
219
+
220
+ itowns.Fetcher.json(
221
+ pointcloudUrl + 'metadata/pivotTHREE.json'
222
+ ).then(
223
+ (pivot) => new THREE.ObjectLoader().parse(pivot)
224
+ ).then(
225
+ (pivotTHREE) => {
226
+ Potree.loadPointCloud(pointcloudUrl + 'ept/ept.json', 'pointcloud', function(e) {
227
+ const pointcloud = e.pointcloud;
228
+ const material = pointcloud.material;
229
+
230
+ potreeViewer.scene.addPointCloud(pointcloud);
231
+
232
+ pointcloud.getAttribute('intensity').range = [0, 10000];
233
+
234
+ material.pointSizeType = Potree.PointSizeType.ADAPTIVE;
235
+ material.shape = Potree.PointShape.CIRCLE
236
+
237
+ pointcloud.position.copy(pivotTHREE.position);
238
+ pointcloud.quaternion.copy(pivotTHREE.quaternion);
239
+ pointcloud.updateMatrixWorld(true);
240
+
241
+ // Move itowns viewer camera to the center of the point cloud
242
+ itownsViewer.controls.lookAtCoordinate({
243
+ coord: new itowns.Coordinates('EPSG:4978').setFromVector3(pivotTHREE.position),
244
+ range: 1500
245
+ }, false);
246
+ });
247
+ }
248
+ );
249
+
250
+ </script>
251
+ </body>
252
+ </html>
@@ -44,8 +44,10 @@ function GuiTools(domId, view, w) {
44
44
  document.body.appendChild(element);
45
45
  this.colorGui = this.gui.addFolder('Color Layers');
46
46
  this.elevationGui = this.gui.addFolder('Elevation Layers');
47
+ this.geoidGui = this.gui.addFolder('Geoid Layers');
47
48
  this.elevationGui.hide();
48
49
  this.colorGui.hide();
50
+ this.geoidGui.hide();
49
51
  this.view = view;
50
52
  view.addEventListener('layers-order-changed', (function refreshColorGui() {
51
53
  var i;
@@ -64,6 +66,8 @@ GuiTools.prototype.addLayerGUI = function fnAddLayerGUI(layer) {
64
66
  this.addImageryLayerGUI(layer);
65
67
  } else if (layer.isElevationLayer) {
66
68
  this.addElevationLayerGUI(layer);
69
+ } else if (layer.isGeoidLayer) {
70
+ this.addGeoidLayerGUI(layer);
67
71
  }
68
72
  };
69
73
 
@@ -107,6 +111,19 @@ GuiTools.prototype.addElevationLayerGUI = function addElevationLayerGUI(layer) {
107
111
  }).bind(this));
108
112
  };
109
113
 
114
+ GuiTools.prototype.addGeoidLayerGUI = function addGeoidLayerGUI(layer) {
115
+ if (this.geoidGui.hasFolder(layer.id)) { return; }
116
+ this.geoidGui.show();
117
+ var folder = this.geoidGui.addFolder(layer.id);
118
+ folder.add({ frozen: layer.frozen }, 'frozen').onChange(function refreshFrozenGui(value) {
119
+ layer.frozen = value;
120
+ });
121
+ folder.add({ visible: layer.visible }, 'visible').onChange((function updateVisibility(value) {
122
+ layer.visible = value;
123
+ this.view.notifyChange(layer);
124
+ }).bind(this));
125
+ };
126
+
110
127
  GuiTools.prototype.addImageryLayersGUI = function addImageryLayersGUI(layers) {
111
128
  var i;
112
129
  var seq = itowns.ImageryLayers.getColorLayersIdOrderedBySequence(layers);
@@ -13,6 +13,7 @@ function roundPixelsFromMeters(view, pixelSize) {
13
13
 
14
14
  // Round the metric distance :
15
15
  distanceMeters = Math.floor(distanceMeters);
16
+ // eslint-disable-next-line prefer-exponentiation-operator
16
17
  var digit = Math.pow(10, distanceMeters.toString().length - 1);
17
18
  distanceMeters = Math.round(distanceMeters / digit) * digit;
18
19
 
@@ -0,0 +1,90 @@
1
+ <html>
2
+ <head>
3
+ <title>Itowns - FileSource - Handle fetching step</title>
4
+ <meta charset="UTF-8">
5
+ <link rel="stylesheet" type="text/css" href="css/example.css">
6
+ <link rel="stylesheet" type="text/css" href="css/LoadingScreen.css">
7
+
8
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
9
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/dat-gui/0.7.6/dat.gui.min.js"></script>
10
+ </head>
11
+ <body>
12
+ <div id="viewerDiv" class="viewer"></div>
13
+ <script src="js/GUI/GuiTools.js"></script>
14
+ <script src="../dist/itowns.js"></script>
15
+ <script src="../dist/debug.js"></script>
16
+ <script src="js/GUI/LoadingScreen.js"></script>
17
+ <script src="js/plugins/FeatureToolTip.js"></script>
18
+ <script type="text/javascript">
19
+ /* global itowns, setupLoadingScreen, GuiTools, ToolTip */
20
+
21
+
22
+
23
+ // ---------- CREATE A GlobeView : ----------
24
+
25
+ // Define camera initial position
26
+ const placement = {
27
+ coord: new itowns.Coordinates('EPSG:4326', 3.05, 48.95),
28
+ range: 70000,
29
+ };
30
+
31
+ // `viewerDiv` will contain iTowns' rendering area (`<canvas>`)
32
+ const viewerDiv = document.getElementById('viewerDiv');
33
+
34
+ // Instantiate iTowns GlobeView
35
+ const view = new itowns.GlobeView(viewerDiv, placement);
36
+
37
+ // Setup loading screen and debug menu
38
+ setupLoadingScreen(viewerDiv, view);
39
+ const debugMenu = new GuiTools('menuDiv', view);
40
+
41
+
42
+
43
+ // ---------- DISPLAY CONTEXTUAL DATA : ----------
44
+
45
+ // Add one imagery layer to the scene
46
+ // This layer is defined in a json file but it could be defined as a plain js
47
+ // object. See Layer* for more info.
48
+ itowns.Fetcher.json('./layers/JSONLayers/Ortho.json').then(function _(config) {
49
+ config.source = new itowns.WMTSSource(config.source);
50
+ var layer = new itowns.ColorLayer('Ortho', config);
51
+ view.addLayer(layer).then(debugMenu.addLayerGUI.bind(debugMenu));
52
+ });
53
+
54
+
55
+
56
+ // ---------- DEFINE DATA SOURCE FROM FETCHED DATA : ----------
57
+
58
+ // Handle fetching step.
59
+ // Should you implement a custom fetcher, it would need to be called here.
60
+ itowns.Fetcher.json(
61
+ 'https://raw.githubusercontent.com/iTowns/iTowns2-sample-data/master/lyon-roads.geojson',
62
+ ).then((fetched) => {
63
+ // Then, create a FileSource, passing it the data just fetched. We also need to specify the `format` or the
64
+ // `parser` parameter so that iTowns knows which parser it can use.
65
+ const sourceFromFetchedData = new itowns.FileSource({
66
+ fetchedData: fetched,
67
+ crs: 'EPSG:4326',
68
+ format: 'application/json',
69
+ });
70
+
71
+ view.addLayer(new itowns.ColorLayer('Roads', {
72
+ source: sourceFromFetchedData,
73
+ style: new itowns.Style({
74
+ stroke: { color: 'yellow' },
75
+ }),
76
+ })).then(debugMenu.addLayerGUI.bind(debugMenu));
77
+ });
78
+
79
+
80
+
81
+ view.addEventListener(itowns.GLOBE_VIEW_EVENTS.GLOBE_INITIALIZED, function () {
82
+ // Organize the order with which layers are superposing.
83
+ itowns.ColorLayersOrdering.moveLayerToIndex(view, 'Ortho', 0);
84
+ // Move the camera to visualize all data.
85
+ view.controls.lookAtCoordinate(view.getLayerById('Roads').source.extent, false);
86
+ });
87
+
88
+ </script>
89
+ </body>
90
+ </html>
@@ -0,0 +1,85 @@
1
+ <html>
2
+ <head>
3
+ <title>Itowns - Source - format</title>
4
+ <meta charset="UTF-8">
5
+ <link rel="stylesheet" type="text/css" href="css/example.css">
6
+ <link rel="stylesheet" type="text/css" href="css/LoadingScreen.css">
7
+
8
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
9
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/dat-gui/0.7.6/dat.gui.min.js"></script>
10
+ </head>
11
+ <body>
12
+ <div id="viewerDiv" class="viewer"></div>
13
+ <script src="js/GUI/GuiTools.js"></script>
14
+ <script src="../dist/itowns.js"></script>
15
+ <script src="../dist/debug.js"></script>
16
+ <script src="js/GUI/LoadingScreen.js"></script>
17
+ <script src="js/plugins/FeatureToolTip.js"></script>
18
+ <script type="text/javascript">
19
+ /* global itowns, setupLoadingScreen, GuiTools, ToolTip */
20
+
21
+
22
+
23
+ // ---------- CREATE A GlobeView : ----------
24
+
25
+ // Define camera initial position
26
+ const placement = {
27
+ coord: new itowns.Coordinates('EPSG:4326', 3.05, 48.95),
28
+ range: 70000,
29
+ };
30
+
31
+ // `viewerDiv` will contain iTowns' rendering area (`<canvas>`)
32
+ const viewerDiv = document.getElementById('viewerDiv');
33
+
34
+ // Instantiate iTowns GlobeView
35
+ const view = new itowns.GlobeView(viewerDiv, placement);
36
+
37
+ // Setup loading screen and debug menu
38
+ setupLoadingScreen(viewerDiv, view);
39
+ const debugMenu = new GuiTools('menuDiv', view);
40
+
41
+
42
+
43
+ // ---------- DISPLAY CONTEXTUAL DATA : ----------
44
+
45
+ // Add one imagery layer to the scene
46
+ // This layer is defined in a json file but it could be defined as a plain js
47
+ // object. See Layer* for more info.
48
+ itowns.Fetcher.json('./layers/JSONLayers/Ortho.json').then(function _(config) {
49
+ config.source = new itowns.WMTSSource(config.source);
50
+ var layer = new itowns.ColorLayer('Ortho', config);
51
+ view.addLayer(layer).then(debugMenu.addLayerGUI.bind(debugMenu));
52
+ });
53
+
54
+
55
+
56
+ // ---------- DEFINE DATA SOURCE SPECIFYING ITS FORMAT : ----------
57
+
58
+ const sourceFromFormat = new itowns.FileSource({
59
+ url: 'https://raw.githubusercontent.com/iTowns/iTowns2-sample-data/master/lyon-ZU.geojson',
60
+ crs: 'EPSG:4326',
61
+ format: 'application/json',
62
+ });
63
+
64
+ view.addLayer(new itowns.ColorLayer('Urban Area', {
65
+ source: sourceFromFormat,
66
+ style: new itowns.Style({
67
+ fill: { color: 'red', opacity: 0.5 },
68
+ stroke: { color: 'red' },
69
+ }),
70
+ })).then(debugMenu.addLayerGUI.bind(debugMenu));
71
+
72
+
73
+
74
+ // ---------- REORDER ColorLayers AND MOVE CAMERA : ----------
75
+
76
+ view.addEventListener(itowns.GLOBE_VIEW_EVENTS.GLOBE_INITIALIZED, function () {
77
+ // Organize the order with which layers are superposing.
78
+ itowns.ColorLayersOrdering.moveLayerToIndex(view, 'Ortho', 0);
79
+ // Move the camera to visualize all data.
80
+ view.controls.lookAtCoordinate(sourceFromFormat.extent, false);
81
+ });
82
+
83
+ </script>
84
+ </body>
85
+ </html>
@@ -0,0 +1,87 @@
1
+ <html>
2
+ <head>
3
+ <title>Itowns - Source - fetcher and parser</title>
4
+ <meta charset="UTF-8">
5
+ <link rel="stylesheet" type="text/css" href="css/example.css">
6
+ <link rel="stylesheet" type="text/css" href="css/LoadingScreen.css">
7
+
8
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
9
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/dat-gui/0.7.6/dat.gui.min.js"></script>
10
+ </head>
11
+ <body>
12
+ <div id="viewerDiv" class="viewer"></div>
13
+ <script src="js/GUI/GuiTools.js"></script>
14
+ <script src="../dist/itowns.js"></script>
15
+ <script src="../dist/debug.js"></script>
16
+ <script src="js/GUI/LoadingScreen.js"></script>
17
+ <script src="js/plugins/FeatureToolTip.js"></script>
18
+ <script type="text/javascript">
19
+ /* global itowns, setupLoadingScreen, GuiTools, ToolTip */
20
+
21
+
22
+
23
+ // ---------- CREATE A GlobeView : ----------
24
+
25
+ // Define camera initial position
26
+ const placement = {
27
+ coord: new itowns.Coordinates('EPSG:4326', 3.05, 48.95),
28
+ range: 70000,
29
+ };
30
+
31
+ // `viewerDiv` will contain iTowns' rendering area (`<canvas>`)
32
+ const viewerDiv = document.getElementById('viewerDiv');
33
+
34
+ // Instantiate iTowns GlobeView
35
+ const view = new itowns.GlobeView(viewerDiv, placement);
36
+
37
+ // Setup loading screen and debug menu
38
+ setupLoadingScreen(viewerDiv, view);
39
+ const debugMenu = new GuiTools('menuDiv', view);
40
+
41
+
42
+
43
+ // ---------- DISPLAY CONTEXTUAL DATA : ----------
44
+
45
+ // Add one imagery layer to the scene
46
+ // This layer is defined in a json file but it could be defined as a plain js
47
+ // object. See Layer* for more info.
48
+ itowns.Fetcher.json('./layers/JSONLayers/Ortho.json').then(function _(config) {
49
+ config.source = new itowns.WMTSSource(config.source);
50
+ var layer = new itowns.ColorLayer('Ortho', config);
51
+ view.addLayer(layer).then(debugMenu.addLayerGUI.bind(debugMenu));
52
+ });
53
+
54
+
55
+
56
+ // ---------- DEFINE DATA SOURCE SPECIFYING FETCHER AND PARSER METHODS : ----------
57
+
58
+ const sourceFromFetcherAndParser = new itowns.FileSource({
59
+ url: 'https://raw.githubusercontent.com/iTowns/iTowns2-sample-data/master/lyon-hydro.geojson',
60
+ crs: 'EPSG:4326',
61
+ // Specify fetcher and parser methods. Should you implement some custom ones, they would need to be called here.
62
+ fetcher: itowns.Fetcher.json,
63
+ parser: itowns.GeoJsonParser.parse,
64
+ })
65
+
66
+ view.addLayer(new itowns.ColorLayer('Hydro', {
67
+ source: sourceFromFetcherAndParser,
68
+ style: new itowns.Style({
69
+ fill: { color: 'cyan', opacity: 0.5 },
70
+ stroke: { color: 'blue',},
71
+ }),
72
+ })).then(debugMenu.addLayerGUI.bind(debugMenu));
73
+
74
+
75
+
76
+ // ---------- REORDER ColorLayers AND MOVE CAMERA : ----------
77
+
78
+ view.addEventListener(itowns.GLOBE_VIEW_EVENTS.GLOBE_INITIALIZED, function () {
79
+ // Organize the order with which layers are superposing.
80
+ itowns.ColorLayersOrdering.moveLayerToIndex(view, 'Ortho', 0);
81
+ // Move the camera to visualize all data.
82
+ view.controls.lookAtCoordinate(sourceFromFetcherAndParser.extent, false);
83
+ });
84
+
85
+ </script>
86
+ </body>
87
+ </html>
@@ -0,0 +1,104 @@
1
+ <html>
2
+ <head>
3
+ <title>Itowns - FileSource - Handle parsing step</title>
4
+ <meta charset="UTF-8">
5
+ <link rel="stylesheet" type="text/css" href="css/example.css">
6
+ <link rel="stylesheet" type="text/css" href="css/LoadingScreen.css">
7
+
8
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
9
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/dat-gui/0.7.6/dat.gui.min.js"></script>
10
+ </head>
11
+ <body>
12
+ <div id="viewerDiv" class="viewer"></div>
13
+ <script src="js/GUI/GuiTools.js"></script>
14
+ <script src="../dist/itowns.js"></script>
15
+ <script src="../dist/debug.js"></script>
16
+ <script src="js/GUI/LoadingScreen.js"></script>
17
+ <script src="js/plugins/FeatureToolTip.js"></script>
18
+ <script type="text/javascript">
19
+ /* global itowns, setupLoadingScreen, GuiTools, ToolTip */
20
+
21
+
22
+
23
+ // ---------- CREATE A GlobeView : ----------
24
+
25
+ // Define camera initial position
26
+ const placement = {
27
+ coord: new itowns.Coordinates('EPSG:4326', 3.05, 48.95),
28
+ range: 70000,
29
+ };
30
+
31
+ // `viewerDiv` will contain iTowns' rendering area (`<canvas>`)
32
+ const viewerDiv = document.getElementById('viewerDiv');
33
+
34
+ // Instantiate iTowns GlobeView
35
+ const view = new itowns.GlobeView(viewerDiv, placement);
36
+
37
+ // Setup loading screen and debug menu
38
+ setupLoadingScreen(viewerDiv, view);
39
+ const debugMenu = new GuiTools('menuDiv', view);
40
+
41
+
42
+
43
+ // ---------- DISPLAY CONTEXTUAL DATA : ----------
44
+
45
+ // Add one imagery layer to the scene
46
+ // This layer is defined in a json file but it could be defined as a plain js
47
+ // object. See Layer* for more info.
48
+ itowns.Fetcher.json('./layers/JSONLayers/Ortho.json').then(function _(config) {
49
+ config.source = new itowns.WMTSSource(config.source);
50
+ var layer = new itowns.ColorLayer('Ortho', config);
51
+ view.addLayer(layer).then(debugMenu.addLayerGUI.bind(debugMenu));
52
+ });
53
+
54
+
55
+
56
+ // ---------- DEFINE DATA SOURCE FROM PARSED DATA : ----------
57
+
58
+ // Handle fetching step.
59
+ // Should you implement a custom fetcher, it would need to be called here.
60
+ itowns.Fetcher.json(
61
+ 'https://raw.githubusercontent.com/iTowns/iTowns2-sample-data/master/lyon-trains.geojson',
62
+ ).then((fetched) => {
63
+ // Handle parsing step.
64
+ // We parse the fetched data into a FeatureCollection.
65
+ // See http://www.itowns-project.org/itowns/docs/#api/Base/FeatureCollection.
66
+ // Should you implement a custom parser, it would need to be called here.
67
+ return itowns.GeoJsonParser.parse(fetched, {
68
+ // Information on the fetched data.
69
+ // See http://www.itowns-project.org/itowns/docs/#api/Source/ParsingOptions.
70
+ in: {
71
+ crs: 'EPSG:4326',
72
+ },
73
+ // Information on the FeatureCollection that should be created from the fetched data. Here, we pass a
74
+ // FeatureBuildingOptions (http://www.itowns-project.org/itowns/docs/#api/Base/FeatureBuildingOptions).
75
+ out: {
76
+ crs: view.tileLayer.extent.crs,
77
+ },
78
+ });
79
+ }).then((parsed) => {
80
+ // Finally, define a FileSource from the parsed data
81
+ const sourceFromParsedData = new itowns.FileSource({ features: parsed });
82
+
83
+ view.addLayer(new itowns.ColorLayer('Trains', {
84
+ source: sourceFromParsedData,
85
+ style: new itowns.Style({
86
+ stroke: { color: 'black', width: 2 },
87
+ }),
88
+ })).then(debugMenu.addLayerGUI.bind(debugMenu));
89
+ });
90
+
91
+
92
+
93
+ // ---------- REORDER ColorLayers AND MOVE CAMERA : ----------
94
+
95
+ view.addEventListener(itowns.GLOBE_VIEW_EVENTS.GLOBE_INITIALIZED, function () {
96
+ // Organize the order with which layers are superposing.
97
+ itowns.ColorLayersOrdering.moveLayerToIndex(view, 'Ortho', 0);
98
+ // Move the camera to visualize all data.
99
+ view.controls.lookAtCoordinate(view.getLayerById('Trains').source.extent, false);
100
+ });
101
+
102
+ </script>
103
+ </body>
104
+ </html>