import React from 'react'; import PropTypes from 'prop-types'; import Storage from 'webodm/classes/Storage'; import L from 'leaflet'; import './ObjDetectPanel.scss'; import ErrorMessage from 'webodm/components/ErrorMessage'; import Workers from 'webodm/classes/Workers'; import { _ } from 'webodm/classes/gettext'; export default class ObjDetectPanel extends React.Component { static defaultProps = { }; static propTypes = { onClose: PropTypes.func.isRequired, tasks: PropTypes.object.isRequired, isShowed: PropTypes.bool.isRequired, map: PropTypes.object.isRequired } constructor(props){ super(props); this.state = { error: "", permanentError: "", model: Storage.getItem("last_objdetect_model") || "cars", loading: true, task: props.tasks[0] || null, detecting: false, objLayer: null, }; } componentDidMount(){ } componentDidUpdate(){ if (this.props.isShowed && this.state.loading){ const {id, project} = this.state.task; this.loadingReq = $.getJSON(`/api/projects/${project}/tasks/${id}/`) .done(res => { const { available_assets } = res; if (available_assets.indexOf("orthophoto.tif") === -1){ this.setState({permanentError: _("No orthophoto is available. To use object detection you need an orthophoto.")}); } }) .fail(() => { this.setState({permanentError: _("Cannot retrieve information for task. Are you are connected to the internet?")}) }) .always(() => { this.setState({loading: false}); this.loadingReq = null; }); } } componentWillUnmount(){ if (this.loadingReq){ this.loadingReq.abort(); this.loadingReq = null; } if (this.detectReq){ this.detectReq.abort(); this.detectReq = null; } } handleSelectModel = e => { this.setState({model: e.target.value}); } getFormValues = () => { const { model } = this.state; return { model }; } addGeoJSONFromURL = (url, cb) => { const { map } = this.props; $.getJSON(url) .done((geojson) => { try{ this.handleRemoveObjLayer(); this.setState({objLayer: L.geoJSON(geojson, { onEachFeature: (feature, layer) => { if (feature.properties && feature.properties.level !== undefined) { layer.bindPopup(`