itowns 2.44.3-next.13 → 2.44.3-next.14
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/dist/itowns.js +1 -1
- package/dist/itowns.js.map +1 -1
- package/lib/Core/View.js +13 -6
- package/lib/Layer/OGC3DTilesLayer.js +26 -22
- package/package.json +1 -1
package/lib/Core/View.js
CHANGED
|
@@ -30,7 +30,8 @@ export const VIEW_EVENTS = {
|
|
|
30
30
|
LAYER_ADDED: 'layer-added',
|
|
31
31
|
INITIALIZED: 'initialized',
|
|
32
32
|
COLOR_LAYERS_ORDER_CHANGED,
|
|
33
|
-
CAMERA_MOVED: 'camera-moved'
|
|
33
|
+
CAMERA_MOVED: 'camera-moved',
|
|
34
|
+
DISPOSED: 'disposed'
|
|
34
35
|
};
|
|
35
36
|
|
|
36
37
|
/**
|
|
@@ -109,9 +110,11 @@ const coordinates = new Coordinates('EPSG:4326');
|
|
|
109
110
|
const viewers = [];
|
|
110
111
|
// Size of the camera frustrum, in meters
|
|
111
112
|
let screenMeters;
|
|
113
|
+
let id = 0;
|
|
112
114
|
|
|
113
115
|
/**
|
|
114
|
-
* @property {
|
|
116
|
+
* @property {number} id - The id of the view. It's incremented at each new view instance, starting at 0.
|
|
117
|
+
* @property {HTMLElement} domElement - The domElement holding the canvas where the view is displayed
|
|
115
118
|
* @property {String} referenceCrs - The coordinate reference system of the view
|
|
116
119
|
* @property {MainLoop} mainLoop - itowns mainloop scheduling the operations
|
|
117
120
|
* @property {THREE.Scene} scene - threejs scene of the view
|
|
@@ -136,10 +139,10 @@ class View extends THREE.EventDispatcher {
|
|
|
136
139
|
* var view = itowns.View('EPSG:4326', viewerDiv, { camera: { type: itowns.CAMERA_TYPE.ORTHOGRAPHIC } });
|
|
137
140
|
* var customControls = itowns.THREE.OrbitControls(view.camera3D, viewerDiv);
|
|
138
141
|
*
|
|
139
|
-
* @param {
|
|
142
|
+
* @param {String} crs - The default CRS of Three.js coordinates. Should be a cartesian CRS.
|
|
140
143
|
* @param {HTMLElement} viewerDiv - Where to instanciate the Three.js scene in the DOM
|
|
141
144
|
* @param {Object} [options] - Optional properties.
|
|
142
|
-
* @param {
|
|
145
|
+
* @param {Object} [options.camera] - Options for the camera associated to the view. See {@link Camera} options.
|
|
143
146
|
* @param {MainLoop} [options.mainLoop] - {@link MainLoop} instance to use, otherwise a default one will be constructed
|
|
144
147
|
* @param {WebGLRenderer|Object} [options.renderer] - {@link WebGLRenderer} instance to use, otherwise
|
|
145
148
|
* a default one will be constructed. In this case, if options.renderer is an object, it will be used to
|
|
@@ -159,6 +162,7 @@ class View extends THREE.EventDispatcher {
|
|
|
159
162
|
}
|
|
160
163
|
super();
|
|
161
164
|
this.domElement = viewerDiv;
|
|
165
|
+
this.id = id++;
|
|
162
166
|
this.referenceCrs = crs;
|
|
163
167
|
let engine;
|
|
164
168
|
// options.renderer can be 2 separate things:
|
|
@@ -272,8 +276,6 @@ class View extends THREE.EventDispatcher {
|
|
|
272
276
|
}
|
|
273
277
|
// remove alls frameRequester
|
|
274
278
|
this.removeAllFrameRequesters();
|
|
275
|
-
// remove alls events
|
|
276
|
-
this.removeAllEvents();
|
|
277
279
|
// remove all layers
|
|
278
280
|
const layers = this.getLayers(l => !l.isTiledGeometryLayer && !l.isAtmosphere);
|
|
279
281
|
for (const layer of layers) {
|
|
@@ -290,6 +292,11 @@ class View extends THREE.EventDispatcher {
|
|
|
290
292
|
viewers.splice(id, 1);
|
|
291
293
|
// Remove remaining objects in the scene (e.g. helpers, debug, etc.)
|
|
292
294
|
this.scene.traverse(ObjectRemovalHelper.cleanup);
|
|
295
|
+
this.dispatchEvent({
|
|
296
|
+
type: VIEW_EVENTS.DISPOSED
|
|
297
|
+
});
|
|
298
|
+
// remove alls events
|
|
299
|
+
this.removeAllEvents();
|
|
293
300
|
}
|
|
294
301
|
|
|
295
302
|
/**
|
|
@@ -6,19 +6,20 @@ import { DRACOLoader } from "../ThreeExtended/loaders/DRACOLoader.js";
|
|
|
6
6
|
import { KTX2Loader } from "../ThreeExtended/loaders/KTX2Loader.js";
|
|
7
7
|
import ReferLayerProperties from "./ReferencingLayerProperties.js";
|
|
8
8
|
import PointsMaterial, { PNTS_MODE, PNTS_SHAPE, PNTS_SIZE_MODE, ClassificationScheme } from "../Renderer/PointsMaterial.js";
|
|
9
|
+
import { VIEW_EVENTS } from "../Core/View.js";
|
|
9
10
|
const _raycaster = new THREE.Raycaster();
|
|
10
11
|
|
|
12
|
+
// Stores lruCache, downloadQueue and parseQueue for each id of view {@link View}
|
|
13
|
+
// every time a tileset has been added
|
|
14
|
+
// https://github.com/iTowns/itowns/issues/2426
|
|
15
|
+
const viewers = {};
|
|
16
|
+
|
|
11
17
|
// Internal instance of GLTFLoader, passed to 3d-tiles-renderer-js to support GLTF 1.0 and 2.0
|
|
12
18
|
// Temporary exported to be used in deprecated B3dmParser
|
|
13
19
|
export const itownsGLTFLoader = new iGLTFLoader();
|
|
14
20
|
itownsGLTFLoader.register(() => new GLTFMeshFeaturesExtension());
|
|
15
21
|
itownsGLTFLoader.register(() => new GLTFStructuralMetadataExtension());
|
|
16
22
|
itownsGLTFLoader.register(() => new GLTFCesiumRTCExtension());
|
|
17
|
-
|
|
18
|
-
// Instantiated by the first tileset. Used to share cache and download and parse queues between tilesets
|
|
19
|
-
let lruCache = null;
|
|
20
|
-
let downloadQueue = null;
|
|
21
|
-
let parseQueue = null;
|
|
22
23
|
export const OGC3DTILES_LAYER_EVENTS = {
|
|
23
24
|
/**
|
|
24
25
|
* Fired when a new root or child tile set is loaded
|
|
@@ -152,8 +153,6 @@ class OGC3DTilesLayer extends GeometryLayer {
|
|
|
152
153
|
}
|
|
153
154
|
this.tilesRenderer.registerPlugin(new ImplicitTilingPlugin());
|
|
154
155
|
this.tilesRenderer.manager.addHandler(/\.gltf$/, itownsGLTFLoader);
|
|
155
|
-
this._setupCacheAndQueues();
|
|
156
|
-
this._setupEvents();
|
|
157
156
|
this.object3d.add(this.tilesRenderer.group);
|
|
158
157
|
|
|
159
158
|
// Add an initialization step that is resolved when the root tileset is loaded (see this._setup below), meaning
|
|
@@ -193,24 +192,26 @@ class OGC3DTilesLayer extends GeometryLayer {
|
|
|
193
192
|
}
|
|
194
193
|
|
|
195
194
|
/**
|
|
196
|
-
* Sets the lruCache and download and parse queues so they are shared amongst
|
|
195
|
+
* Sets the lruCache and download and parse queues so they are shared amongst
|
|
196
|
+
* all tilesets from a same {@link View} view.
|
|
197
|
+
* @param {View} view - view associated to this layer.
|
|
197
198
|
* @private
|
|
198
199
|
*/
|
|
199
|
-
_setupCacheAndQueues() {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
this.tilesRenderer.
|
|
204
|
-
|
|
205
|
-
if (downloadQueue === null) {
|
|
206
|
-
downloadQueue = this.tilesRenderer.downloadQueue;
|
|
200
|
+
_setupCacheAndQueues(view) {
|
|
201
|
+
const id = view.id;
|
|
202
|
+
if (viewers[id]) {
|
|
203
|
+
this.tilesRenderer.lruCache = viewers[id].lruCache;
|
|
204
|
+
this.tilesRenderer.downloadQueue = viewers[id].downloadQueue;
|
|
205
|
+
this.tilesRenderer.parseQueue = viewers[id].parseQueue;
|
|
207
206
|
} else {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
207
|
+
viewers[id] = {
|
|
208
|
+
lruCache: this.tilesRenderer.lruCache,
|
|
209
|
+
downloadQueue: this.tilesRenderer.downloadQueue,
|
|
210
|
+
parseQueue: this.tilesRenderer.parseQueue
|
|
211
|
+
};
|
|
212
|
+
view.addEventListener(VIEW_EVENTS.DISPOSED, evt => {
|
|
213
|
+
delete viewers[evt.target.id];
|
|
214
|
+
});
|
|
214
215
|
}
|
|
215
216
|
}
|
|
216
217
|
|
|
@@ -254,6 +255,9 @@ class OGC3DTilesLayer extends GeometryLayer {
|
|
|
254
255
|
});
|
|
255
256
|
view.notifyChange(this);
|
|
256
257
|
});
|
|
258
|
+
this._setupCacheAndQueues(view);
|
|
259
|
+
this._setupEvents();
|
|
260
|
+
|
|
257
261
|
// Start loading tileset and tiles
|
|
258
262
|
this.tilesRenderer.update();
|
|
259
263
|
}
|