mirror of
https://github.com/overte-org/overte.git
synced 2025-04-08 14:12:50 +02:00
initial live earthqukes commit
This commit is contained in:
parent
2ace061893
commit
3b6cd4c2d1
3 changed files with 1481 additions and 0 deletions
173
examples/data_visualization/earthquakes_live.js
Normal file
173
examples/data_visualization/earthquakes_live.js
Normal file
|
@ -0,0 +1,173 @@
|
|||
//earthquakes_live.js
|
||||
//created by james b. pollack @imgntn on 12/5/2015
|
||||
Script.include('../libraries/promise.js');
|
||||
var Promise = loadPromise();
|
||||
|
||||
Script.include('../libraries/tinyColor.js');
|
||||
var tinyColor = loadTinyColor();
|
||||
|
||||
var EARTH_SPHERE_RADIUS = 5;
|
||||
var EARTH_CENTER_POSITION = Vec3.sum(MyAvatar.position, {
|
||||
x: 5,
|
||||
y: 0,
|
||||
z: 0
|
||||
});
|
||||
|
||||
var EARTH_MODEL_URL='http://public.highfidelity.io/marketplace/hificontent/Scripts/planets/planets/earth.fbx';
|
||||
//USGS updates the data every five minutes
|
||||
var CHECK_QUAKE_FREQUENCY = 300 * 1000;
|
||||
|
||||
var QUAKE_MARKER_DIMENSIONS = {
|
||||
x: 0.1,
|
||||
y: 0.1,
|
||||
z: 0.1
|
||||
};
|
||||
|
||||
function createEarth() {
|
||||
var earthProperties = {
|
||||
name: 'Earth',
|
||||
type: 'Model',
|
||||
modelURL:EARTH_MODEL_URL,
|
||||
position: EARTH_CENTER_POSITION,
|
||||
dimensions: {
|
||||
x: EARTH_SPHERE_RADIUS,
|
||||
y: EARTH_SPHERE_RADIUS,
|
||||
z: EARTH_SPHERE_RADIUS
|
||||
},
|
||||
// color: {
|
||||
// red: 0,
|
||||
// green: 100,
|
||||
// blue: 150
|
||||
// },
|
||||
collisionsWillMove: false,
|
||||
userData: JSON.stringify({
|
||||
grabbableKey: {
|
||||
grabbable: false
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
return Entities.addEntity(earthProperties)
|
||||
}
|
||||
|
||||
function plotLatitudeLongitude(radiusOfSphere, latitude, longitude) {
|
||||
var tx = radiusOfSphere * Math.cos(latitude) * Math.cos(longitude);
|
||||
var ty = radiusOfSphere * -Math.sin(latitude);
|
||||
var tz = radiusOfSphere * Math.cos(latitude) * Math.sin(longitude);
|
||||
return {
|
||||
x: tx,
|
||||
y: ty,
|
||||
z: tz
|
||||
}
|
||||
}
|
||||
|
||||
function getQuakePosition(earthquake) {
|
||||
var latitude = earthquake.geometry.coordinates[0];
|
||||
var longitude = earthquake.geometry.coordinates[1];
|
||||
var latlng = plotLatitudeLongitude(2.5, latitude, longitude);
|
||||
|
||||
var position = EARTH_CENTER_POSITION;
|
||||
var finalPosition = Vec3.sum(position, latlng);
|
||||
|
||||
// print('finalpos::' + JSON.stringify(finalPosition))
|
||||
return finalPosition
|
||||
}
|
||||
|
||||
var QUAKE_URL = 'http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_day.geojson'
|
||||
|
||||
function get(url) {
|
||||
print('getting' + url)
|
||||
// Return a new promise.
|
||||
return new Promise(function(resolve, reject) {
|
||||
// Do the usual XHR stuff
|
||||
var req = new XMLHttpRequest();
|
||||
req.open('GET', url);
|
||||
req.onreadystatechange = function() {
|
||||
print('req status:: ' + JSON.stringify(req.status))
|
||||
|
||||
if (req.readyState == 4 && req.status == 200) {
|
||||
var myArr = JSON.parse(req.responseText);
|
||||
resolve(myArr);
|
||||
}
|
||||
};
|
||||
|
||||
req.send();
|
||||
});
|
||||
}
|
||||
|
||||
function showEarthquake(snapshot) {
|
||||
var earthquake = snapshot.val();
|
||||
print("Mag " + earthquake.mag + " at " + earthquake.place);
|
||||
}
|
||||
|
||||
function createQuakeMarker(earthquake) {
|
||||
var markerProperties = {
|
||||
name: 'Marker',
|
||||
type: 'Sphere',
|
||||
dimensions: QUAKE_MARKER_DIMENSIONS,
|
||||
position: getQuakePosition(earthquake),
|
||||
lifetime: 6000,
|
||||
color: getQuakeMarkerColor(earthquake)
|
||||
}
|
||||
|
||||
//print('marker properties::' + JSON.stringify(markerProperties))
|
||||
return Entities.addEntity(markerProperties);
|
||||
}
|
||||
|
||||
function getQuakeMarkerColor(earthquake) {
|
||||
var color = {};
|
||||
var magnitude = earthquake.properties.mag;
|
||||
//realistic but will never get full red coloring and will probably be pretty dull for most. must experiment
|
||||
var sValue = scale(magnitude, 0, 10, 0, 100);
|
||||
var HSL_string = "hsl(0, " + sValue + "%, 50%)"
|
||||
var color = tinyColor(HSL_string);
|
||||
var finalColor = {
|
||||
red: color._r,
|
||||
green: color._g,
|
||||
blue: color._b
|
||||
}
|
||||
|
||||
return finalColor
|
||||
}
|
||||
|
||||
function scale(value, min1, max1, min2, max2) {
|
||||
return min2 + (max2 - min2) * ((value - min1) / (max1 - min1));
|
||||
}
|
||||
|
||||
function processQuakes(earthquakes) {
|
||||
print('quakers length' + earthquakes.length)
|
||||
earthquakes.forEach(function(quake) {
|
||||
// print('PROCESSING A QUAKE')
|
||||
var marker = createQuakeMarker(quake);
|
||||
markers.push(marker);
|
||||
})
|
||||
print('markers length:' + markers.length)
|
||||
}
|
||||
|
||||
var quakea;
|
||||
var markers = [];
|
||||
|
||||
var earth = createEarth();
|
||||
|
||||
get(QUAKE_URL).then(function(response) {
|
||||
print('got it::' + response.features.length)
|
||||
quakes = response.features;
|
||||
processQuakes(quakes);
|
||||
//print("Success!" + JSON.stringify(response));
|
||||
}, function(error) {
|
||||
print('error getting quakes')
|
||||
});
|
||||
|
||||
function cleanupMarkers() {
|
||||
print('CLEANING UP MARKERS')
|
||||
while (markers.length > 0) {
|
||||
Entities.deleteEntity(markers.pop());
|
||||
}
|
||||
}
|
||||
|
||||
function cleanupEarth() {
|
||||
Entities.deleteEntity(earth);
|
||||
}
|
||||
|
||||
Script.scriptEnding.connect(cleanupMarkers);
|
||||
Script.scriptEnding.connect(cleanupEarth);
|
153
examples/data_visualization/testQuakes.json
Normal file
153
examples/data_visualization/testQuakes.json
Normal file
|
@ -0,0 +1,153 @@
|
|||
{
|
||||
"type": "FeatureCollection",
|
||||
"metadata": {
|
||||
"generated": 1449347736000,
|
||||
"url": "http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_hour.geojson",
|
||||
"title": "USGS All Earthquakes, Past Hour",
|
||||
"status": 200,
|
||||
"api": "1.1.0",
|
||||
"count": 4
|
||||
},
|
||||
"features": [{
|
||||
"type": "Feature",
|
||||
"properties": {
|
||||
"mag": 1.39,
|
||||
"place": "17km ESE of Julian, California",
|
||||
"time": 1449345604050,
|
||||
"updated": 1449345856673,
|
||||
"tz": -480,
|
||||
"url": "http://earthquake.usgs.gov/earthquakes/eventpage/ci37498832",
|
||||
"detail": "http://earthquake.usgs.gov/earthquakes/feed/v1.0/detail/ci37498832.geojson",
|
||||
"felt": null,
|
||||
"cdi": null,
|
||||
"mmi": null,
|
||||
"alert": null,
|
||||
"status": "automatic",
|
||||
"tsunami": 0,
|
||||
"sig": 30,
|
||||
"net": "ci",
|
||||
"code": "37498832",
|
||||
"ids": ",ci37498832,",
|
||||
"sources": ",ci,",
|
||||
"types": ",general-link,geoserve,nearby-cities,origin,phase-data,",
|
||||
"nst": 32,
|
||||
"dmin": 0.1379,
|
||||
"rms": 0.21,
|
||||
"gap": 68,
|
||||
"magType": "ml",
|
||||
"type": "earthquake",
|
||||
"title": "M 1.4 - 17km ESE of Julian, California"
|
||||
},
|
||||
"geometry": {
|
||||
"type": "Point",
|
||||
"coordinates": [-116.4293333, 33.0301667, 7.84]
|
||||
},
|
||||
"id": "ci37498832"
|
||||
}, {
|
||||
"type": "Feature",
|
||||
"properties": {
|
||||
"mag": 1.12,
|
||||
"place": "3km ESE of The Geysers, California",
|
||||
"time": 1449344686690,
|
||||
"updated": 1449344783260,
|
||||
"tz": -480,
|
||||
"url": "http://earthquake.usgs.gov/earthquakes/eventpage/nc72564866",
|
||||
"detail": "http://earthquake.usgs.gov/earthquakes/feed/v1.0/detail/nc72564866.geojson",
|
||||
"felt": null,
|
||||
"cdi": null,
|
||||
"mmi": null,
|
||||
"alert": null,
|
||||
"status": "automatic",
|
||||
"tsunami": 0,
|
||||
"sig": 19,
|
||||
"net": "nc",
|
||||
"code": "72564866",
|
||||
"ids": ",nc72564866,",
|
||||
"sources": ",nc,",
|
||||
"types": ",general-link,geoserve,nearby-cities,origin,phase-data,",
|
||||
"nst": 11,
|
||||
"dmin": 0.01342,
|
||||
"rms": 0.03,
|
||||
"gap": 154,
|
||||
"magType": "md",
|
||||
"type": "earthquake",
|
||||
"title": "M 1.1 - 3km ESE of The Geysers, California"
|
||||
},
|
||||
"geometry": {
|
||||
"type": "Point",
|
||||
"coordinates": [-122.7176666, 38.7598343, 1.48]
|
||||
},
|
||||
"id": "nc72564866"
|
||||
}, {
|
||||
"type": "Feature",
|
||||
"properties": {
|
||||
"mag": 1.99,
|
||||
"place": "3km SE of The Geysers, California",
|
||||
"time": 1449344287500,
|
||||
"updated": 1449344383210,
|
||||
"tz": -480,
|
||||
"url": "http://earthquake.usgs.gov/earthquakes/eventpage/nc72564856",
|
||||
"detail": "http://earthquake.usgs.gov/earthquakes/feed/v1.0/detail/nc72564856.geojson",
|
||||
"felt": null,
|
||||
"cdi": null,
|
||||
"mmi": null,
|
||||
"alert": null,
|
||||
"status": "automatic",
|
||||
"tsunami": 0,
|
||||
"sig": 61,
|
||||
"net": "nc",
|
||||
"code": "72564856",
|
||||
"ids": ",nc72564856,",
|
||||
"sources": ",nc,",
|
||||
"types": ",general-link,geoserve,nearby-cities,origin,phase-data,",
|
||||
"nst": 13,
|
||||
"dmin": 0.01626,
|
||||
"rms": 0.02,
|
||||
"gap": 72,
|
||||
"magType": "md",
|
||||
"type": "earthquake",
|
||||
"title": "M 2.0 - 3km SE of The Geysers, California"
|
||||
},
|
||||
"geometry": {
|
||||
"type": "Point",
|
||||
"coordinates": [-122.7203369, 38.7571678, 0.3]
|
||||
},
|
||||
"id": "nc72564856"
|
||||
}, {
|
||||
"type": "Feature",
|
||||
"properties": {
|
||||
"mag": 2.36,
|
||||
"place": "3km ESE of The Geysers, California",
|
||||
"time": 1449344196380,
|
||||
"updated": 1449344459434,
|
||||
"tz": -480,
|
||||
"url": "http://earthquake.usgs.gov/earthquakes/eventpage/nc72564836",
|
||||
"detail": "http://earthquake.usgs.gov/earthquakes/feed/v1.0/detail/nc72564836.geojson",
|
||||
"felt": 0,
|
||||
"cdi": 1,
|
||||
"mmi": null,
|
||||
"alert": null,
|
||||
"status": "automatic",
|
||||
"tsunami": 0,
|
||||
"sig": 86,
|
||||
"net": "nc",
|
||||
"code": "72564836",
|
||||
"ids": ",nc72564836,",
|
||||
"sources": ",nc,",
|
||||
"types": ",dyfi,focal-mechanism,general-link,geoserve,nearby-cities,origin,phase-data,scitech-link,",
|
||||
"nst": 36,
|
||||
"dmin": 0.01395,
|
||||
"rms": 0.07,
|
||||
"gap": 38,
|
||||
"magType": "md",
|
||||
"type": "earthquake",
|
||||
"title": "M 2.4 - 3km ESE of The Geysers, California"
|
||||
},
|
||||
"geometry": {
|
||||
"type": "Point",
|
||||
"coordinates": [-122.722168, 38.7598343, 1.21]
|
||||
},
|
||||
"id": "nc72564836"
|
||||
}],
|
||||
"bbox": [-122.722168, 33.0301667, 0.3, -116.4293333, 38.7598343, 7.84]
|
||||
}
|
1155
examples/libraries/tinyColor.js
Normal file
1155
examples/libraries/tinyColor.js
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue