/** * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author Alexander Rose */ import * as React from 'react' import { App } from '../app'; import { MarkerAction } from 'mol-geo/geometry/marker-data'; import { EmptyLoci, Loci, areLociEqual } from 'mol-model/loci'; import { labelFirst } from 'mol-canvas3d/label'; interface ViewportProps { app: App } interface ViewportState { noWebGl: boolean pickingInfo: string taskInfo: string } export class Viewport extends React.Component { private container: HTMLDivElement | null = null; private canvas: HTMLCanvasElement | null = null; state: ViewportState = { noWebGl: false, pickingInfo: '', taskInfo: '' }; handleResize() { this.props.app.viewer.handleResize() } componentDidMount() { if (!this.canvas || !this.container || !this.props.app.initViewer(this.canvas, this.container)) { this.setState({ noWebGl: true }); } this.handleResize() const viewer = this.props.app.viewer viewer.input.resize.subscribe(() => this.handleResize()) let prevLoci: Loci = EmptyLoci viewer.input.move.subscribe(({x, y, inside, buttons}) => { if (!inside || buttons) return const p = viewer.identify(x, y) if (p) { const loci = viewer.getLoci(p) if (!areLociEqual(loci, prevLoci)) { viewer.mark(prevLoci, MarkerAction.RemoveHighlight) viewer.mark(loci, MarkerAction.Highlight) prevLoci = loci const label = labelFirst(loci) const pickingInfo = `${label}` this.setState({ pickingInfo }) } } }) this.props.app.taskCountChanged.subscribe(({ count, info }) => { this.setState({ taskInfo: count > 0 ? info : '' }) }) } componentWillUnmount() { if (super.componentWillUnmount) super.componentWillUnmount(); // TODO viewer cleanup } renderMissing() { return

WebGL does not seem to be available.

This can be caused by an outdated browser, graphics card driver issue, or bad weather. Sometimes, just restarting the browser helps.

For a list of supported browsers, refer to http://caniuse.com/#feat=webgl.

} render() { if (this.state.noWebGl) return this.renderMissing(); return
this.container = elm} style={{width: '100%', height: '100%'}}> this.canvas = elm}>
{this.state.pickingInfo}
{ this.state.taskInfo ?
{this.state.taskInfo}
: '' }
; } }