itowns 2.44.3-next.9 → 2.45.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.
- package/README.md +3 -129
- package/examples/3dtiles_loader.html +20 -6
- package/examples/config.json +1 -0
- package/examples/copc_simple_loader.html +15 -5
- package/examples/effects_stereo.html +2 -2
- package/examples/entwine_3d_loader.html +3 -1
- package/examples/entwine_simple_loader.html +1 -1
- package/examples/images/itowns_logo.svg +123 -0
- package/examples/js/plugins/COGParser.js +1 -1
- package/examples/jsm/OGC3DTilesHelper.js +6 -1
- package/examples/layers/JSONLayers/GeoidMNT.json +3 -1
- package/examples/misc_collada.html +2 -2
- package/examples/source_file_geojson_3d.html +0 -1
- package/examples/source_file_kml_raster_usgs.html +0 -1
- package/examples/source_stream_wfs_raster.html +0 -7
- package/examples/vector_tile_mapbox_raster.html +91 -0
- package/examples/view_3d_map_webxr.html +3 -1
- package/examples/view_multi_25d.html +2 -2
- package/package.json +21 -75
- package/CODING.md +0 -120
- package/CONTRIBUTING.md +0 -150
- package/CONTRIBUTORS.md +0 -55
- package/LICENSE.md +0 -44
- package/changelog.md +0 -1361
- package/dist/455.js +0 -2
- package/dist/455.js.map +0 -1
- package/dist/debug.js +0 -3
- package/dist/debug.js.LICENSE.txt +0 -13
- package/dist/debug.js.map +0 -1
- package/dist/itowns.js +0 -3
- package/dist/itowns.js.LICENSE.txt +0 -7
- package/dist/itowns.js.map +0 -1
- package/dist/itowns_lasparser.js +0 -2
- package/dist/itowns_lasparser.js.map +0 -1
- package/dist/itowns_lasworker.js +0 -2
- package/dist/itowns_lasworker.js.map +0 -1
- package/dist/itowns_potree2worker.js +0 -2
- package/dist/itowns_potree2worker.js.map +0 -1
- package/dist/itowns_widgets.js +0 -2
- package/dist/itowns_widgets.js.map +0 -1
- package/examples/.eslintrc.cjs +0 -35
- package/examples/jsm/.eslintrc.cjs +0 -38
- package/lib/Controls/FirstPersonControls.js +0 -308
- package/lib/Controls/FlyControls.js +0 -175
- package/lib/Controls/GlobeControls.js +0 -1162
- package/lib/Controls/PlanarControls.js +0 -1025
- package/lib/Controls/StateControl.js +0 -429
- package/lib/Controls/StreetControls.js +0 -392
- package/lib/Converter/Feature2Mesh.js +0 -615
- package/lib/Converter/Feature2Texture.js +0 -170
- package/lib/Converter/convertToTile.js +0 -75
- package/lib/Converter/textureConverter.js +0 -44
- package/lib/Core/3DTiles/C3DTBatchTable.js +0 -131
- package/lib/Core/3DTiles/C3DTBatchTableHierarchyExtension.js +0 -96
- package/lib/Core/3DTiles/C3DTBoundingVolume.js +0 -157
- package/lib/Core/3DTiles/C3DTExtensions.js +0 -97
- package/lib/Core/3DTiles/C3DTFeature.js +0 -110
- package/lib/Core/3DTiles/C3DTilesEnums.js +0 -20
- package/lib/Core/3DTiles/C3DTileset.js +0 -99
- package/lib/Core/3DTiles/utils/BinaryPropertyAccessor.js +0 -100
- package/lib/Core/AnimationPlayer.js +0 -142
- package/lib/Core/CopcNode.js +0 -174
- package/lib/Core/Deprecated/Undeprecator.js +0 -75
- package/lib/Core/EntwinePointTileNode.js +0 -126
- package/lib/Core/Feature.js +0 -490
- package/lib/Core/Geographic/CoordStars.js +0 -80
- package/lib/Core/Geographic/Coordinates.js +0 -320
- package/lib/Core/Geographic/Crs.js +0 -175
- package/lib/Core/Geographic/Extent.js +0 -534
- package/lib/Core/Geographic/GeoidGrid.js +0 -109
- package/lib/Core/Label.js +0 -222
- package/lib/Core/MainLoop.js +0 -211
- package/lib/Core/Math/Ellipsoid.js +0 -144
- package/lib/Core/Picking.js +0 -255
- package/lib/Core/PointCloudNode.js +0 -42
- package/lib/Core/Potree2Node.js +0 -206
- package/lib/Core/Potree2PointAttributes.js +0 -139
- package/lib/Core/PotreeNode.js +0 -101
- package/lib/Core/Prefab/Globe/Atmosphere.js +0 -299
- package/lib/Core/Prefab/Globe/BuilderEllipsoidTile.js +0 -110
- package/lib/Core/Prefab/Globe/GlobeLayer.js +0 -145
- package/lib/Core/Prefab/Globe/SkyShader.js +0 -78
- package/lib/Core/Prefab/GlobeView.js +0 -161
- package/lib/Core/Prefab/Planar/PlanarLayer.js +0 -53
- package/lib/Core/Prefab/Planar/PlanarTileBuilder.js +0 -72
- package/lib/Core/Prefab/PlanarView.js +0 -62
- package/lib/Core/Prefab/TileBuilder.js +0 -80
- package/lib/Core/Prefab/computeBufferTileGeometry.js +0 -183
- package/lib/Core/Scheduler/Cache.js +0 -256
- package/lib/Core/Scheduler/CancelledCommandException.js +0 -15
- package/lib/Core/Scheduler/Scheduler.js +0 -294
- package/lib/Core/Style.js +0 -1121
- package/lib/Core/System/Capabilities.js +0 -63
- package/lib/Core/Tile/Tile.js +0 -219
- package/lib/Core/Tile/TileGrid.js +0 -46
- package/lib/Core/TileGeometry.js +0 -40
- package/lib/Core/TileMesh.js +0 -109
- package/lib/Core/View.js +0 -1109
- package/lib/Layer/C3DTilesLayer.js +0 -456
- package/lib/Layer/ColorLayer.js +0 -128
- package/lib/Layer/CopcLayer.js +0 -58
- package/lib/Layer/ElevationLayer.js +0 -107
- package/lib/Layer/EntwinePointTileLayer.js +0 -64
- package/lib/Layer/FeatureGeometryLayer.js +0 -63
- package/lib/Layer/GeoidLayer.js +0 -80
- package/lib/Layer/GeometryLayer.js +0 -202
- package/lib/Layer/InfoLayer.js +0 -64
- package/lib/Layer/LabelLayer.js +0 -456
- package/lib/Layer/Layer.js +0 -304
- package/lib/Layer/LayerUpdateState.js +0 -89
- package/lib/Layer/LayerUpdateStrategy.js +0 -80
- package/lib/Layer/OGC3DTilesLayer.js +0 -412
- package/lib/Layer/OrientedImageLayer.js +0 -222
- package/lib/Layer/PointCloudLayer.js +0 -359
- package/lib/Layer/Potree2Layer.js +0 -164
- package/lib/Layer/PotreeLayer.js +0 -65
- package/lib/Layer/RasterLayer.js +0 -27
- package/lib/Layer/ReferencingLayerProperties.js +0 -62
- package/lib/Layer/TiledGeometryLayer.js +0 -403
- package/lib/Loader/LASLoader.js +0 -193
- package/lib/Loader/Potree2BrotliLoader.js +0 -261
- package/lib/Loader/Potree2Loader.js +0 -207
- package/lib/Main.js +0 -115
- package/lib/MainBundle.js +0 -4
- package/lib/Parser/B3dmParser.js +0 -174
- package/lib/Parser/CameraCalibrationParser.js +0 -94
- package/lib/Parser/GDFParser.js +0 -72
- package/lib/Parser/GTXParser.js +0 -75
- package/lib/Parser/GeoJsonParser.js +0 -212
- package/lib/Parser/GpxParser.js +0 -25
- package/lib/Parser/ISGParser.js +0 -71
- package/lib/Parser/KMLParser.js +0 -25
- package/lib/Parser/LASParser.js +0 -137
- package/lib/Parser/MapBoxUrlParser.js +0 -83
- package/lib/Parser/PntsParser.js +0 -131
- package/lib/Parser/Potree2BinParser.js +0 -92
- package/lib/Parser/PotreeBinParser.js +0 -106
- package/lib/Parser/PotreeCinParser.js +0 -29
- package/lib/Parser/ShapefileParser.js +0 -78
- package/lib/Parser/VectorTileParser.js +0 -202
- package/lib/Parser/XbilParser.js +0 -119
- package/lib/Parser/deprecated/LegacyGLTFLoader.js +0 -1386
- package/lib/Parser/iGLTFLoader.js +0 -168
- package/lib/Process/3dTilesProcessing.js +0 -304
- package/lib/Process/FeatureProcessing.js +0 -76
- package/lib/Process/LayeredMaterialNodeProcessing.js +0 -221
- package/lib/Process/ObjectRemovalHelper.js +0 -97
- package/lib/Process/handlerNodeError.js +0 -23
- package/lib/Provider/3dTilesProvider.js +0 -149
- package/lib/Provider/DataSourceProvider.js +0 -8
- package/lib/Provider/Fetcher.js +0 -229
- package/lib/Provider/PointCloudProvider.js +0 -45
- package/lib/Provider/TileProvider.js +0 -16
- package/lib/Provider/URLBuilder.js +0 -116
- package/lib/Renderer/Camera.js +0 -281
- package/lib/Renderer/Color.js +0 -56
- package/lib/Renderer/ColorLayersOrdering.js +0 -115
- package/lib/Renderer/CommonMaterial.js +0 -31
- package/lib/Renderer/Label2DRenderer.js +0 -190
- package/lib/Renderer/LayeredMaterial.js +0 -243
- package/lib/Renderer/OBB.js +0 -153
- package/lib/Renderer/OrientedImageCamera.js +0 -118
- package/lib/Renderer/OrientedImageMaterial.js +0 -167
- package/lib/Renderer/PointsMaterial.js +0 -485
- package/lib/Renderer/RasterTile.js +0 -209
- package/lib/Renderer/RenderMode.js +0 -31
- package/lib/Renderer/Shader/ShaderChunk.js +0 -160
- package/lib/Renderer/Shader/ShaderUtils.js +0 -47
- package/lib/Renderer/SphereHelper.js +0 -23
- package/lib/Renderer/WebXR.js +0 -51
- package/lib/Renderer/c3DEngine.js +0 -214
- package/lib/Source/C3DTilesGoogleSource.js +0 -74
- package/lib/Source/C3DTilesIonSource.js +0 -54
- package/lib/Source/C3DTilesSource.js +0 -30
- package/lib/Source/CopcSource.js +0 -115
- package/lib/Source/EntwinePointTileSource.js +0 -62
- package/lib/Source/FileSource.js +0 -189
- package/lib/Source/OGC3DTilesGoogleSource.js +0 -29
- package/lib/Source/OGC3DTilesIonSource.js +0 -34
- package/lib/Source/OGC3DTilesSource.js +0 -21
- package/lib/Source/OrientedImageSource.js +0 -59
- package/lib/Source/Potree2Source.js +0 -167
- package/lib/Source/PotreeSource.js +0 -82
- package/lib/Source/Source.js +0 -223
- package/lib/Source/TMSSource.js +0 -145
- package/lib/Source/VectorTilesSource.js +0 -178
- package/lib/Source/WFSSource.js +0 -168
- package/lib/Source/WMSSource.js +0 -133
- package/lib/Source/WMTSSource.js +0 -86
- package/lib/ThreeExtended/capabilities/WebGL.js +0 -69
- package/lib/ThreeExtended/libs/ktx-parse.module.js +0 -470
- package/lib/ThreeExtended/libs/zstddec.module.js +0 -29
- package/lib/ThreeExtended/loaders/DDSLoader.js +0 -200
- package/lib/ThreeExtended/loaders/DRACOLoader.js +0 -399
- package/lib/ThreeExtended/loaders/GLTFLoader.js +0 -2876
- package/lib/ThreeExtended/loaders/KTX2Loader.js +0 -625
- package/lib/ThreeExtended/utils/BufferGeometryUtils.js +0 -846
- package/lib/ThreeExtended/utils/WorkerPool.js +0 -70
- package/lib/Utils/CameraUtils.js +0 -555
- package/lib/Utils/DEMUtils.js +0 -350
- package/lib/Utils/FeaturesUtils.js +0 -156
- package/lib/Utils/Gradients.js +0 -16
- package/lib/Utils/OrientationUtils.js +0 -457
- package/lib/Utils/ThreeUtils.js +0 -115
- package/lib/Utils/gui/C3DTilesStyle.js +0 -215
- package/lib/Utils/gui/Main.js +0 -7
- package/lib/Utils/gui/Minimap.js +0 -154
- package/lib/Utils/gui/Navigation.js +0 -245
- package/lib/Utils/gui/Scale.js +0 -107
- package/lib/Utils/gui/Searchbar.js +0 -234
- package/lib/Utils/gui/Widget.js +0 -80
- package/lib/Utils/placeObjectOnGround.js +0 -137
- package/lib/Worker/LASLoaderWorker.js +0 -19
- package/lib/Worker/Potree2Worker.js +0 -21
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
import { C3DTILES_LAYER_EVENTS } from "../../Layer/C3DTilesLayer.js";
|
|
2
|
-
import Widget from "./Widget.js";
|
|
3
|
-
const DEFAULT_OPTIONS = {
|
|
4
|
-
width: 200,
|
|
5
|
-
position: 'top-right'
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* A widget for dynamic 3DTiles styling
|
|
10
|
-
*
|
|
11
|
-
* To use it, you need to link the widgets' stylesheet to your html webpage. This stylesheet is included in
|
|
12
|
-
* [itowns bundles](https://github.com/iTowns/itowns/releases) if you downloaded them, or it can be found in
|
|
13
|
-
* `node_modules/itowns/examples/css` if you installed iTowns with npm. Otherwise, it can be found at
|
|
14
|
-
* [this link](https://raw.githubusercontent.com/iTowns/itowns/master/examples/css/widgets.css). See
|
|
15
|
-
* [this example](http://www.itowns-project.org/itowns/examples/#widgets_3dtiles_style) for more details.
|
|
16
|
-
*
|
|
17
|
-
* @extends Widget
|
|
18
|
-
*
|
|
19
|
-
* @property {HTMLElement} domElement An html div containing the minimap.
|
|
20
|
-
* @property {HTMLElement} parentElement The parent HTML container of `this.domElement`.
|
|
21
|
-
*/
|
|
22
|
-
class C3DTilesStyle extends Widget {
|
|
23
|
-
/**
|
|
24
|
-
*
|
|
25
|
-
* @param {View} view view
|
|
26
|
-
* @param {*} options options
|
|
27
|
-
*/
|
|
28
|
-
constructor(view, options) {
|
|
29
|
-
super(view, options, DEFAULT_OPTIONS);
|
|
30
|
-
this.domElement.onclick = event => event.stopImmediatePropagation();
|
|
31
|
-
|
|
32
|
-
// create select of the C3DTilesLayers
|
|
33
|
-
const selectC3DTilesLayer = document.createElement('select');
|
|
34
|
-
this.domElement.appendChild(selectC3DTilesLayer);
|
|
35
|
-
|
|
36
|
-
/** @type {Map<HTMLElement, HTMLElement>} */
|
|
37
|
-
const selectOptionLayerContent = new Map();
|
|
38
|
-
const updateSelectedLayer = () => {
|
|
39
|
-
for (const [sO, lC] of selectOptionLayerContent) {
|
|
40
|
-
lC.hidden = sO !== selectC3DTilesLayer.selectedOptions[0];
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
selectC3DTilesLayer.onchange = updateSelectedLayer;
|
|
44
|
-
view.getLayers().filter(el => el.isC3DTilesLayer === true).forEach(c3DTilesLayer => {
|
|
45
|
-
const selectC3DTilesLayerOption = document.createElement('option');
|
|
46
|
-
selectC3DTilesLayerOption.innerText = c3DTilesLayer.name;
|
|
47
|
-
selectC3DTilesLayer.add(selectC3DTilesLayerOption);
|
|
48
|
-
const layerContent = document.createElement('div');
|
|
49
|
-
this.domElement.appendChild(layerContent);
|
|
50
|
-
|
|
51
|
-
// link select option to layer content
|
|
52
|
-
selectOptionLayerContent.set(selectC3DTilesLayerOption, layerContent);
|
|
53
|
-
|
|
54
|
-
// wait for C3DTileFeatures to load
|
|
55
|
-
c3DTilesLayer.addEventListener(C3DTILES_LAYER_EVENTS.ON_TILE_CONTENT_LOADED, () => {
|
|
56
|
-
// reset
|
|
57
|
-
while (layerContent.firstChild) {
|
|
58
|
-
layerContent.firstChild.remove();
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/** @type {Map<string,Array>} */
|
|
62
|
-
const buffer = new Map(); // record what are the possible values for a key in batchTable
|
|
63
|
-
for (const [, tileC3DTileFeatures] of c3DTilesLayer.tilesC3DTileFeatures) {
|
|
64
|
-
for (const [, c3DTileFeature] of tileC3DTileFeatures) {
|
|
65
|
-
// eslint-disable-next-line guard-for-in
|
|
66
|
-
for (const key in c3DTileFeature.getInfo().batchTable) {
|
|
67
|
-
if (!buffer.has(key)) {
|
|
68
|
-
buffer.set(key, []);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// check possible value for this key
|
|
72
|
-
const value = c3DTileFeature.getInfo().batchTable[key];
|
|
73
|
-
if (!buffer.get(key).includes(value)) {
|
|
74
|
-
buffer.get(key).push(value);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/** @type {Map<HTMLElement, Function>} */
|
|
81
|
-
const colorFunctions = new Map();
|
|
82
|
-
/** @type {Map<HTMLElement, Function>} */
|
|
83
|
-
const opacityFunctions = new Map();
|
|
84
|
-
const appendInputColorAndOpacity = (getKeyValue, key, possibleValues) => {
|
|
85
|
-
const inputColor = document.createElement('input');
|
|
86
|
-
inputColor.setAttribute('type', 'color');
|
|
87
|
-
layerContent.appendChild(inputColor);
|
|
88
|
-
inputColor.onchange = () => {
|
|
89
|
-
const keyValue = getKeyValue();
|
|
90
|
-
if (!possibleValues.includes(keyValue)) {
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
const colorSelected = inputColor.value; // copy
|
|
94
|
-
colorFunctions.set(keyValue, c3DTileFeature => {
|
|
95
|
-
if (c3DTileFeature.getInfo().batchTable[key] == keyValue) {
|
|
96
|
-
return colorSelected;
|
|
97
|
-
}
|
|
98
|
-
return null;
|
|
99
|
-
});
|
|
100
|
-
c3DTilesLayer.updateStyle();
|
|
101
|
-
view.notifyChange();
|
|
102
|
-
};
|
|
103
|
-
const opacityElement = document.createElement('input');
|
|
104
|
-
opacityElement.setAttribute('type', 'range');
|
|
105
|
-
opacityElement.min = 0;
|
|
106
|
-
opacityElement.max = 1;
|
|
107
|
-
opacityElement.step = 0.1;
|
|
108
|
-
opacityElement.value = 1;
|
|
109
|
-
layerContent.appendChild(opacityElement);
|
|
110
|
-
opacityElement.onchange = () => {
|
|
111
|
-
const keyValue = getKeyValue();
|
|
112
|
-
if (!possibleValues.includes(keyValue)) {
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
const opacitySelected = opacityElement.value; // copy
|
|
116
|
-
opacityFunctions.set(keyValue, c3DTileFeature => {
|
|
117
|
-
if (c3DTileFeature.getInfo().batchTable[key] == keyValue) {
|
|
118
|
-
return opacitySelected;
|
|
119
|
-
}
|
|
120
|
-
return null;
|
|
121
|
-
});
|
|
122
|
-
c3DTilesLayer.updateStyle();
|
|
123
|
-
view.notifyChange();
|
|
124
|
-
};
|
|
125
|
-
return {
|
|
126
|
-
inputColor,
|
|
127
|
-
opacityElement
|
|
128
|
-
};
|
|
129
|
-
};
|
|
130
|
-
const appendFilterSelect = (key, values) => {
|
|
131
|
-
const label = document.createElement('label');
|
|
132
|
-
label.innerText = key;
|
|
133
|
-
layerContent.appendChild(label);
|
|
134
|
-
const selectKey = document.createElement('select');
|
|
135
|
-
layerContent.appendChild(selectKey);
|
|
136
|
-
values.forEach(value => {
|
|
137
|
-
const selectKeyOption = document.createElement('option');
|
|
138
|
-
selectKeyOption.value = value;
|
|
139
|
-
selectKeyOption.text = value;
|
|
140
|
-
selectKey.add(selectKeyOption);
|
|
141
|
-
});
|
|
142
|
-
appendInputColorAndOpacity(() => selectKey.selectedOptions[0].value, key, values);
|
|
143
|
-
};
|
|
144
|
-
const appendFilterInputText = (key, values) => {
|
|
145
|
-
const label = document.createElement('label');
|
|
146
|
-
label.innerText = key;
|
|
147
|
-
layerContent.appendChild(label);
|
|
148
|
-
const inputText = document.createElement('input');
|
|
149
|
-
inputText.setAttribute('type', 'text');
|
|
150
|
-
layerContent.appendChild(inputText);
|
|
151
|
-
const {
|
|
152
|
-
inputColor,
|
|
153
|
-
opacityElement
|
|
154
|
-
} = appendInputColorAndOpacity(() => inputText.value, key, values);
|
|
155
|
-
inputText.onchange = () => {
|
|
156
|
-
if (!values.includes(inputText.value)) {
|
|
157
|
-
return;
|
|
158
|
-
}
|
|
159
|
-
const colorSelected = inputColor.value; // copy
|
|
160
|
-
const textSelected = inputText.value; // copy
|
|
161
|
-
colorFunctions.set(textSelected, c3DTileFeature => {
|
|
162
|
-
if (c3DTileFeature.getInfo().batchTable[key] == textSelected) {
|
|
163
|
-
return colorSelected;
|
|
164
|
-
}
|
|
165
|
-
return null;
|
|
166
|
-
});
|
|
167
|
-
const opacitySelected = opacityElement.value; // copy
|
|
168
|
-
opacityFunctions.set(textSelected, c3DTileFeature => {
|
|
169
|
-
if (c3DTileFeature.getInfo().batchTable[key] == textSelected) {
|
|
170
|
-
return opacitySelected;
|
|
171
|
-
}
|
|
172
|
-
return null;
|
|
173
|
-
});
|
|
174
|
-
c3DTilesLayer.updateStyle();
|
|
175
|
-
view.notifyChange();
|
|
176
|
-
};
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
// create ui from buffer
|
|
180
|
-
for (const [key, values] of buffer) {
|
|
181
|
-
if (values.length < C3DTilesStyle.MAX_SELECT_VALUE) {
|
|
182
|
-
appendFilterSelect(key, values);
|
|
183
|
-
} else {
|
|
184
|
-
appendFilterInputText(key, values);
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
// set style
|
|
189
|
-
c3DTilesLayer.style = {
|
|
190
|
-
fill: {
|
|
191
|
-
color: c3DTileFeature => {
|
|
192
|
-
let result = null;
|
|
193
|
-
for (const [, colorFunction] of colorFunctions) {
|
|
194
|
-
result = colorFunction(c3DTileFeature) || result;
|
|
195
|
-
}
|
|
196
|
-
return result;
|
|
197
|
-
},
|
|
198
|
-
opacity: c3DTileFeature => {
|
|
199
|
-
let result = 1;
|
|
200
|
-
for (const [, opacityFunction] of opacityFunctions) {
|
|
201
|
-
result = opacityFunction(c3DTileFeature) || result;
|
|
202
|
-
}
|
|
203
|
-
return result;
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
};
|
|
207
|
-
});
|
|
208
|
-
});
|
|
209
|
-
updateSelectedLayer();
|
|
210
|
-
}
|
|
211
|
-
static get MAX_SELECT_VALUE() {
|
|
212
|
-
return 10;
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
export default C3DTilesStyle;
|
package/lib/Utils/gui/Main.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
// eslint-disable-next-line import/prefer-default-export
|
|
2
|
-
export { default as Navigation } from "./Navigation.js";
|
|
3
|
-
export { default as Minimap } from "./Minimap.js";
|
|
4
|
-
export { default as Scale } from "./Scale.js";
|
|
5
|
-
export { default as Searchbar } from "./Searchbar.js";
|
|
6
|
-
export { default as Widget } from "./Widget.js";
|
|
7
|
-
export { default as C3DTilesStyle } from "./C3DTilesStyle.js";
|
package/lib/Utils/gui/Minimap.js
DELETED
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import Coordinates from "../../Core/Geographic/Coordinates.js";
|
|
2
|
-
import { MAIN_LOOP_EVENTS } from "../../Core/MainLoop.js";
|
|
3
|
-
import PlanarView from "../../Core/Prefab/PlanarView.js";
|
|
4
|
-
import { CAMERA_TYPE } from "../../Renderer/Camera.js";
|
|
5
|
-
import Widget from "./Widget.js";
|
|
6
|
-
const DEFAULT_OPTIONS = {
|
|
7
|
-
minScale: 1 / 500000,
|
|
8
|
-
maxScale: 1 / 5E8,
|
|
9
|
-
zoomRatio: 1 / 30,
|
|
10
|
-
width: 150,
|
|
11
|
-
height: 150,
|
|
12
|
-
position: 'bottom-left'
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* A widget for minimap
|
|
17
|
-
*
|
|
18
|
-
* To use it, you need to link the widgets' stylesheet to your html webpage. This stylesheet is included in
|
|
19
|
-
* [itowns bundles](https://github.com/iTowns/itowns/releases) if you downloaded them, or it can be found in
|
|
20
|
-
* `node_modules/itowns/examples/css` if you installed iTowns with npm. Otherwise, it can be found at
|
|
21
|
-
* [this link](https://raw.githubusercontent.com/iTowns/itowns/master/examples/css/widgets.css). See
|
|
22
|
-
* [this example](http://www.itowns-project.org/itowns/examples/#widgets_minimap) for more details.
|
|
23
|
-
*
|
|
24
|
-
* @extends Widget
|
|
25
|
-
*
|
|
26
|
-
* @property {HTMLElement} domElement An html div containing the minimap.
|
|
27
|
-
* @property {HTMLElement} parentElement The parent HTML container of `this.domElement`.
|
|
28
|
-
*/
|
|
29
|
-
class Minimap extends Widget {
|
|
30
|
-
/**
|
|
31
|
-
* @param {GlobeView} view The iTowns view the minimap should be
|
|
32
|
-
* linked to. Only {@link GlobeView} is
|
|
33
|
-
* supported at the moment.
|
|
34
|
-
* @param {ColorLayer} layer The {@link ColorLayer} that should be
|
|
35
|
-
* displayed on the minimap.
|
|
36
|
-
* @param {Object} [options] The minimap optional configuration.
|
|
37
|
-
* @param {HTMLElement} [options.parentElement=view.domElement] The parent HTML container of the div
|
|
38
|
-
* which contains minimap widgets.
|
|
39
|
-
* @param {number} [options.size] The size of the minimap. It is a number
|
|
40
|
-
* that describes both width and height
|
|
41
|
-
* in pixels of the minimap.
|
|
42
|
-
* @param {number} [options.width=150] The width in pixels of the minimap.
|
|
43
|
-
* @param {number} [options.height=150] The height in pixels of the minimap.
|
|
44
|
-
* @param {string} [options.position='bottom-left'] Defines which position within the
|
|
45
|
-
* `parentElement` the minimap should be
|
|
46
|
-
* displayed to. Possible values are
|
|
47
|
-
* `top`, `bottom`, `left`, `right`,
|
|
48
|
-
* `top-left`, `top-right`, `bottom-left`
|
|
49
|
-
* and `bottom-right`. If the input value
|
|
50
|
-
* does not match one of these, it will
|
|
51
|
-
* be defaulted to `bottom-left`.
|
|
52
|
-
* @param {Object} [options.translate] An optional translation of the minimap.
|
|
53
|
-
* @param {number} [options.translate.x=0] The minimap translation along the page
|
|
54
|
-
* x-axis.
|
|
55
|
-
* @param {number} [options.translate.y=0] The minimap translation along the page
|
|
56
|
-
* y-axis.
|
|
57
|
-
* @param {HTMLElement|string} [options.cursor] An html element or an HTML string
|
|
58
|
-
* describing a cursor showing minimap
|
|
59
|
-
* view camera target position at the
|
|
60
|
-
* center of the minimap.
|
|
61
|
-
* @param {number} [options.minScale=1/2000] The minimal scale the minimap can reach.
|
|
62
|
-
* @param {number} [options.maxScale=1/1_250_000] The maximal scale the minimap can reach.
|
|
63
|
-
* @param {number} [options.zoomRatio=1/30] The ratio between minimap camera zoom
|
|
64
|
-
* and view camera zoom.
|
|
65
|
-
* @param {number} [options.pitch=0.28] The screen pixel pitch, used to compute
|
|
66
|
-
* view and minimap scale.
|
|
67
|
-
*/
|
|
68
|
-
constructor(view, layer) {
|
|
69
|
-
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
70
|
-
// ---------- BUILD PROPERTIES ACCORDING TO DEFAULT OPTIONS AND OPTIONS PASSED IN PARAMETERS : ----------
|
|
71
|
-
|
|
72
|
-
if (!view.isGlobeView) {
|
|
73
|
-
throw new Error('\'Minimap\' plugin only supports \'GlobeView\'. Therefore, the \'view\' parameter must be a ' + '\'GlobeView\'.');
|
|
74
|
-
}
|
|
75
|
-
if (!layer.isColorLayer) {
|
|
76
|
-
throw new Error('\'layer\' parameter form \'Minimap\' constructor should be a \'ColorLayer\'.');
|
|
77
|
-
}
|
|
78
|
-
super(view, options, DEFAULT_OPTIONS);
|
|
79
|
-
this.minScale = options.minScale || DEFAULT_OPTIONS.minScale;
|
|
80
|
-
this.maxScale = options.maxScale || DEFAULT_OPTIONS.maxScale;
|
|
81
|
-
|
|
82
|
-
// TODO : it could be interesting to be able to specify a method as zoomRatio parameter. This method could
|
|
83
|
-
// return a zoom ratio from the scale of the minimap.
|
|
84
|
-
this.zoomRatio = options.zoomRatio || DEFAULT_OPTIONS.zoomRatio;
|
|
85
|
-
|
|
86
|
-
// ---------- this.domElement SETTINGS SPECIFIC TO MINIMAP : ----------
|
|
87
|
-
|
|
88
|
-
this.domElement.id = 'widgets-minimap';
|
|
89
|
-
|
|
90
|
-
// Display a cursor at the center of the minimap, if requested.
|
|
91
|
-
if (options.cursor) {
|
|
92
|
-
// Wrap cursor domElement inside a div to center it in minimap.
|
|
93
|
-
const cursorWrapper = document.createElement('div');
|
|
94
|
-
cursorWrapper.id = 'cursor-wrapper';
|
|
95
|
-
this.domElement.appendChild(cursorWrapper);
|
|
96
|
-
|
|
97
|
-
// Add specified cursor to its wrapper.
|
|
98
|
-
if (typeof options.cursor === 'string') {
|
|
99
|
-
cursorWrapper.innerHTML = options.cursor;
|
|
100
|
-
} else if (options.cursor instanceof HTMLElement) {
|
|
101
|
-
cursorWrapper.appendChild(options.cursor);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// ---------- CREATE A MINIMAP View AND DISPLAY DATA PASSED IN Layer PARAMETER : ----------
|
|
106
|
-
|
|
107
|
-
this.view = new PlanarView(this.domElement, layer.source.extent, {
|
|
108
|
-
camera: {
|
|
109
|
-
type: CAMERA_TYPE.ORTHOGRAPHIC
|
|
110
|
-
},
|
|
111
|
-
placement: layer.source.extent,
|
|
112
|
-
// TODO : the default placement should be the view extent for ortho camera
|
|
113
|
-
noControls: true,
|
|
114
|
-
maxSubdivisionLevel: view.tileLayer.maxSubdivisionLevel,
|
|
115
|
-
disableFocusOnStart: true
|
|
116
|
-
});
|
|
117
|
-
this.view.addLayer(layer); // TODO : should this promise be returned by constructor so that user can use it ?
|
|
118
|
-
|
|
119
|
-
// Prevent the minimap domElement to get focus when clicked, and prevent click event to be propagated to the
|
|
120
|
-
// main view controls.
|
|
121
|
-
this.domElement.addEventListener('pointerdown', event => {
|
|
122
|
-
event.preventDefault();
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
// ---------- UPDATE MINIMAP VIEW WHEN UPDATING THE MAIN VIEW : ----------
|
|
126
|
-
|
|
127
|
-
// The minimal and maximal value the minimap camera3D zoom can reach in order to stay in the scale limits.
|
|
128
|
-
const initialScale = this.view.getScale(options.pitch);
|
|
129
|
-
const minZoom = this.view.camera3D.zoom * this.maxScale / initialScale;
|
|
130
|
-
const maxZoom = this.view.camera3D.zoom * this.minScale / initialScale;
|
|
131
|
-
|
|
132
|
-
// Coordinates used to transform position vectors from the main view CRS to the minimap view CRS.
|
|
133
|
-
const mainViewCoordinates = new Coordinates(view.referenceCrs);
|
|
134
|
-
const viewCoordinates = new Coordinates(this.view.referenceCrs);
|
|
135
|
-
const targetPosition = view.controls.getCameraTargetPosition();
|
|
136
|
-
view.addFrameRequester(MAIN_LOOP_EVENTS.AFTER_RENDER, () => {
|
|
137
|
-
// Update minimap camera zoom
|
|
138
|
-
const distance = view.camera3D.position.distanceTo(targetPosition);
|
|
139
|
-
const scale = view.getScaleFromDistance(options.pitch, distance);
|
|
140
|
-
this.view.camera3D.zoom = this.zoomRatio * maxZoom * scale / this.minScale;
|
|
141
|
-
this.view.camera3D.zoom = Math.min(Math.max(this.view.camera3D.zoom, minZoom), maxZoom);
|
|
142
|
-
this.view.camera3D.updateProjectionMatrix();
|
|
143
|
-
|
|
144
|
-
// Update minimap camera position.
|
|
145
|
-
mainViewCoordinates.setFromVector3(view.controls.getCameraTargetPosition());
|
|
146
|
-
mainViewCoordinates.as(this.view.referenceCrs, viewCoordinates);
|
|
147
|
-
this.view.camera3D.position.x = viewCoordinates.x;
|
|
148
|
-
this.view.camera3D.position.y = viewCoordinates.y;
|
|
149
|
-
this.view.camera3D.updateMatrixWorld(true);
|
|
150
|
-
this.view.notifyChange(this.view.camera3D);
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
export default Minimap;
|
|
@@ -1,245 +0,0 @@
|
|
|
1
|
-
import { VIEW_EVENTS } from "../../Core/View.js";
|
|
2
|
-
import Widget from "./Widget.js";
|
|
3
|
-
const DEFAULT_OPTIONS = {
|
|
4
|
-
displayCompass: true,
|
|
5
|
-
display3DToggle: true,
|
|
6
|
-
displayZoomIn: true,
|
|
7
|
-
displayZoomOut: true,
|
|
8
|
-
animationDuration: 500,
|
|
9
|
-
position: 'bottom-left',
|
|
10
|
-
direction: 'column'
|
|
11
|
-
};
|
|
12
|
-
const DEFAULT_BUTTONS = {
|
|
13
|
-
compass: {
|
|
14
|
-
id: 'compass',
|
|
15
|
-
content: '',
|
|
16
|
-
info: 'Rotate the camera to face North',
|
|
17
|
-
parentId: 'widgets'
|
|
18
|
-
},
|
|
19
|
-
toggle3D: {
|
|
20
|
-
id: '3d-button',
|
|
21
|
-
content: '3D',
|
|
22
|
-
info: 'Tilt the camera'
|
|
23
|
-
},
|
|
24
|
-
zoomIn: {
|
|
25
|
-
id: 'zoom-in-button',
|
|
26
|
-
content: '<span class="widget-zoom-button-logo"></span>',
|
|
27
|
-
info: 'Zoom in',
|
|
28
|
-
parentId: 'zoom-button-bar'
|
|
29
|
-
},
|
|
30
|
-
zoomOut: {
|
|
31
|
-
id: 'zoom-out-button',
|
|
32
|
-
content: '<span id="zoom-out-logo" class="widget-zoom-button-logo"></span>',
|
|
33
|
-
info: 'Zoom out',
|
|
34
|
-
parentId: 'zoom-button-bar'
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* A widget menu manager for navigation.
|
|
40
|
-
*
|
|
41
|
-
* To use it, you need to link the widgets' stylesheet to your html webpage. This stylesheet is included in
|
|
42
|
-
* [itowns bundles](https://github.com/iTowns/itowns/releases) if you downloaded them, or it can be found in
|
|
43
|
-
* `node_modules/itowns/examples/css` if you installed iTowns with npm. Otherwise, it can be found at
|
|
44
|
-
* [this link](https://raw.githubusercontent.com/iTowns/itowns/master/examples/css/widgets.css). See
|
|
45
|
-
* [this example](http://www.itowns-project.org/itowns/examples/#widgets_navigation) for more details.
|
|
46
|
-
*
|
|
47
|
-
* @extends Widget
|
|
48
|
-
*
|
|
49
|
-
* @property {HTMLElement} domElement An html div containing all navigation widgets.
|
|
50
|
-
* @property {HTMLElement} parentElement The parent HTML container of `this.domElement`.
|
|
51
|
-
* @property {HTMLButtonElement} compass The HTML button for the compass.
|
|
52
|
-
* @property {HTMLButtonElement} toggle3D The HTML button for the 3D/2D toggle button.
|
|
53
|
-
* @property {HTMLButtonElement} zoomIn The HTML button for the zoom-in button.
|
|
54
|
-
* @property {HTMLButtonElement} zoomOut The HTML button for the zoom-out button.
|
|
55
|
-
*
|
|
56
|
-
* @example
|
|
57
|
-
* // Create a Navigation widget in the bottom-right corner of an iTowns view domElement
|
|
58
|
-
* const navigation = new Navigation(view, { position: 'bottom-right' };
|
|
59
|
-
*
|
|
60
|
-
* // Change the tooltip for the compass :
|
|
61
|
-
* navigation.compass.title = 'new tooltip';
|
|
62
|
-
*
|
|
63
|
-
* // Change the method ran when clicking zoom-in button :
|
|
64
|
-
* function newMethod() {
|
|
65
|
-
* // do something
|
|
66
|
-
* }
|
|
67
|
-
* navigation.zoomIn.onclick = newMethod;
|
|
68
|
-
*/
|
|
69
|
-
class Navigation extends Widget {
|
|
70
|
-
#_view;
|
|
71
|
-
#_action(params) {
|
|
72
|
-
params.time = this.animationDuration;
|
|
73
|
-
return this.#_view.controls.lookAtCoordinate(params);
|
|
74
|
-
}
|
|
75
|
-
#_addDefaultButton(settings, onclick) {
|
|
76
|
-
return this.addButton(settings.id, settings.content, settings.info, onclick, settings.parentId);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* @param {GlobeView} view The iTowns view the navigation should be linked
|
|
81
|
-
* to. For the moment, only `{@link GlobeView}`
|
|
82
|
-
* is supported.
|
|
83
|
-
* @param {Object} options The navigation menu optional configuration.
|
|
84
|
-
* @param {HTMLElement} [options.parentElement=view.domElement] The parent HTML container of the div which
|
|
85
|
-
* contains navigation widgets.
|
|
86
|
-
* @param {boolean} [options.displayCompass=true] Whether the compass widget should be displayed.
|
|
87
|
-
* @param {boolean} [options.display3DToggle=true] Whether the navigation should include a widget
|
|
88
|
-
* to toggle between top and oblique view.
|
|
89
|
-
* @param {boolean} [options.displayZoomIn=true] Whether the zoom-in widget should be displayed.
|
|
90
|
-
* @param {boolean} [options.displayZoomOut=true] Whether the zoom-out widget should be displayed.
|
|
91
|
-
* @param {number} [options.animationDuration=500] The duration of travel animations, when clicking
|
|
92
|
-
* navigation widgets.
|
|
93
|
-
* @param {string} [options.position='bottom-left'] Defines which corner of the `parentElement` the
|
|
94
|
-
* navigation menu should be displayed to.
|
|
95
|
-
* Possible values are `top-left`, `top-right`,
|
|
96
|
-
* `bottom-left` and `bottom-right`. If the input
|
|
97
|
-
* value does not match one of these, it will be
|
|
98
|
-
* defaulted to `bottom-left`.
|
|
99
|
-
* @param {string} [options.direction='column'] Whether the navigation menu should expand
|
|
100
|
-
* horizontally or vertically. Possible values
|
|
101
|
-
* are `column` and `row`. If the input value
|
|
102
|
-
* does not match one of these, it will be
|
|
103
|
-
* defaulted to `column`.
|
|
104
|
-
* @param {Object} [options.translate] An optional translation of the navigation menu.
|
|
105
|
-
* @param {number} [options.translate.x=0] The navigation menu translation along the page
|
|
106
|
-
* x-axis.
|
|
107
|
-
* @param {number} [options.translate.y=0] The navigation menu translation along the page
|
|
108
|
-
* y-axis.
|
|
109
|
-
*/
|
|
110
|
-
constructor(view) {
|
|
111
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
112
|
-
// ---------- BUILD PROPERTIES ACCORDING TO DEFAULT OPTIONS AND OPTIONS PASSED IN PARAMETERS : ----------
|
|
113
|
-
|
|
114
|
-
// Check if the view is supported.
|
|
115
|
-
if (!view.isGlobeView) {
|
|
116
|
-
throw new Error('\'Navigation\' plugin only supports \'GlobeView\'. Therefore, the \'view\' parameter must be a ' + '\'GlobeView\'.');
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
// `top`, `bottom`, `left` and `right` values for `position` option are not relevant for navigation widget.
|
|
120
|
-
if (['top', 'bottom', 'left', 'right'].includes(options.position)) {
|
|
121
|
-
console.warn('\'position\' optional parameter for \'Navigation\' is not a valid option. ' + `It will be set to '${DEFAULT_OPTIONS.position}'.`);
|
|
122
|
-
options.position = DEFAULT_OPTIONS.position;
|
|
123
|
-
}
|
|
124
|
-
super(view, options, DEFAULT_OPTIONS);
|
|
125
|
-
this.#_view = view;
|
|
126
|
-
this.direction = options.direction || DEFAULT_OPTIONS.direction;
|
|
127
|
-
if (!['column', 'row'].includes(this.direction)) {
|
|
128
|
-
console.warn('\'direction\' optional parameter for \'Navigation\' constructor is not a valid option. ' + `It will be set to '${DEFAULT_OPTIONS.direction}'.`);
|
|
129
|
-
this.direction = DEFAULT_OPTIONS.direction;
|
|
130
|
-
}
|
|
131
|
-
this.animationDuration = options.animationDuration === undefined ? DEFAULT_OPTIONS.animationDuration : options.animationDuration;
|
|
132
|
-
|
|
133
|
-
// ---------- CREATE A DomElement WITH id AND classes RELEVANT TO THE WIDGET PROPERTIES : ----------
|
|
134
|
-
|
|
135
|
-
// Create a div containing all widgets and add it to its specified parent.
|
|
136
|
-
this.domElement.id = 'widgets-navigation';
|
|
137
|
-
|
|
138
|
-
// Position widget div according to options.
|
|
139
|
-
this.domElement.classList.add(`${this.direction}-widget`);
|
|
140
|
-
|
|
141
|
-
// ---------- CREATE THE DEFAULT WIDGETS IF NOT HIDDEN (COMPASS, 3D AND ZOOM BUTTONS) : ----------
|
|
142
|
-
|
|
143
|
-
// Add a compass widget if requested.
|
|
144
|
-
if (options.displayCompass ?? DEFAULT_OPTIONS.displayCompass) {
|
|
145
|
-
this.compass = this.#_addDefaultButton(DEFAULT_BUTTONS.compass, () => {
|
|
146
|
-
this.#_action({
|
|
147
|
-
heading: 0,
|
|
148
|
-
tilt: 89.5
|
|
149
|
-
});
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
// Manage compass rotation when the view's camera is moved.
|
|
153
|
-
view.addEventListener(VIEW_EVENTS.CAMERA_MOVED, event => {
|
|
154
|
-
this.compass.style.transform = `rotate(${-event.heading}deg)`;
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
// Add a 3D toggle button if requested.
|
|
159
|
-
if (options.display3DToggle ?? DEFAULT_OPTIONS.display3DToggle) {
|
|
160
|
-
this.toggle3D = this.#_addDefaultButton(DEFAULT_BUTTONS.toggle3D, () => {
|
|
161
|
-
this.#_action({
|
|
162
|
-
tilt: this.#_view.controls.getTilt() < 89 ? 89.5 : 40
|
|
163
|
-
});
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
// Manage button content toggle when the view's camera is moved.
|
|
167
|
-
view.addEventListener(VIEW_EVENTS.CAMERA_MOVED, event => {
|
|
168
|
-
this.toggle3D.innerHTML = event.tilt < 89 ? '2D' : '3D';
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
// Add a zoom-in button if requested.
|
|
173
|
-
if (options.displayZoomIn ?? DEFAULT_OPTIONS.displayZoomIn) {
|
|
174
|
-
this.zoomIn = this.#_addDefaultButton(DEFAULT_BUTTONS.zoomIn, () => {
|
|
175
|
-
this.#_action({
|
|
176
|
-
zoom: Math.min(20, this.#_view.controls.getZoom() + 1)
|
|
177
|
-
});
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
// Add a zoom-out button if requested.
|
|
182
|
-
if (options.displayZoomOut ?? DEFAULT_OPTIONS.displayZoomOut) {
|
|
183
|
-
this.zoomOut = this.#_addDefaultButton(DEFAULT_BUTTONS.zoomOut, () => {
|
|
184
|
-
this.#_action({
|
|
185
|
-
zoom: Math.max(3, this.#_view.controls.getZoom() - 1)
|
|
186
|
-
});
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
*
|
|
193
|
-
* @param {string} id The unique id the created button should be given.
|
|
194
|
-
* @param {string} [content=''] An HTML string defining the content of the button.
|
|
195
|
-
* @param {string} [title=''] An HTML string defining information on the button. This string will be
|
|
196
|
-
* displayed in a tooltip when hovering the button.
|
|
197
|
-
* @param {function} [onclick] The method that should be executed when the button is clicked on.
|
|
198
|
-
* @param {string} [parentId] The unique id of a button bar in which the created button should be added.
|
|
199
|
-
* A button bar is a group which contains one or several buttons. All
|
|
200
|
-
* buttons created with Navigation are in a button bar. If the given id does
|
|
201
|
-
* not match an already existing button bar, a new button bar will be created
|
|
202
|
-
* with this id. If no id is given, a button bar will be created with no id.
|
|
203
|
-
* The later case can be useful for creating isolated buttons.
|
|
204
|
-
*
|
|
205
|
-
* @returns {HTMLButtonElement} The created button.
|
|
206
|
-
*/
|
|
207
|
-
addButton(id) {
|
|
208
|
-
let content = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
209
|
-
let title = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
|
|
210
|
-
let onclick = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : () => {};
|
|
211
|
-
let parentId = arguments.length > 4 ? arguments[4] : undefined;
|
|
212
|
-
let buttonBar = document.getElementById(parentId);
|
|
213
|
-
if (!buttonBar) {
|
|
214
|
-
buttonBar = this.addButtonBar(parentId);
|
|
215
|
-
}
|
|
216
|
-
const button = document.createElement('button');
|
|
217
|
-
button.className = 'widget-button';
|
|
218
|
-
button.id = id;
|
|
219
|
-
button.innerHTML = content;
|
|
220
|
-
button.title = title;
|
|
221
|
-
button.onclick = onclick;
|
|
222
|
-
buttonBar.appendChild(button);
|
|
223
|
-
|
|
224
|
-
// The buttons must not be focused using tab key.
|
|
225
|
-
button.tabIndex = -1;
|
|
226
|
-
// When releasing the mouse after clicking the button, we give the focus back to the view. Therefore, we can use
|
|
227
|
-
// key events on the view without having to click the view to grant it focus.
|
|
228
|
-
window.addEventListener('pointerup', () => {
|
|
229
|
-
if (document.activeElement === button) {
|
|
230
|
-
this.#_view.domElement.focus();
|
|
231
|
-
}
|
|
232
|
-
});
|
|
233
|
-
return button;
|
|
234
|
-
}
|
|
235
|
-
addButtonBar(id) {
|
|
236
|
-
const buttonBar = document.createElement('div');
|
|
237
|
-
buttonBar.className = 'widget-button-bar';
|
|
238
|
-
if (id) {
|
|
239
|
-
buttonBar.id = id;
|
|
240
|
-
}
|
|
241
|
-
this.domElement.appendChild(buttonBar);
|
|
242
|
-
return buttonBar;
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
export default Navigation;
|