meta-client
Version:
redefining space
82 lines (68 loc) • 1.78 kB
JavaScript
import * as LOCATOR from 'geolocator';
LOCATOR.config({
language: "en",
google: {
version: "3",
key: "AIzaSyCvpVRTh5o3g6yBY-i8IcqTb5hxn45P52U"
}
});
let DEFAULT = {};
DEFAULT.position = {};
DEFAULT.position.locator = {
enableHighAccuracy: true,
timeout: 5000,
maximumWait: 10000, // max wait time for desired accuracy
maximumAge: 0, // disable cache
desiredAccuracy: 30, // meters
fallbackToIP: true, // fallback to IP if Geolocation fails or rejected
addressLookup: true, // requires Google API key if true
timezone: true // map image URL (boolean or options object)
};
DEFAULT.position.startup = false;
class Human {
constructor(WORLD){
let that = this;
this.events = {};
this.position = {
local:{},
space:{
x:0,
y:0,
z:0
}
};
this.locator = LOCATOR;
}
on(eventName, callback){
if(this.events[eventName]){
this.events[eventName].push(callback);
}else{
this.events[eventName] = [callback];
}
}
go(eventName, ...rest){
if(this.events[eventName]){
this.events[eventName].forEach(cb =>{
cb(...rest);
})
}
}
locate(){}
set(position){
if(position.local){
if(position.local.latitude)
this.position.local.latitude = position.local.latitude;
if(position.local.longitude)
this.position.local.longitude = position.local.longitude;
}
if(position.space){
if(position.space.x)
this.position.space.x = position.space.x;
if(position.space.y)
this.position.space.y = position.space.y;
if(position.space.x)
this.position.space.z = position.space.z;
}
}
}
export default Human;