Created
March 9, 2022 16:41
-
-
Save datadavev/286f76f073eca289c493c3bfeac2409c to your computer and use it in GitHub Desktop.
Streaming 500k points from isamples to Cesium
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const sc = document.createElement("script"); | |
sc.type="module"; | |
sc.onload = showData; | |
sc.src="https://unpkg.com/[email protected]/dist/oboe-browser.js"; | |
document.head.appendChild(sc); | |
const serviceEndpoint = "https://mars.cyverse.org/"; | |
function pointStream(params={}, perdoc_cb=null, finaldoc_cb=null, error_cb=null) { | |
const fields = params.fields || [ ]; | |
delete params.fields; | |
const fq = params.fq || []; | |
delete params.fq; | |
const sorters = params.sorters || []; | |
delete params.sorters; | |
params.q = params.q || "*:*"; | |
params.wt = params.wt || "json"; | |
params.df = params.df || "searchText"; | |
if (params.q == "") { | |
params.q = this.defaultQuery; | |
} | |
let _url = new URL("/thing/stream", serviceEndpoint); | |
let _params = _url.searchParams; | |
for (let key in params) { | |
_params.append(key, params[key]); | |
} | |
fq.forEach(_fq => _params.append("fq", _fq)); | |
_params.append("fl", fields.join(",")); | |
sorters.forEach(_srt => _params.append("sort", _srt.field+" "+_srt.dir)) | |
oboe( _url.toString() ) | |
.node('docs.*', (doc) => { | |
if (perdoc_cb !== null) { | |
perdoc_cb(doc); | |
} | |
return oboe.drop; | |
}) | |
.done( (finalJson) => { | |
if (finaldoc_cb !== null) { | |
finaldoc_cb(finalJson); | |
} | |
}) | |
.fail( (err) => { | |
if (error_cb !=null) { | |
error_cb(err) | |
} else { | |
console.error(err); | |
} | |
}) | |
} | |
var viewer = new Cesium.Viewer('cesiumContainer'); | |
var scene = viewer.scene; | |
scene.debugShowFramesPerSecond = true; | |
async function showData() { | |
const params = { | |
q:"-source:SESAR", | |
rows: 500000 | |
}; | |
var points = scene.primitives.add(new Cesium.PointPrimitiveCollection()); | |
pointStream(params, (doc) => { | |
if (doc.hasOwnProperty("x")) { | |
points.add({ | |
position: Cesium.Cartesian3.fromDegrees(doc.x, doc.y, 1), | |
pixelSize: 8 | |
}); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment