import React from 'react'; import PropTypes from 'prop-types'; import AssetDownloads from '../classes/AssetDownloads'; import '../css/ImagePopup.scss'; import { _ } from '../classes/gettext'; class ImagePopup extends React.Component { static propTypes = { feature: PropTypes.object.isRequired, task: PropTypes.object.isRequired, }; constructor(props){ super(props); this.state = { error: "", loading: true, expandThumb: false, } } getImageUrl(){ const { feature, task } = this.props; return `/api/projects/${task.project}/tasks/${task.id}/images/thumbnail/${feature.properties.filename}`; } getThumbUrl(size){ return `${this.getImageUrl()}?size=${size}`; } componentDidMount(){ if (this.image) this.image.addEventListener("fullscreenchange", this.onFullscreenChange); } componentWillUnmount(){ if (this.image) this.image.removeEventListener("fullscreenchange", this.onFullscreenChange); } onFullscreenChange = (e) => { if (!document.fullscreenElement){ this.setState({expandThumb: false}); } } imageOnError = () => { this.setState({error: _("Image missing"), loading: false}); } imageOnLoad = () => { this.setState({loading: false}); } onImgClick = () => { const { expandThumb } = this.state; if (!expandThumb){ this.image.requestFullscreen(); this.setState({ loading: true, expandThumb: true}); }else{ document.exitFullscreen(); this.setState({ expandThumb: false }); } } render(){ const { error, loading, expandThumb } = this.state; const { feature, task } = this.props; const downloadImageLink = `/api/projects/${task.project}/tasks/${task.id}/images/download/${feature.properties.filename}`; const downloadShotsLink = `/api/projects/${task.project}/tasks/${task.id}/download/shots.geojson`; const imageUrl = expandThumb ? this.getThumbUrl(999999999) : this.getThumbUrl(320); const assetDownload = AssetDownloads.only(["shots.geojson"])[0]; return (