15832144755
2022-01-06 7b4c8991dca9cf2a809a95e239d144697d3afb56
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
import {
  Cartesian3,
  Cartesian4,
  Cesium3DTileFeature,
  Ellipsoid,
  HeadingPitchRange,
  Math as CesiumMath,
  Rectangle,
} from "../../Source/Cesium.js";
import Cesium3DTilesTester from "../Cesium3DTilesTester.js";
import createScene from "../createScene.js";
 
describe(
  "Scene/Cesium3DTileFeature",
  function () {
    describe("polylinePositions", function () {
      var vectorPolylinesWithBatchIds =
        "./Data/Cesium3DTiles/Vector/VectorTilePolylinesWithBatchIds/tileset.json";
      var b3dmWithBatchIds =
        "Data/Cesium3DTiles/Batched/BatchedWithBatchTable/tileset.json";
 
      var scene;
      beforeAll(function () {
        scene = createScene();
      });
 
      afterAll(function () {
        scene.destroyForSpecs();
      });
 
      beforeEach(function () {
        scene.primitives.removeAll();
      });
 
      it("polylinePositions gets positions for polyline vector data", function () {
        var tilesetRectangle = Rectangle.fromDegrees(-0.01, -0.01, 0.01, 0.01);
        var ellipsoid = Ellipsoid.WGS84;
        scene.camera.lookAt(
          ellipsoid.cartographicToCartesian(Rectangle.center(tilesetRectangle)),
          new Cartesian3(0.0, 0.0, 0.01)
        );
        return Cesium3DTilesTester.loadTileset(
          scene,
          vectorPolylinesWithBatchIds,
          {
            vectorKeepDecodedPositions: true,
          }
        ).then(function (tileset) {
          var feature = tileset.root.content.getFeature(0);
          var polylinePositions = feature.polylinePositions;
          expect(polylinePositions.length).toBe(60);
          expect(polylinePositions[0]).toEqualEpsilon(
            6378136.806372941,
            CesiumMath.EPSILON7
          );
          expect(polylinePositions[1]).toEqualEpsilon(
            -1113.194885441724,
            CesiumMath.EPSILON7
          );
          expect(polylinePositions[2]).toEqualEpsilon(
            1105.675261474196,
            CesiumMath.EPSILON7
          );
        });
      });
 
      it("polylinePositions returns undefined for non polyline features", function () {
        var centerLongitude = -1.31968;
        var centerLatitude = 0.698874;
        var center = Cartesian3.fromRadians(centerLongitude, centerLatitude);
        scene.camera.lookAt(center, new HeadingPitchRange(0.0, -1.57, 15.0));
 
        return Cesium3DTilesTester.loadTileset(scene, b3dmWithBatchIds, {
          vectorKeepDecodedPositions: true,
        }).then(function (tileset) {
          var feature = tileset.root.content.getFeature(0);
          var polylinePositions = feature.polylinePositions;
          expect(polylinePositions).toBeUndefined();
        });
      });
    });
 
    describe("3DTILES_metadata", function () {
      var tilesetWithMetadataUrl =
        "Data/Cesium3DTiles/Metadata/AllMetadataTypes/tileset.json";
 
      var centerLongitude = -1.31968;
      var centerLatitude = 0.698874;
 
      var scene;
      var tileset;
      beforeAll(function () {
        scene = createScene();
 
        var center = Cartesian3.fromRadians(centerLongitude, centerLatitude);
        scene.camera.lookAt(center, new HeadingPitchRange(0.0, -1.57, 15.0));
 
        return Cesium3DTilesTester.loadTileset(
          scene,
          tilesetWithMetadataUrl
        ).then(function (result) {
          tileset = result;
        });
      });
 
      afterAll(function () {
        scene.destroyForSpecs();
      });
 
      var parentContent;
      var childContents = {};
      beforeEach(function () {
        parentContent = tileset.root.content;
        var children = tileset.root.children;
 
        children.forEach(function (child) {
          var uri = child._header.content.uri;
          childContents[uri] = child.content;
        });
      });
 
      it("getPropertyInherited returns undefined for unknown property", function () {
        var feature = new Cesium3DTileFeature(childContents["ll.b3dm"], 0);
        expect(feature.getPropertyInherited("unknown")).not.toBeDefined();
      });
 
      it("getPropertyInherited returns tile property by semantic", function () {
        var feature = new Cesium3DTileFeature(childContents["ll.b3dm"], 0);
        expect(feature.getPropertyInherited("COLOR")).toEqual(
          new Cartesian4(255, 255, 0, 1.0)
        );
      });
 
      it("getPropertyInherited returns tile property", function () {
        var feature = new Cesium3DTileFeature(childContents["ll.b3dm"], 0);
        expect(feature.getPropertyInherited("color")).toEqual(
          new Cartesian4(255, 255, 0, 1.0)
        );
        expect(feature.getPropertyInherited("population")).toBe(50);
      });
 
      it("getPropertyInherited returns group property by semantic", function () {
        var feature = new Cesium3DTileFeature(childContents["lr.b3dm"], 0);
        expect(feature.getPropertyInherited("GROUP_NAME")).toBe("commercial");
        feature = new Cesium3DTileFeature(childContents["ll.b3dm"], 0);
        expect(feature.getPropertyInherited("GROUP_NAME")).toBe("residential");
      });
 
      it("getPropertyInherited returns group property", function () {
        var feature = new Cesium3DTileFeature(childContents["lr.b3dm"], 0);
        expect(feature.getPropertyInherited("majorIndustries")).toEqual([
          "Finance",
          "Manufacturing",
        ]);
        expect(feature.getPropertyInherited("businessCount")).toBe(143);
      });
 
      it("getPropertyInherited returns tileset property by semantic", function () {
        var feature = new Cesium3DTileFeature(parentContent, 0);
        expect(feature.getPropertyInherited("COLOR")).toEqual(
          new Cartesian4(255, 0, 255, 1.0)
        );
        expect(feature.getPropertyInherited("DATE_ISO_8601")).toBe(
          "2021-04-07"
        );
        expect(feature.getPropertyInherited("AUTHOR")).toBe("Cesium");
      });
 
      it("getPropertyInherited returns tileset property", function () {
        var feature = new Cesium3DTileFeature(parentContent, 0);
        expect(feature.getPropertyInherited("color")).toEqual(
          new Cartesian4(255, 0, 255, 1.0)
        );
        expect(feature.getPropertyInherited("centerCartographic")).toEqual(
          new Cartesian3(
            -1.3196816996258511,
            0.6988767486400521,
            45.78600543644279
          )
        );
        expect(feature.getPropertyInherited("date")).toBe("2021-04-07");
        expect(feature.getPropertyInherited("author")).toBe("Cesium");
        expect(feature.getPropertyInherited("tileCount")).toBe(5);
      });
 
      it("resolves conflicting names from most specific to most general", function () {
        // tile metadata is more specific than tileset metadata so this returns
        // yellow not magenta
        var feature = new Cesium3DTileFeature(childContents["ll.b3dm"], 0);
        expect(feature.getPropertyInherited("color")).toEqual(
          new Cartesian4(255, 255, 0, 1.0)
        );
 
        // group metadata is more specific than tileset metadata, so this returns
        // 2 not 5
        expect(feature.getPropertyInherited("tileCount")).toEqual(2);
      });
    });
  },
  "WebGL"
);