itowns 2.37.0 → 2.38.2

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 (77) hide show
  1. package/README.md +12 -1
  2. package/changelog.md +101 -0
  3. package/dist/debug.js +1 -1
  4. package/dist/debug.js.LICENSE.txt +2 -2
  5. package/dist/debug.js.map +1 -1
  6. package/dist/itowns.js +1 -1
  7. package/dist/itowns.js.LICENSE.txt +2 -2
  8. package/dist/itowns.js.map +1 -1
  9. package/dist/itowns_widgets.js +1 -1
  10. package/dist/itowns_widgets.js.map +1 -1
  11. package/examples/config.json +4 -1
  12. package/examples/css/example.css +21 -1
  13. package/examples/css/widgets.css +118 -6
  14. package/examples/images/code-logo.svg +43 -0
  15. package/examples/index.html +5 -5
  16. package/examples/mars.html +0 -1
  17. package/examples/misc_orthographic_camera.html +7 -19
  18. package/examples/vector_tile_3d_mesh.html +155 -0
  19. package/examples/vector_tile_raster_3d.html +0 -5
  20. package/examples/view_25d_map.html +6 -19
  21. package/examples/view_2d_map.html +6 -19
  22. package/examples/view_3d_map.html +106 -81
  23. package/examples/widgets_minimap.html +3 -1
  24. package/examples/widgets_navigation.html +6 -1
  25. package/examples/widgets_scale.html +96 -0
  26. package/examples/widgets_searchbar.html +124 -0
  27. package/lib/Controls/PlanarControls.js +10 -42
  28. package/lib/Converter/Feature2Mesh.js +225 -61
  29. package/lib/Converter/Feature2Texture.js +4 -3
  30. package/lib/Converter/convertToTile.js +10 -5
  31. package/lib/Core/Feature.js +57 -30
  32. package/lib/Core/MainLoop.js +136 -62
  33. package/lib/Core/TileMesh.js +21 -5
  34. package/lib/Core/View.js +46 -15
  35. package/lib/Layer/FeatureGeometryLayer.js +37 -10
  36. package/lib/Layer/GeoidLayer.js +17 -6
  37. package/lib/Layer/GeometryLayer.js +6 -54
  38. package/lib/Layer/OrientedImageLayer.js +1 -0
  39. package/lib/Layer/RasterLayer.js +3 -1
  40. package/lib/Layer/ReferencingLayerProperties.js +50 -0
  41. package/lib/Main.js +1 -1
  42. package/lib/Parser/B3dmParser.js +3 -2
  43. package/lib/Parser/GeoJsonParser.js +29 -7
  44. package/lib/Parser/VectorTileParser.js +5 -4
  45. package/lib/Parser/deprecated/LegacyGLTFLoader.js +3 -3
  46. package/lib/Process/3dTilesProcessing.js +3 -3
  47. package/lib/Process/FeatureProcessing.js +36 -86
  48. package/lib/Process/LayeredMaterialNodeProcessing.js +9 -3
  49. package/lib/Process/ObjectRemovalHelper.js +4 -0
  50. package/lib/Provider/3dTilesProvider.js +2 -7
  51. package/lib/Provider/Fetcher.js +5 -2
  52. package/lib/Provider/TileProvider.js +18 -2
  53. package/lib/Renderer/Camera.js +33 -12
  54. package/lib/Renderer/ColorLayersOrdering.js +3 -1
  55. package/lib/Renderer/LayeredMaterial.js +32 -7
  56. package/lib/Renderer/OBB.js +8 -4
  57. package/lib/Renderer/OrientedImageMaterial.js +8 -5
  58. package/lib/Renderer/PointsMaterial.js +1 -0
  59. package/lib/Renderer/RenderMode.js +3 -1
  60. package/lib/Renderer/Shader/ShaderChunk.js +5 -1
  61. package/lib/Renderer/c3DEngine.js +9 -6
  62. package/lib/Source/FileSource.js +8 -1
  63. package/lib/Source/VectorTilesSource.js +5 -0
  64. package/lib/Source/WFSSource.js +9 -3
  65. package/lib/ThreeExtended/{WebGL.js → capabilities/WebGL.js} +8 -7
  66. package/lib/ThreeExtended/loaders/GLTFLoader.js +3 -4
  67. package/lib/Utils/DEMUtils.js +3 -1
  68. package/lib/Utils/gui/Main.js +39 -0
  69. package/lib/Utils/gui/Minimap.js +195 -0
  70. package/lib/Utils/gui/Navigation.js +322 -0
  71. package/lib/Utils/gui/Scale.js +154 -0
  72. package/lib/Utils/gui/Searchbar.js +299 -0
  73. package/lib/Utils/gui/Widget.js +119 -0
  74. package/package.json +27 -22
  75. package/examples/images/compass.svg +0 -60
  76. package/examples/images/widget-logo.svg +0 -66
  77. package/examples/js/Scale.js +0 -41
@@ -0,0 +1,322 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports["default"] = void 0;
9
+
10
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
11
+
12
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
13
+
14
+ var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
15
+
16
+ var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
17
+
18
+ var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
19
+
20
+ var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
21
+
22
+ var _classPrivateFieldSet2 = _interopRequireDefault(require("@babel/runtime/helpers/classPrivateFieldSet"));
23
+
24
+ var _classPrivateFieldGet2 = _interopRequireDefault(require("@babel/runtime/helpers/classPrivateFieldGet"));
25
+
26
+ var _View = require("../../Core/View");
27
+
28
+ var _Widget2 = _interopRequireDefault(require("./Widget"));
29
+
30
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function () { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }
31
+
32
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
33
+
34
+ function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }
35
+
36
+ function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
37
+
38
+ function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
39
+
40
+ function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; }
41
+
42
+ var DEFAULT_OPTIONS = {
43
+ displayCompass: true,
44
+ display3DToggle: true,
45
+ displayZoomIn: true,
46
+ displayZoomOut: true,
47
+ animationDuration: 500,
48
+ position: 'bottom-left',
49
+ direction: 'column'
50
+ };
51
+ var DEFAULT_BUTTONS = {
52
+ compass: {
53
+ id: 'compass',
54
+ content: '',
55
+ info: 'Rotate the camera to face North',
56
+ parentId: 'widgets'
57
+ },
58
+ toggle3D: {
59
+ id: '3d-button',
60
+ content: '3D',
61
+ info: 'Tilt the camera'
62
+ },
63
+ zoomIn: {
64
+ id: 'zoom-in-button',
65
+ content: '<span class="widget-zoom-button-logo"></span>',
66
+ info: 'Zoom in',
67
+ parentId: 'zoom-button-bar'
68
+ },
69
+ zoomOut: {
70
+ id: 'zoom-out-button',
71
+ content: '<span id="zoom-out-logo" class="widget-zoom-button-logo"></span>',
72
+ info: 'Zoom out',
73
+ parentId: 'zoom-button-bar'
74
+ }
75
+ };
76
+ /**
77
+ * A widget menu manager for navigation.
78
+ *
79
+ * To use it, you need to link the widgets' stylesheet to your html webpage. This stylesheet is included in
80
+ * [itowns bundles](https://github.com/iTowns/itowns/releases) if you downloaded them, or it can be found in
81
+ * `node_modules/itowns/examples/css` if you installed iTowns with npm. Otherwise, it can be found at
82
+ * [this link](https://raw.githubusercontent.com/iTowns/itowns/master/examples/css/widgets.css). See
83
+ * [this example](http://www.itowns-project.org/itowns/examples/#widgets_navigation) for more details.
84
+ *
85
+ * @extends Widget
86
+ *
87
+ * @property {HTMLElement} domElement An html div containing all navigation widgets.
88
+ * @property {HTMLElement} parentElement The parent HTML container of `this.domElement`.
89
+ * @property {HTMLButtonElement} compass The HTML button for the compass.
90
+ * @property {HTMLButtonElement} toggle3D The HTML button for the 3D/2D toggle button.
91
+ * @property {HTMLButtonElement} zoomIn The HTML button for the zoom-in button.
92
+ * @property {HTMLButtonElement} zoomOut The HTML button for the zoom-out button.
93
+ *
94
+ * @example
95
+ * // Create a Navigation widget in the bottom-right corner of an iTowns view domElement
96
+ * const navigation = new Navigation(view, { position: 'bottom-right' };
97
+ *
98
+ * // Change the tooltip for the compass :
99
+ * navigation.compass.title = 'new tooltip';
100
+ *
101
+ * // Change the method ran when clicking zoom-in button :
102
+ * function newMethod() {
103
+ * // do something
104
+ * }
105
+ * navigation.zoomIn.onclick = newMethod;
106
+ */
107
+
108
+ var _view = /*#__PURE__*/new WeakMap();
109
+
110
+ var _action = /*#__PURE__*/new WeakSet();
111
+
112
+ var _addDefaultButton = /*#__PURE__*/new WeakSet();
113
+
114
+ var Navigation = /*#__PURE__*/function (_Widget) {
115
+ (0, _inherits2["default"])(Navigation, _Widget);
116
+
117
+ var _super = _createSuper(Navigation);
118
+
119
+ /**
120
+ * @param {GlobeView} view The iTowns view the navigation should be linked
121
+ * to. For the moment, only `{@link GlobeView}`
122
+ * is supported.
123
+ * @param {Object} options The navigation menu optional configuration.
124
+ * @param {HTMLElement} [options.parentElement=view.domElement] The parent HTML container of the div which
125
+ * contains navigation widgets.
126
+ * @param {boolean} [options.displayCompass=true] Whether the compass widget should be displayed.
127
+ * @param {boolean} [options.display3DToggle=true] Whether the navigation should include a widget
128
+ * to toggle between top and oblique view.
129
+ * @param {boolean} [options.displayZoomIn=true] Whether the zoom-in widget should be displayed.
130
+ * @param {boolean} [options.displayZoomOut=true] Whether the zoom-out widget should be displayed.
131
+ * @param {number} [options.animationDuration=500] The duration of travel animations, when clicking
132
+ * navigation widgets.
133
+ * @param {string} [options.position='bottom-left'] Defines which corner of the `parentElement` the
134
+ * navigation menu should be displayed to.
135
+ * Possible values are `top-left`, `top-right`,
136
+ * `bottom-left` and `bottom-right`. If the input
137
+ * value does not match one of these, it will be
138
+ * defaulted to `bottom-left`.
139
+ * @param {string} [options.direction='column'] Whether the navigation menu should expand
140
+ * horizontally or vertically. Possible values
141
+ * are `column` and `row`. If the input value
142
+ * does not match one of these, it will be
143
+ * defaulted to `column`.
144
+ * @param {Object} [options.translate] An optional translation of the navigation menu.
145
+ * @param {number} [options.translate.x=0] The navigation menu translation along the page
146
+ * x-axis.
147
+ * @param {number} [options.translate.y=0] The navigation menu translation along the page
148
+ * y-axis.
149
+ */
150
+ function Navigation(view) {
151
+ var _options$displayCompa, _options$display3DTog, _options$displayZoomI, _options$displayZoomO;
152
+
153
+ var _this;
154
+
155
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
156
+ (0, _classCallCheck2["default"])(this, Navigation);
157
+
158
+ // ---------- BUILD PROPERTIES ACCORDING TO DEFAULT OPTIONS AND OPTIONS PASSED IN PARAMETERS : ----------
159
+ // Check if the view is supported.
160
+ if (!view.isGlobeView) {
161
+ throw new Error('\'Navigation\' plugin only supports \'GlobeView\'. Therefore, the \'view\' parameter must be a ' + '\'GlobeView\'.');
162
+ } // `top`, `bottom`, `left` and `right` values for `position` option are not relevant for navigation widget.
163
+
164
+
165
+ if (['top', 'bottom', 'left', 'right'].includes(options.position)) {
166
+ console.warn('\'position\' optional parameter for \'Navigation\' is not a valid option. ' + "It will be set to '".concat(DEFAULT_OPTIONS.position, "'."));
167
+ options.position = DEFAULT_OPTIONS.position;
168
+ }
169
+
170
+ _this = _super.call(this, view, options, DEFAULT_OPTIONS);
171
+
172
+ _classPrivateMethodInitSpec((0, _assertThisInitialized2["default"])(_this), _addDefaultButton);
173
+
174
+ _classPrivateMethodInitSpec((0, _assertThisInitialized2["default"])(_this), _action);
175
+
176
+ _classPrivateFieldInitSpec((0, _assertThisInitialized2["default"])(_this), _view, {
177
+ writable: true,
178
+ value: void 0
179
+ });
180
+
181
+ (0, _classPrivateFieldSet2["default"])((0, _assertThisInitialized2["default"])(_this), _view, view);
182
+ _this.direction = options.direction || DEFAULT_OPTIONS.direction;
183
+
184
+ if (!['column', 'row'].includes(_this.direction)) {
185
+ console.warn('\'direction\' optional parameter for \'Navigation\' constructor is not a valid option. ' + "It will be set to '".concat(DEFAULT_OPTIONS.direction, "'."));
186
+ _this.direction = DEFAULT_OPTIONS.direction;
187
+ }
188
+
189
+ _this.animationDuration = options.animationDuration === undefined ? DEFAULT_OPTIONS.animationDuration : options.animationDuration; // ---------- CREATE A DomElement WITH id AND classes RELEVANT TO THE WIDGET PROPERTIES : ----------
190
+ // Create a div containing all widgets and add it to its specified parent.
191
+
192
+ _this.domElement.id = 'widgets-navigation'; // Position widget div according to options.
193
+
194
+ _this.domElement.classList.add("".concat(_this.direction, "-widget")); // ---------- CREATE THE DEFAULT WIDGETS IF NOT HIDDEN (COMPASS, 3D AND ZOOM BUTTONS) : ----------
195
+ // Add a compass widget if requested.
196
+
197
+
198
+ if ((_options$displayCompa = options.displayCompass) !== null && _options$displayCompa !== void 0 ? _options$displayCompa : DEFAULT_OPTIONS.displayCompass) {
199
+ _this.compass = _classPrivateMethodGet((0, _assertThisInitialized2["default"])(_this), _addDefaultButton, _addDefaultButton2).call((0, _assertThisInitialized2["default"])(_this), DEFAULT_BUTTONS.compass, function () {
200
+ _classPrivateMethodGet((0, _assertThisInitialized2["default"])(_this), _action, _action2).call((0, _assertThisInitialized2["default"])(_this), {
201
+ heading: 0,
202
+ tilt: 89.5
203
+ });
204
+ }); // Manage compass rotation when the view's camera is moved.
205
+
206
+ view.addEventListener(_View.VIEW_EVENTS.CAMERA_MOVED, function (event) {
207
+ _this.compass.style.transform = "rotate(".concat(-event.heading, "deg)");
208
+ });
209
+ } // Add a 3D toggle button if requested.
210
+
211
+
212
+ if ((_options$display3DTog = options.display3DToggle) !== null && _options$display3DTog !== void 0 ? _options$display3DTog : DEFAULT_OPTIONS.display3DToggle) {
213
+ _this.toggle3D = _classPrivateMethodGet((0, _assertThisInitialized2["default"])(_this), _addDefaultButton, _addDefaultButton2).call((0, _assertThisInitialized2["default"])(_this), DEFAULT_BUTTONS.toggle3D, function () {
214
+ _classPrivateMethodGet((0, _assertThisInitialized2["default"])(_this), _action, _action2).call((0, _assertThisInitialized2["default"])(_this), {
215
+ tilt: (0, _classPrivateFieldGet2["default"])((0, _assertThisInitialized2["default"])(_this), _view).controls.getTilt() < 89 ? 89.5 : 40
216
+ });
217
+ }); // Manage button content toggle when the view's camera is moved.
218
+
219
+ view.addEventListener(_View.VIEW_EVENTS.CAMERA_MOVED, function (event) {
220
+ _this.toggle3D.innerHTML = event.tilt < 89 ? '2D' : '3D';
221
+ });
222
+ } // Add a zoom-in button if requested.
223
+
224
+
225
+ if ((_options$displayZoomI = options.displayZoomIn) !== null && _options$displayZoomI !== void 0 ? _options$displayZoomI : DEFAULT_OPTIONS.displayZoomIn) {
226
+ _this.zoomIn = _classPrivateMethodGet((0, _assertThisInitialized2["default"])(_this), _addDefaultButton, _addDefaultButton2).call((0, _assertThisInitialized2["default"])(_this), DEFAULT_BUTTONS.zoomIn, function () {
227
+ _classPrivateMethodGet((0, _assertThisInitialized2["default"])(_this), _action, _action2).call((0, _assertThisInitialized2["default"])(_this), {
228
+ zoom: Math.min(20, (0, _classPrivateFieldGet2["default"])((0, _assertThisInitialized2["default"])(_this), _view).controls.getZoom() + 1)
229
+ });
230
+ });
231
+ } // Add a zoom-out button if requested.
232
+
233
+
234
+ if ((_options$displayZoomO = options.displayZoomOut) !== null && _options$displayZoomO !== void 0 ? _options$displayZoomO : DEFAULT_OPTIONS.displayZoomOut) {
235
+ _this.zoomOut = _classPrivateMethodGet((0, _assertThisInitialized2["default"])(_this), _addDefaultButton, _addDefaultButton2).call((0, _assertThisInitialized2["default"])(_this), DEFAULT_BUTTONS.zoomOut, function () {
236
+ _classPrivateMethodGet((0, _assertThisInitialized2["default"])(_this), _action, _action2).call((0, _assertThisInitialized2["default"])(_this), {
237
+ zoom: Math.max(3, (0, _classPrivateFieldGet2["default"])((0, _assertThisInitialized2["default"])(_this), _view).controls.getZoom() - 1)
238
+ });
239
+ });
240
+ }
241
+
242
+ return _this;
243
+ }
244
+ /**
245
+ *
246
+ * @param {string} id The unique id the created button should be given.
247
+ * @param {string} [content=''] An HTML string defining the content of the button.
248
+ * @param {string} [title=''] An HTML string defining information on the button. This string will be
249
+ * displayed in a tooltip when hovering the button.
250
+ * @param {function} [onclick] The method that should be executed when the button is clicked on.
251
+ * @param {string} [parentId] The unique id of a button bar in which the created button should be added.
252
+ * A button bar is a group which contains one or several buttons. All
253
+ * buttons created with Navigation are in a button bar. If the given id does
254
+ * not match an already existing button bar, a new button bar will be created
255
+ * with this id. If no id is given, a button bar will be created with no id.
256
+ * The later case can be useful for creating isolated buttons.
257
+ *
258
+ * @returns {HTMLButtonElement} The created button.
259
+ */
260
+
261
+
262
+ (0, _createClass2["default"])(Navigation, [{
263
+ key: "addButton",
264
+ value: function addButton(id) {
265
+ var _this2 = this;
266
+
267
+ var content = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
268
+ var title = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
269
+ var onclick = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : function () {};
270
+ var parentId = arguments.length > 4 ? arguments[4] : undefined;
271
+ var buttonBar = document.getElementById(parentId);
272
+
273
+ if (!buttonBar) {
274
+ buttonBar = this.addButtonBar(parentId);
275
+ }
276
+
277
+ var button = document.createElement('button');
278
+ button.className = 'widget-button';
279
+ button.id = id;
280
+ button.innerHTML = content;
281
+ button.title = title;
282
+ button.onclick = onclick;
283
+ buttonBar.appendChild(button); // The buttons must not be focused using tab key.
284
+
285
+ button.tabIndex = -1; // When releasing the mouse after clicking the button, we give the focus back to the view. Therefore, we can use
286
+ // key events on the view without having to click the view to grant it focus.
287
+
288
+ window.addEventListener('pointerup', function () {
289
+ if (document.activeElement === button) {
290
+ (0, _classPrivateFieldGet2["default"])(_this2, _view).domElement.focus();
291
+ }
292
+ });
293
+ return button;
294
+ }
295
+ }, {
296
+ key: "addButtonBar",
297
+ value: function addButtonBar(id) {
298
+ var buttonBar = document.createElement('div');
299
+ buttonBar.className = 'widget-button-bar';
300
+
301
+ if (id) {
302
+ buttonBar.id = id;
303
+ }
304
+
305
+ this.domElement.appendChild(buttonBar);
306
+ return buttonBar;
307
+ }
308
+ }]);
309
+ return Navigation;
310
+ }(_Widget2["default"]);
311
+
312
+ function _action2(params) {
313
+ params.time = this.animationDuration;
314
+ return (0, _classPrivateFieldGet2["default"])(this, _view).controls.lookAtCoordinate(params);
315
+ }
316
+
317
+ function _addDefaultButton2(settings, onclick) {
318
+ return this.addButton(settings.id, settings.content, settings.info, onclick, settings.parentId);
319
+ }
320
+
321
+ var _default = Navigation;
322
+ exports["default"] = _default;
@@ -0,0 +1,154 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports["default"] = void 0;
9
+
10
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
11
+
12
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
13
+
14
+ var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
15
+
16
+ var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
17
+
18
+ var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
19
+
20
+ var _GlobeControls = require("../../Controls/GlobeControls");
21
+
22
+ var _GlobeView = require("../../Core/Prefab/GlobeView");
23
+
24
+ var _PlanarControls = require("../../Controls/PlanarControls");
25
+
26
+ var _View = require("../../Core/View");
27
+
28
+ var _Widget2 = _interopRequireDefault(require("./Widget"));
29
+
30
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function () { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }
31
+
32
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
33
+
34
+ var DEFAULT_OPTIONS = {
35
+ width: 200,
36
+ height: 30,
37
+ position: 'bottom-left'
38
+ };
39
+ /**
40
+ * A widget for scale
41
+ *
42
+ * To use it, you need to link the widgets' stylesheet to your html webpage. This stylesheet is included in
43
+ * [itowns bundles](https://github.com/iTowns/itowns/releases) if you downloaded them, or it can be found in
44
+ * `node_modules/itowns/examples/css` if you installed iTowns with npm. Otherwise, it can be found at
45
+ * [this link](https://raw.githubusercontent.com/iTowns/itowns/master/examples/css/widgets.css). See
46
+ * [this example](http://www.itowns-project.org/itowns/examples/#widgets_scale) for more details.
47
+ *
48
+ * @extends Widget
49
+ *
50
+ * @property {HTMLElement} domElement An html div containing the scale.
51
+ * @property {HTMLElement} parentElement The parent HTML container of `this.domElement`.
52
+ */
53
+
54
+ var Scale = /*#__PURE__*/function (_Widget) {
55
+ (0, _inherits2["default"])(Scale, _Widget);
56
+
57
+ var _super = _createSuper(Scale);
58
+
59
+ /**
60
+ * @param {View} view The iTowns view the scale should be
61
+ * linked to. If it is a
62
+ * {@link PlanarView} or a
63
+ * {@link GlobeView}, the scale will be
64
+ * automatically updated. Otherwise, user
65
+ * will need to implement the update
66
+ * automation using the `Scale.update`
67
+ * method.
68
+ * @param {Object} [options] The scale optional configuration.
69
+ * @param {HTMLElement} [options.parentElement=view.domElement] The parent HTML container of the div
70
+ * which contains scale widgets.
71
+ * @param {number} [options.width=200] The width in pixels of the scale.
72
+ * @param {number} [options.height=30] The height in pixels of the scale.
73
+ * @param {string} [options.position='bottom-left'] Defines which position within the
74
+ * `parentElement` the scale should be
75
+ * displayed to. Possible values are
76
+ * `top`, `bottom`, `left`, `right`,
77
+ * `top-left`, `top-right`, `bottom-left`
78
+ * and `bottom-right`. If the input value
79
+ * does not match one of these, it will
80
+ * be defaulted to `bottom-left`.
81
+ * @param {Object} [options.translate] An optional translation of the scale.
82
+ * @param {number} [options.translate.x=0] The scale translation along the page
83
+ * x-axis.
84
+ * @param {number} [options.translate.y=0] The scale translation along the page
85
+ * y-axis.
86
+ */
87
+ function Scale(view) {
88
+ var _this;
89
+
90
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
91
+ (0, _classCallCheck2["default"])(this, Scale);
92
+ // ---------- BUILD PROPERTIES ACCORDING TO DEFAULT OPTIONS AND OPTIONS PASSED IN PARAMETERS : ----------
93
+ _this = _super.call(this, view, options, DEFAULT_OPTIONS); // ---------- this.domElement SETTINGS SPECIFIC TO SCALE : ----------
94
+
95
+ _this.domElement.id = 'widgets-scale';
96
+ _this.view = view; // Initialize the text content of the scale, which will later be updated by a numerical value.
97
+
98
+ _this.domElement.innerHTML = 'Scale';
99
+ _this.width = options.width || DEFAULT_OPTIONS.width;
100
+
101
+ if (_this.view.isGlobeView) {
102
+ _this.view.addEventListener(_GlobeView.GLOBE_VIEW_EVENTS.GLOBE_INITIALIZED, function () {
103
+ _this.update();
104
+ });
105
+
106
+ _this.view.controls.addEventListener(_GlobeControls.CONTROL_EVENTS.RANGE_CHANGED, function () {
107
+ _this.update();
108
+ });
109
+ } else if (_this.view.isPlanarView) {
110
+ _this.view.addEventListener(_View.VIEW_EVENTS.INITIALIZED, function () {
111
+ _this.update();
112
+ });
113
+
114
+ _this.view.addEventListener(_PlanarControls.PLANAR_CONTROL_EVENT.MOVED, function () {
115
+ _this.update();
116
+ });
117
+ } else {
118
+ console.warn('The \'view\' linked to scale widget is neither a \'GlobeView\' nor a \'PlanarView\'. The ' + 'scale wont automatically update. You can implement its update automation using \'Scale.update\' ' + 'method.');
119
+ }
120
+
121
+ return _this;
122
+ }
123
+
124
+ (0, _createClass2["default"])(Scale, [{
125
+ key: "addEventListeners",
126
+ value: function addEventListeners() {}
127
+ /**
128
+ * Update the scale size and content according to view camera position.
129
+ */
130
+
131
+ }, {
132
+ key: "update",
133
+ value: function update() {
134
+ // Calculate the rounded metric distance which matches the scale width in pixels.
135
+ var metricDistance = Math.round(this.view.getPixelsToMeters(this.width));
136
+ var digit = Math.pow(10, metricDistance.toString().length - 1);
137
+ metricDistance = Math.round(metricDistance / digit) * digit;
138
+ var pixelDistance = this.view.getMetersToPixels(metricDistance);
139
+ var unit = 'm';
140
+
141
+ if (metricDistance >= 1000) {
142
+ metricDistance /= 1000;
143
+ unit = 'km';
144
+ }
145
+
146
+ this.domElement.innerHTML = "".concat(metricDistance, " ").concat(unit);
147
+ this.domElement.style.width = "".concat(pixelDistance, "px");
148
+ }
149
+ }]);
150
+ return Scale;
151
+ }(_Widget2["default"]);
152
+
153
+ var _default = Scale;
154
+ exports["default"] = _default;