Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
} from 'streetscape.gl';
import {Form} from '@streetscape.gl/monochrome';
import {
XVIZ_CONFIG,
APP_SETTINGS,
MAPBOX_TOKEN,
MAP_STYLE,
XVIZ_STYLE,
CAR,
STYLES
} from './constants';
import {default as XVIZLoaderFactory} from './log-from-factory';
setXVIZConfig(XVIZ_CONFIG);
const TIMEFORMAT_SCALE = getXVIZConfig().TIMESTAMP_FORMAT === 'seconds' ? 1000 : 1;
// Pass through path & parameters to loaders
function buildLoaderOptions() {
const url = new URL(window.location);
// I prefer to work with an object
const params = {};
for (const [k, v] of url.searchParams.entries()) {
if (Number.isNaN(Number.parseFloat(v))) {
params[k] = v;
} else {
params[k] = Number.parseFloat(v);
}
}
const {
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import {setXVIZConfig, getXVIZConfig} from '@xviz/parser';
const defaultXVIZConfig = Object.assign({}, getXVIZConfig());
export function resetXVIZConfigAndSettings() {
setXVIZConfig(defaultXVIZConfig);
}
LogViewer,
PlaybackControl,
StreamSettingsPanel,
MeterWidget,
TrafficLightWidget,
TurnSignalWidget,
XVIZPanel,
VIEW_MODE
} from 'streetscape.gl';
import {Form} from '@streetscape.gl/monochrome';
import {XVIZ_CONFIG, APP_SETTINGS, MAPBOX_TOKEN, MAP_STYLE, XVIZ_STYLE, CAR} from './constants';
setXVIZConfig(XVIZ_CONFIG);
const TIMEFORMAT_SCALE = getXVIZConfig().TIMESTAMP_FORMAT === 'seconds' ? 1000 : 1;
// __IS_STREAMING__ and __IS_LIVE__ are defined in webpack.config.js
const exampleLog = require(__IS_STREAMING__
? './log-from-stream'
: __IS_LIVE__
? './log-from-live'
: './log-from-file').default;
class Example extends PureComponent {
state = {
log: exampleLog,
settings: {
viewMode: 'PERSPECTIVE',
showTooltip: false
}
};
function getSocketRequestParams(options) {
const {
logGuid,
logProfile = DEFAULT_LOG_PROFILE,
duration: requestedDuration,
timestamp,
serverConfig,
bufferLength = DEFAULT_BUFFER_LENGTH[getXVIZConfig().TIMESTAMP_FORMAT],
// These are parent class options we want to filter
maxConcurrency,
WebSocketClass,
...passThroughOptions
} = options;
// set duration overrides & defaults
const duration = requestedDuration || serverConfig.defaultLogLength;
assert(logGuid && duration);
const queryParams = {
...passThroughOptions,
...serverConfig.queryParams,
log: logGuid,
profile: logProfile
_getCurrentFrames(allFrames, currentTime) {
let currentFrame = null;
let currentFrameIndex = -1;
let bestDelta = getXVIZConfig().TIME_WINDOW;
// Find the frame closest to the current timestamp
allFrames.forEach((frame, i) => {
const delta = currentTime - frame.time;
if (delta >= 0 && delta < bestDelta) {
bestDelta = delta;
currentFrame = frame;
currentFrameIndex = i;
}
});
// Load adjacent frames into the buffer
const bufferedFrames =
currentFrameIndex >= 0
? allFrames.slice(Math.max(0, currentFrameIndex - this.size), currentFrameIndex + this.size)
: [];
// dual playback control config
maxLookAhead: PropTypes.number,
formatLookAhead: PropTypes.func,
// callbacks
onPlay: PropTypes.func,
onPause: PropTypes.func,
onSeek: PropTypes.func,
onLookAheadChange: PropTypes.func
};
static defaultProps = DualPlaybackControl.defaultProps;
state = {
isPlaying: false,
timeScale: TIME_SCALES[getXVIZConfig().TIMESTAMP_FORMAT] || 1
};
componentWillReceiveProps(nextProps) {
if ('isPlaying' in nextProps) {
this.setState({isPlaying: Boolean(nextProps.isPlaying)});
}
}
componentDidUpdate(prevProps, prevState) {
const {isPlaying} = this.state;
if (isPlaying && prevState.isPlaying !== isPlaying) {
this._lastAnimationUpdate = Date.now();
this._animationFrame = window.requestAnimationFrame(this._animate);
}
}
test('setXVIZConfig', t => {
const preProcessPrimitive = () => {};
resetXVIZConfigAndSettings();
setXVIZConfig({preProcessPrimitive});
t.is(getXVIZConfig().preProcessPrimitive, preProcessPrimitive, 'XVIZ config is set');
t.deepEquals(getXVIZConfig().supportedVersions, [1, 2], 'XVIZ default config is used');
setXVIZConfig({supportedVersions: [1]});
t.is(
getXVIZConfig().preProcessPrimitive,
preProcessPrimitive,
'XVIZ config preProcessPrimitive is not changed'
);
t.deepEquals(getXVIZConfig().supportedVersions, [1], 'XVIZ config is set');
setXVIZConfig({currentMajorVersion: 2});
t.is(
getXVIZConfig().preProcessPrimitive,
preProcessPrimitive,
'XVIZ config preProcessPrimitive is not changed'
);
setXVIZConfig({supportedVersions: [1]});
t.is(
getXVIZConfig().preProcessPrimitive,
preProcessPrimitive,
'XVIZ config preProcessPrimitive is not changed'
);
t.deepEquals(getXVIZConfig().supportedVersions, [1], 'XVIZ config is set');
setXVIZConfig({currentMajorVersion: 2});
t.is(
getXVIZConfig().preProcessPrimitive,
preProcessPrimitive,
'XVIZ config preProcessPrimitive is not changed'
);
t.is(getXVIZConfig().currentMajorVersion, 2, 'XVIZ config currentMajorVersion is set');
t.end();
});