I have been attempting to use the code found here https://github.com/TerriaJS/terriajs/blob/master/lib/Map/EarthGravityModel1996.js
to get MSL elevation values for locations on the globe.
However, when the code attempts to create a new Int16Array after swapping the byte order of the array buffer an error is thrown. The error is occurring in the try/catch below:
function getHeightData(model) {
if (!Cesium.defined(model.data)) {
model.data = Cesium.Resource.fetchArrayBuffer(model.gridFileUrl);
}
return Cesium.when(model.data, function(data) {
if (!(model.data instanceof Int16Array)) {
// Data file is big-endian, all relevant platforms are little endian, so swap the byte order.
var byteView = new Uint8Array(data);
for (var k = 0; k < byteView.length; k += 2) {
var tmp = byteView[k];
byteView[k] = byteView[k + 1];
byteView[k + 1] = tmp;
}
try {
model.data = new Int16Array(data);
}
catch (ex) {
console.log("getHeightData Error: " + ex.toString());
}
}
return model.data;
});
}
``
The error states: “RangeError: byte length of Int16Array should be a multiple of 2”
I also get the same error if I attempt to create a new Int16Array without swapping the byte order.
I have downloaded the WW15MGH.DAC file from several different sources (including TerriaJS), and the file looks identical from each source. So I don’t think the file is the issue.
Is there something obvious I’m missing? I’d really like to be able to read MSL elevation from Cesium.