yzt
2023-05-26 2f70f6727314edd84d8ec2bfe3ce832803f1ea77
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
import { ModelExperimental, when } from "../../../Source/Cesium.js";
import pollToPromise from "../../pollToPromise.js";
 
function loadAndZoomToModelExperimental(options, scene) {
  var model;
 
  try {
    model = ModelExperimental.fromGltf({
      content: options.content,
      color: options.color,
      gltf: options.gltf,
      show: options.show,
      customShader: options.customShader,
      basePath: options.basePath,
      modelMatrix: options.modelMatrix,
      allowPicking: options.allowPicking,
      upAxis: options.upAxis,
      forwardAxis: options.forwardAxis,
      debugShowBoundingVolume: options.debugShowBoundingVolume,
      featureIdAttributeIndex: options.featureIdAttributeIndex,
      featureIdTextureIndex: options.featureIdTextureIndex,
      incrementallyLoadTextures: options.incrementallyLoadTextures,
    });
  } catch (error) {
    return when.reject(error);
  }
 
  scene.primitives.add(model);
 
  var finished = false;
  var rejected = false;
  model.readyPromise
    .otherwise(function () {
      rejected = true;
    })
    .always(function () {
      finished = true;
    });
 
  return pollToPromise(
    function () {
      scene.renderForSpecs();
      return finished;
    },
    { timeout: 10000 }
  ).then(function () {
    if (rejected) {
      return model.readyPromise;
    }
    scene.camera.flyToBoundingSphere(model.boundingSphere, {
      duration: 0,
      offset: options.offset,
    });
    return model.readyPromise;
  });
}
 
export default loadAndZoomToModelExperimental;