/* eslint-disable import/no-absolute-path */ /* eslint-disable react/jsx-indent-props */ /* eslint-disable react/jsx-indent */ import React, { Fragment } from 'react'; import PropTypes from 'prop-types'; import { withTracker } from 'meteor/react-meteor-data'; import { withTranslation, Trans } from 'react-i18next'; import { Row, Col, Alert, Form, Dropdown } from 'react-bootstrap'; import { Meteor } from 'meteor/meteor'; import { Bert } from 'meteor/themeteorchef:bert'; import { Helmet } from 'react-helmet-async'; import { MapContainer, GeoJSON } from 'react-leaflet'; import { MapReady } from '/imports/ui/components/Maps/MapBridge'; import { rectangleAround } from 'map-common-utils'; import DefMapLayers from '/imports/ui/components/Maps/DefMapLayers'; import NotFound from '/imports/ui/pages/NotFound/NotFound'; import FiresCollection from '/imports/api/Fires/Fires'; import FireList from '/imports/ui/components/Maps/FireList'; import FromNow from '/imports/ui/components/FromNow/FromNow'; import { dateLongFormat, dateYYYYMMDD } from '/imports/api/Common/dates'; import { hexId } from '/imports/api/Common/id'; import CommentsBox from '/imports/ui/components/Comments/CommentsBox'; import FalsePositiveTypes from '/imports/api/FalsePositives/FalsePositiveTypes'; import FalsePositivesCollection, { falsePositivesRemap } from '/imports/api/FalsePositives/FalsePositives'; import IndustriesCollection, { industriesRemap } from '/imports/api/Industries/Industries'; import ShareIt from '/imports/ui/components/ShareIt/ShareIt'; import FullScreenMap from '/imports/ui/components/Maps/FullScreenMap'; import './Fires.scss'; class Fire extends React.Component { constructor(props) { super(props); this.state = { loading: props.loading, notfound: props.notfound, when: props.when }; } // state mirrors props purely for shouldComponentUpdate (render reads props // directly). Was the derived-state half of UNSAFE_componentWillReceiveProps. static getDerivedStateFromProps(props, state) { if (props.when !== state.when || props.loading !== state.loading || props.notfound !== state.notfound) { return { loading: props.loading, notfound: props.notfound, when: props.when }; } return null; } componentDidUpdate(prevProps) { // side effect (must not run in getDerivedStateFromProps): once the fire is // resolved via alert/active/hash, canonicalize the URL to /fire/archive/:id if (prevProps.when !== this.props.when || prevProps.loading !== this.props.loading || prevProps.notfound !== this.props.notfound) { const { fire, alert, active, fromHash, history } = this.props; if (fire && (alert || active || fromHash)) { history.replace(`/fire/archive/${hexId(fire._id)}`); } } } shouldComponentUpdate(nextProps, nextState) { return !(nextState.when === this.state.when && nextState.loading === this.state.loading && this.state.notfound === nextState.notfound && nextState.nasaLink === this.state.nasaLink); } onTypeSelect(key) { // console.log(key); Meteor.call('falsePositives.insert', this.props.fire._id, key, (error) => { if (error) { // console.log(error); Bert.alert(this.props.t(error.reason), 'danger'); } else { Bert.alert(this.props.t('Tomamos nota, ¡gracias por colaborar!'), 'success'); } }); } // v4: MapReady hands us the ready Leaflet map directly (no ref/.leafletElement) handleMapReady(lmap) { this.fireMap = lmap; this.handleLeafletMapLoad(lmap); if (this.circle) lmap.fitBounds(this.circle.getBounds()); } handleLeafletMapLoad(lmap) { if (lmap) { const bounds = lmap.getBounds(); const ne = bounds.getNorthEast(); const sw = bounds.getSouthWest(); // console.log(`${sw},${ne}`); // const nasaLinkBase = 'https://worldview.earthdata.nasa.gov/?p=geographic&l=VIIRS_SNPP_CorrectedReflectance_TrueColor(hidden),MODIS_Aqua_CorrectedReflectance_TrueColor(hidden),MODIS_Terra_CorrectedReflectance_TrueColor,MODIS_Fires_All,MODIS_Fires_Aqua,VIIRS_SNPP_Fires_375m_Night,VIIRS_SNPP_Fires_375m_Day,MODIS_Fires_Terra,Reference_Labels(hidden),Reference_Features(hidden),Coastlines&t=' const nasaLinkBase = 'https://worldview.earthdata.nasa.gov/?p=geographic&l=' + 'VIIRS_SNPP_CorrectedReflectance_TrueColor,' + 'MODIS_Aqua_CorrectedReflectance_TrueColor,' + 'MODIS_Terra_CorrectedReflectance_TrueColor,' + 'MODIS_Terra_Data_No_Data(hidden),' + 'MODIS_Fires_All,' + 'MODIS_Fires_Aqua,' + 'VIIRS_SNPP_Fires_375m_Night,' + 'VIIRS_SNPP_Fires_375m_Day,' + 'MODIS_Fires_Terra,' + 'Reference_Labels,' + 'Reference_Features,' + 'Coastlines' + '&t='; const nasaZoom = 5; this.setState({ nasaLink: `${nasaLinkBase}${this.dateYYYYMMDD}&z=3&v=${sw.lng},${sw.lat},${ne.lng},${ne.lat}&ab=off&as=${this.dateYYYYMMDD}&ae=${this.dateYYYYMMDD}&av=${nasaZoom}&al=true` }); } } handleLeafletCircleLoad(circle) { // v4: circle is the Leaflet GeoJSON layer; this.fireMap is the Leaflet map if (this.fireMap && circle) { this.fireMap.fitBounds(circle.getBounds()); } } render() { const { notfound, loading, fire, t } = this.props; if (Meteor.isDevelopment) console.log(`False positives total: ${this.props.falsePositives.length}`); if (Meteor.isDevelopment) console.log(`Industries total: ${this.props.industries.length}`); /* console.log(`loading fire: ${loading}`); * console.log(`Not found fire: ${notfound}`); */ if (fire && fire.when) { this.dateLongFormat = dateLongFormat(fire.when); this.dateYYYYMMDD = dateYYYYMMDD(fire.when); this.title = fire.address ? t('Información adicional sobre fuego detectado en {{where}} el {{when}}', { where: fire.address, when: this.dateLongFormat }) : t('Información adicional sobre fuego detectado el {{when}}', { when: this.dateLongFormat }); } const ready = fire && !loading; const rect = ready ? rectangleAround({ lat: fire.lat, lon: fire.lon }, fire.track, fire.track) : null; return (ready ? (
{t('Coordenadas:')} {fire.lat}, {fire.lon}
{(fire.type === 'modis' || fire.type === 'viirs') &&