2023西安数博会CIM演示-【前端】-Web
AdaKing88
2023-08-21 bc03b832caa49bbcd2674fe4cae3701b5059bf95
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
 * @module olcs.core.VectorLayerCounterpart
 */
import {unByKey as olObservableUnByKey} from 'ol/Observable.js';
 
 
/**
 * Context for feature conversion.
 * @typedef {Object} OlFeatureToCesiumContext
 * @property {!(import('ol/Projection.js').default|string)} projection
 * @property {!Cesium.PrimitiveCollection} primitives
 * @property {Object<number, Array<!Cesium.Primitive|!Cesium.Billboard>>} featureToCesiumMap
 * @property {!Cesium.BillboardCollection} billboards
 */
 
 
class VectorLayerCounterpart {
  /**
  * Result of the conversion of an OpenLayers layer to Cesium.
  * @param {!(ol.proj.Projection|string)} layerProjection
  * @param {!Cesium.Scene} scene
  */
  constructor(layerProjection, scene) {
    const billboards = new Cesium.BillboardCollection({scene});
    const primitives = new Cesium.PrimitiveCollection();
 
    /**
    * @type {!Array.<ol.EventsKey>}
    */
    this.olListenKeys = [];
 
    this.rootCollection_ = new Cesium.PrimitiveCollection();
    /**
    * @type {!OlFeatureToCesiumContext}
    */
    this.context = {
      projection: layerProjection,
      billboards,
      featureToCesiumMap: {},
      primitives
    };
 
    this.rootCollection_.add(billboards);
    this.rootCollection_.add(primitives);
  }
 
  /**
  * Unlisten.
  */
  destroy() {
    this.olListenKeys.forEach(olObservableUnByKey);
    this.olListenKeys.length = 0;
  }
 
  /**
  * @return {!Cesium.Primitive}
  */
  getRootPrimitive() {
    return this.rootCollection_;
  }
}
 
 
export default VectorLayerCounterpart;