| 9 | import { _ } from 'webodm/classes/gettext'; |
| 10 | |
| 11 | export default class ObjDetectPanel extends React.Component { |
| 12 | static defaultProps = { |
| 13 | }; |
| 14 | static propTypes = { |
| 15 | onClose: PropTypes.func.isRequired, |
| 16 | tasks: PropTypes.object.isRequired, |
| 17 | isShowed: PropTypes.bool.isRequired, |
| 18 | map: PropTypes.object.isRequired |
| 19 | } |
| 20 | |
| 21 | constructor(props){ |
| 22 | super(props); |
| 23 | |
| 24 | this.state = { |
| 25 | error: "", |
| 26 | permanentError: "", |
| 27 | model: Storage.getItem("last_objdetect_model") || "cars", |
| 28 | loading: true, |
| 29 | task: props.tasks[0] || null, |
| 30 | detecting: false, |
| 31 | progress: null, |
| 32 | objLayer: null, |
| 33 | }; |
| 34 | } |
| 35 | |
| 36 | componentDidMount(){ |
| 37 | } |
| 38 | |
| 39 | componentDidUpdate(){ |
| 40 | if (this.props.isShowed && this.state.loading){ |
| 41 | const {id, project} = this.state.task; |
| 42 | |
| 43 | this.loadingReq = $.getJSON(`/api/projects/${project}/tasks/${id}/`) |
| 44 | .done(res => { |
| 45 | const { available_assets } = res; |
| 46 | if (available_assets.indexOf("orthophoto.tif") === -1){ |
| 47 | this.setState({permanentError: _("No orthophoto is available. To use object detection you need an orthophoto.")}); |
| 48 | } |
| 49 | }) |
| 50 | .fail(() => { |
| 51 | this.setState({permanentError: _("Cannot retrieve information for task. Are you are connected to the internet?")}) |
| 52 | }) |
| 53 | .always(() => { |
| 54 | this.setState({loading: false}); |
| 55 | this.loadingReq = null; |
| 56 | }); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | componentWillUnmount(){ |
| 61 | if (this.loadingReq){ |
| 62 | this.loadingReq.abort(); |
| 63 | this.loadingReq = null; |
| 64 | } |
| 65 | if (this.detectReq){ |
| 66 | this.detectReq.abort(); |
| 67 | this.detectReq = null; |
| 68 | } |