UNPKG

react-vr-geolocate

Version:

69 lines (59 loc) 3.88 kB
Object.defineProperty(exports,"__esModule",{value:true});var _jsxFileName="src\\components\\solar-system\\earthSpin.js";var _createClass=function(){function defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor;};}();var _react=require("react");var _react2=_interopRequireDefault(_react); var _reactVr=require("react-vr"); var _coordinateHelpers=require("../../helpers/coordinateHelpers");function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj};}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _possibleConstructorReturn(self,call){if(!self){throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return call&&(typeof call==="object"||typeof call==="function")?call:self;}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function, not "+typeof superClass);}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,enumerable:false,writable:true,configurable:true}});if(superClass)Object.setPrototypeOf?Object.setPrototypeOf(subClass,superClass):subClass.__proto__=superClass;}var EarthSpin=function(_React$Component){_inherits(EarthSpin,_React$Component); function EarthSpin(props){_classCallCheck(this,EarthSpin);var _this=_possibleConstructorReturn(this,(EarthSpin.__proto__||Object.getPrototypeOf(EarthSpin)).call(this, props)); _this.spin=_this.spin.bind(_this); _this.resetEarthPosition=_this.resetEarthPosition.bind(_this); _this.primeMeridianOffset=_this.props.xOffset||0; _this.equatorOffset=_this.props.yOffset||0; _this.state={ bounceXValue:new _reactVr.Animated.Value(_this.primeMeridianOffset), bounceYValue:new _reactVr.Animated.Value(_this.equatorOffset)};return _this; }_createClass(EarthSpin,[{key:"mapLatitude",value:function mapLatitude( lat){ return lat+this.equatorOffset; }},{key:"mapLongitude",value:function mapLongitude( lon){ return(lon>=0?-lon:Math.abs(lon))+this.primeMeridianOffset; }},{key:"resetEarthPosition",value:function resetEarthPosition( props){ var locationItems=props.locationContent; if(!Array.isArray(locationItems)||locationItems.length<=0){ return false; } var focalPoint=locationItems[0]; if(locationItems.length>=1){ var firstLoc=locationItems[0].coordinates; var lastLoc=locationItems[locationItems.length-1].coordinates; focalPoint=(0,_coordinateHelpers.midpoint)(firstLoc,lastLoc,.5); } this.spin(this.mapLatitude(focalPoint.coordinates.lat),this.mapLongitude(focalPoint.coordinates.lon)); }},{key:"componentWillMount",value:function componentWillMount() { this.resetEarthPosition(this.props); }},{key:"componentWillReceiveProps",value:function componentWillReceiveProps( next){ this.resetEarthPosition(next); }},{key:"spin",value:function spin( lat,lon){ _reactVr.Animated.spring(this.state.bounceXValue,{ toValue:lon, friction:15, tension:4}). start(); _reactVr.Animated.spring(this.state.bounceYValue,{ toValue:lat, friction:15, tension:4}). start(); }},{key:"render",value:function render() { return( _react2.default.createElement(_reactVr.Animated.View,{style:{ transform:[ {rotateX:this.state.bounceYValue}, {rotateY:this.state.bounceXValue}]},__source:{fileName:_jsxFileName,lineNumber:60}}, this.props.children)); }}]);return EarthSpin;}(_react2.default.Component);exports.default=EarthSpin;