yzt
2023-05-08 24e1c6a1c3d5331b5a4f1111dcbae3ef148eda1a
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
import {
  PropertyTexture,
  MetadataClass,
  PixelDatatype,
  PixelFormat,
  Texture,
} from "../../Source/Cesium.js";
import createContext from "../createContext.js";
 
describe("Scene/PropertyTexture", function () {
  var classDefinition;
  var context;
  var texture0;
  var texture1;
  var extras;
  var extensions;
  var featureTexture;
 
  beforeAll(function () {
    classDefinition = new MetadataClass({
      id: "map",
      class: {
        properties: {
          color: {
            type: "ARRAY",
            componentType: "UINT8",
            componentCount: 3,
          },
          intensity: {
            type: "UINT8",
          },
          ortho: {
            type: "UINT8",
            normalized: true,
          },
        },
      },
    });
 
    context = createContext();
 
    texture0 = new Texture({
      context: context,
      pixelFormat: PixelFormat.RGBA,
      pixelDatatype: PixelDatatype.UNSIGNED_BYTE,
      source: {
        arrayBufferView: new Uint8Array([1, 2, 3, 4]),
        width: 1,
        height: 1,
      },
    });
 
    texture1 = new Texture({
      context: context,
      pixelFormat: PixelFormat.LUMINANCE,
      pixelDatatype: PixelDatatype.UNSIGNED_BYTE,
      source: {
        arrayBufferView: new Uint8Array([5]),
        width: 1,
        height: 1,
      },
    });
 
    extras = {
      description: "Extra",
    };
 
    extensions = {
      EXT_other_extension: {},
    };
 
    var featureTextureJson = {
      class: "map",
      extras: extras,
      extensions: extensions,
      properties: {
        color: {
          channels: "rgb",
          texture: {
            index: 0,
            texCoord: 0,
          },
        },
        intensity: {
          channels: "a",
          texture: {
            index: 0,
            texCoord: 0,
          },
        },
        ortho: {
          channels: "r",
          texture: {
            index: 1,
            texCoord: 0,
          },
        },
      },
    };
 
    featureTexture = new PropertyTexture({
      featureTexture: featureTextureJson,
      class: classDefinition,
      textures: {
        0: texture0,
        1: texture1,
      },
    });
  });
 
  afterAll(function () {
    texture0.destroy();
    texture1.destroy();
    context.destroyForSpecs();
  });
 
  it("creates feature texture", function () {
    expect(featureTexture.class).toBe(classDefinition);
    expect(featureTexture.extras).toBe(extras);
    expect(featureTexture.extensions).toBe(extensions);
  });
 
  it("constructor throws without featureTexture", function () {
    expect(function () {
      return new PropertyTexture({
        class: classDefinition,
        textures: {},
      });
    }).toThrowDeveloperError();
  });
 
  it("constructor throws without class", function () {
    expect(function () {
      return new PropertyTexture({
        featureTexture: {},
        textures: {},
      });
    }).toThrowDeveloperError();
  });
 
  it("constructor throws without textures", function () {
    expect(function () {
      return new PropertyTexture({
        featureTexture: {},
        class: classDefinition,
      });
    }).toThrowDeveloperError();
  });
 
  it("getProperty returns feature texture property", function () {
    expect(featureTexture.getProperty("color")).toBeDefined();
    expect(featureTexture.getProperty("intensity")).toBeDefined();
    expect(featureTexture.getProperty("ortho")).toBeDefined();
  });
 
  it("getProperty returns undefined if the property doesn't exist", function () {
    expect(featureTexture.getProperty("other")).toBeUndefined();
  });
 
  it("getProperty throws if propertyId is undefined", function () {
    expect(function () {
      featureTexture.getProperty(undefined);
    }).toThrowDeveloperError();
  });
});