1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
const Temperature3DLayer = BaseElevationLayer.createSubclass({
properties: {
// exaggerates the temps by 80000x so we can see// variation at large scalesexaggeration: 80000 },
load: function() {
// load ImageryLayer containing temperature values// See the code in the sandbox for details about// createTemperatureLayer()this._temperature = createTemperatureLayer(depth, tempDate, "lerc");
this.addResolvingPromise(this._temperature.load());
}
});
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
fetchTile: function(level, row, col, options) {
const bounds = this.getTileBounds(level, row, col);
// Add one because of overlapping vertices in neighboring tilesconst tileSize = this.tileInfo.size[0] + 1;
const extent = new Extent({
xmin: bounds[0],
ymin: bounds[1],
xmax: bounds[2],
ymax: bounds[3],
spatialReference: this.spatialReference
});
const factor = this.factor;
// fetch the image representing temperature for the extent of the tile.// this method returns the pixel data of the image for the extent// of the given elevation tilereturnthis._temperature.fetchImage(extent, tileSize, tileSize, options)
.then((data) => {
const pixelBlock = data.pixelData.pixelBlock;
// contains the temperature values of each pixel in the imageconst elevations = pixelBlock.pixels[0];
const stats = pixelBlock.statistics[0];
// pixels that don't contain any temperature valuesconst noDataValue = stats.noDataValue;
elevations.forEach((value, index, pixelData) => {
if (value !== noDataValue) {
// multiply temperatures by the given factor pixelData[index] = value * factor;
}
else {
// areas with no temperature data (land)// will be assigned the average sea surface// temperature (17 degrees Celsius) pixelData[index] = 17*factor;
}
});
// return the modified temperatures as elevationsreturn {
values: elevations,
width: pixelBlock.width,
height: pixelBlock.height,
noDataValue: noDataValue
};
});
}