/* global L Counter */ /* 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 { ButtonGroup, Row, Col, Checkbox } from 'react-bootstrap'; import { Meteor } from 'meteor/meteor'; import { ReactiveVar } from 'meteor/reactive-var'; import { withTracker } from 'meteor/react-meteor-data'; import { Trans, translate } from 'react-i18next'; import { Map } from 'react-leaflet'; import Control from 'react-leaflet-control'; import _ from 'lodash'; import 'leaflet/dist/leaflet.css'; import 'leaflet-graphicscale/dist/Leaflet.GraphicScale.min.css'; import 'leaflet-graphicscale/dist/Leaflet.GraphicScale.min.js'; import 'leaflet-sleep/Leaflet.Sleep.js'; import geolocation from '/imports/startup/client/geolocation'; import CenterInMyPosition from '/imports/ui/components/CenterInMyPosition/CenterInMyPosition'; import FireList from '/imports/ui/components/Maps/FireList'; import subsUnion from '/imports/ui/components/Maps/SubsUnion/SubsUnion'; import DefMapLayers from '/imports/ui/components/Maps/DefMapLayers'; import FromNow from '/imports/ui/components/FromNow/FromNow'; import Loading from '/imports/ui/components/Loading/Loading'; import ActiveFiresCollection from '/imports/api/ActiveFires/ActiveFires'; import FireAlertsCollection from '/imports/api/FireAlerts/FireAlerts'; import SiteSettings from '/imports/api/SiteSettings/SiteSettings'; import UserSubsToFiresCollection from '/imports/api/Subscriptions/Subscriptions'; import { isNotHomeAndMobile, isChrome } from '/imports/ui/components/Utils/isMobile'; import './FiresMap.scss'; const MAXZOOM = 6; const MAXZOOMREACTIVE = 6; const zoom = new ReactiveVar(8); const center = new ReactiveVar([0, 0]); const mapSize = new ReactiveVar(); // Remove map in subscription class FiresMap extends React.Component { constructor(props) { super(props); this.state = { viewport: { center: props.center, zoom: props.zoom }, useMarkers: false, scaleAdded: false, showSubsUnion: true }; const self = this; // viewportchange // https://stackoverflow.com/questions/23123138/perform-debounce-in-react-js this.debounceView = _.debounce((viewport) => { self.handleViewportChange(viewport); }, 1500); this.onViewportChanged = this.onViewportChanged.bind(this); } componentDidMount() { } onViewportChanged(viewport) { this.debounceView(viewport); } getMap() { return this.fireMap.leafletElement; } setShowSubsUnion(showSubsUnion) { this.setState({ showSubsUnion }); } handleViewportChange(viewport) { console.log(`Viewport changed: ${JSON.stringify(viewport)}`); const bounds = this.getMap().getBounds(); // console.log(bounds); mapSize.set([bounds.getNorthEast(), bounds.getSouthWest()]); /* if (viewport.center === this.state.viewport.center && viewport.zoom === this.state.viewport.zoom) { // Do nothing, in same point return; } zoom.set(viewport.zoom); center.set(viewport.center); this.setState({ viewport }); */ } centerOnUserLocation(viewport) { this.setState({ viewport }); } useMarkers(use) { this.setState({ useMarkers: use }); } addScale() { // https://www.npmjs.com/package/leaflet-graphicscale const map = this.getMap(); const options = { fill: 'fill', showSubunits: true }; L.control.graphicScale([options]).addTo(map); } handleLeafletLoad(map) { // console.log(map); if (map) { // console.log('Firesmap loading'); try { const bounds = this.getMap().getBounds(); mapSize.set([bounds.getNorthEast(), bounds.getSouthWest()]); if (!this.state.scaleAdded) { this.addScale(); this.state.scaleAdded = true; } } catch (e) { console.log('Failed to set map bounds and scale'); } this.state.union = subsUnion(this.state.union, { map, subs: this.props.userSubs, show: this.state.showSubsUnion, fit: false }); } } render() { console.log(`Rendering ${this.props.loading ? 'loading' : 'LOADED'} map ${this.props.activefires.length + this.props.firealerts.length} of ${this.props.activefirestotal} total. Subs users ready ${this.props.subsready}, reactive ${this.state.viewport.zoom >= MAXZOOMREACTIVE}`); return ( /* Large number of markers: https://stackoverflow.com/questions/43015854/large-dataset-of-markers-or-dots-in-leaflet/43019740#43019740 */
{ (this.props.activefires.length + this.props.firealerts.length) === 0 ?
{ this.state.viewport.zoom >= MAXZOOMREACTIVE ?
(*)