Skip to content

Instantly share code, notes, and snippets.

@jgravois
Created January 10, 2017 20:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jgravois/2af34ac193a72977726d0ba65c366f5b to your computer and use it in GitHub Desktop.
Save jgravois/2af34ac193a72977726d0ba65c366f5b to your computer and use it in GitHub Desktop.
use lerc in node
var http = require('http');
var request = require('request');
var Lerc = require('./LercDecode');
http.get('http://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer/tile/0/0/0', function (res) {
var data = [];
res.on('data', function (chunk) {
data.push(chunk);
})
res.on('end', function () {
data = Buffer.concat(data);
// <Buffer 43 6e 74 5a 49 6d 61 67 65 20 0b 00 00 00 08 00 00 00 01 01 00 00 01 01 00 00 9a 99 99 99 99 99 b9 3f 00 00 00 00 00 00 00 00 24 06 00 00 00 00 80 3f ... >
console.log(data);
// ArrayBuffer {}
console.log(data.buffer);
Lerc.decode(data.buffer);
})
})
request('https://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer/tile/0/0/0', function (error, response, body) {
if (!error && response.statusCode == 200) {
// no clue
// console.log(Lerc.decode(data.buffer));
// node buffer
// var b = new Buffer(body);
// ArrayBuffer http://stackoverflow.com/questions/8609289/convert-a-binary-nodejs-buffer-to-javascript-arraybuffer/31394257#31394257
// var ab = b.buffer.slice(b.byteOffset, b.byteOffset + b.byteLength);
// var c = new ArrayBuffer(body);
// var d = new UInt8Array(c);
// d.set(_another_u8_byte_array);
// console.log(Buffer(body));
// var ab = new ArrayBuffer(Buffer(body));
// console.log(ab.buffer);
//console.log(data);
// var c = new ArrayBuffer(data.length);
// console.log(c);
//Lerc.decode(data);
}
});
@jgravois
Copy link
Author

couldn't make enough sense of the doc below to be successful with request

https://nodejs.org/api/buffer.html#buffer_class_method_buffer_from_buffer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment