Skip to content
Snippets Groups Projects
MapApp.js 8.87 KiB
Newer Older
import React from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import { withStyles } from '@material-ui/core/styles';
import withWidth from '@material-ui/core/withWidth';
import compose from 'recompose/compose';
import Paper from '@material-ui/core/Paper';
import Immutable from 'immutable';
Esko Ikkala's avatar
Esko Ikkala committed
import VirtualizedTable from '../components/VirtualizedTable';
import LeafletMap from '../components/map/LeafletMap';
import GMap from '../components/map/GMap';
import Pie from '../components/Pie';
import TopBar from '../components/TopBar';
  //getVisibleResults,
  getVisibleValues
} from '../selectors';
Esko Ikkala's avatar
Esko Ikkala committed
  toggleDataset,
  fetchSuggestions,
  clearSuggestions,
  fetchResults,
Esko Ikkala's avatar
Esko Ikkala committed
  fetchAllResults,
  getGeoJSON,
  updateResultFormat,
esikkala's avatar
esikkala committed
  updateResultsFilter,
  sortResults,
Esko Ikkala's avatar
Esko Ikkala committed
  bounceMarker,
} from '../actions';

const styles = theme => ({
  root: {
    flexGrow: 1,
    height: '100%',
  },
Esko Ikkala's avatar
Esko Ikkala committed
  flex: {
    flexGrow: 1,
Esko Ikkala's avatar
Esko Ikkala committed
  appFrame: {
    height: '100%',
    zIndex: 1,
Esko Ikkala's avatar
Esko Ikkala committed
    overflow: 'hidden',
Esko Ikkala's avatar
Esko Ikkala committed
    position: 'relative',
Esko Ikkala's avatar
Esko Ikkala committed
    width: '100%',
    minWidth: 640,
    minHeight: 700
Esko Ikkala's avatar
Esko Ikkala committed
  mainContainer: {
    display: 'flex',
    width: '100%',
Esko Ikkala's avatar
Esko Ikkala committed
    marginTop: 64,
    height: 'calc(100% - 128px)',
    borderRight: '4px solid' + theme.palette.primary.main,
    borderLeft: '4px solid' + theme.palette.primary.main,
  },
  resultTable: {
    width: 1024,
    height: 'calc(100% - 5px)',
    borderRight: '4px solid' + theme.palette.primary.main,

  },
  resultTableOneColumn: {
    width: 1024,
    height: 'calc(100% - 5px)',
  },
  rightColumn: {
    height: '100%',
    width: 'calc(100% - 1024px)',
  },
  map: {
    width: '100%',
    height: '50%',
    borderBottom: '4px solid' + theme.palette.primary.main,
Esko Ikkala's avatar
Esko Ikkala committed
  },
  fullMap: {
    width: '100%',
    height: '100%',
  },
Esko Ikkala's avatar
Esko Ikkala committed
  statistics: {
    width: '100%',
    height: '50%',
Esko Ikkala's avatar
Esko Ikkala committed
  statisticsOneColumn: {
    width: '100%',
    height: '100%',
  },
  footer: {
    position: 'absolute',
    borderTop: '4px solid' + theme.palette.primary.main,
    display: 'flex',
    alignItems: 'center',
    justifyContent: 'center',
    bottom: 0,
    width: '100%',
    height: 64,
    background: theme.palette.primary.main,
    borderRadius: 0,
  },
  aaltoLogo: {
    //paddingLeft: 24,
    height: 37
  },
  uhLogo: {
    paddingLeft: 44,
    height: 52
  },
  secoLogo: {
    paddingLeft: 44,
    height: 52
  },
  heldigLogo: {
    paddingLeft: 44,
    height: 37
  },
  kotusLogo: {
    paddingLeft: 44,
    height: 50
  },
  const { classes, options, browser, search, map, manuscripts, creationPlaces, resultValues } = props;
  let oneColumnView = browser.lessThan.extraLarge;

  // console.log('oneColumnView', oneColumnView)
  // console.log('resultFormat', resultFormat)
  // console.log('mapMode', mapMode)
  //console.log(props.results)
  //console.log(manuscripts)
  if ((oneColumnView && options.resultFormat === 'table') || (!oneColumnView)) {
    table = (
      <div className={oneColumnView ? classes.resultTableOneColumn : classes.resultTable}>
        <VirtualizedTable
          list={Immutable.List(manuscripts)}
          resultValues={resultValues}
          search={search}
          sortResults={props.sortResults}
          updateResultsFilter={props.updateResultsFilter}
          updateQuery={props.updateQuery}
          fetchResults={props.fetchResults}
Esko Ikkala's avatar
Esko Ikkala committed
          fetchAllResults={props.fetchAllResults}
          clearResults={props.clearResults}
          fetchSuggestions={props.fetchSuggestions}
          clearSuggestions={props.clearSuggestions}
Esko Ikkala's avatar
Esko Ikkala committed
          bounceMarker={props.bounceMarker}
          openMarkerPopup={props.openMarkerPopup}
          removeTempMarker={props.removeTempMarker}
  let mapElement = '';
  if ((oneColumnView && options.resultFormat === 'map') || (!oneColumnView)) {
    if (options.mapMode === 'heatmap') {
      mapElement = (
          results={props.creationPlaces}
          googleMapURL="https://maps.googleapis.com/maps/api/js?key=AIzaSyCKWw5FjhwLsfp_l2gjVAifPkT3cxGXhA4&v=3.exp&libraries=geometry,drawing,places,visualization"
          loadingElement={<div style={{ height: `100%` }} />}
          containerElement={<div style={{ height: `100%` }} />}
          mapElement={<div style={{ height: `100%` }} />}
        />
      );
    } else {
          results={creationPlaces}
          mapMode={options.mapMode}
          geoJSON={map.geoJSON}
          geoJSONKey={map.geoJSONKey}
Esko Ikkala's avatar
Esko Ikkala committed
          getGeoJSON={props.getGeoJSON}
          bouncingMarker={map.bouncingMarker}
          popupMarker={map.popupMarker}
          bouncingMarkerKey={map.bouncingMarkerKey}
          openPopupMarkerKey={map.openPopupMarkerKey}
  if ((oneColumnView && options.resultFormat === 'statistics') || (!oneColumnView)) {
Esko Ikkala's avatar
Esko Ikkala committed
      <div className={oneColumnView ? classes.statisticsOneColumn : classes.statistics}>
        <Pie data={manuscripts} groupBy={props.search.groupBy} query={props.search.query} />
  }

  let mainResultsView = '';
  if (oneColumnView) {
    switch(options.resultFormat) {
      case 'table': {
        mainResultsView = table;
        break;
      }
      case 'map': {
        mainResultsView = (
          <div className={classes.fullMap}>
            {map}
          </div>
        );
        break;
      }
      case 'statistics': {
        mainResultsView = statistics;
        break;
      }
    }
    mainResultsView = table;
  return (
    <div className={classes.root}>
      <div className={classes.appFrame}>
          results={manuscripts}
          oneColumnView={oneColumnView}
          mapMode={options.mapMode}
          resultFormat={options.resultFormat}
          updateMapMode={props.updateMapMode}
          updateResultFormat={props.updateResultFormat}
          toggleDataset={props.toggleDataset}
        <div className={classes.mainContainer}>
          {!oneColumnView &&
            <div className={classes.rightColumn}>
              <div className={classes.map}>
        <Paper className={classes.footer}>
Esko Ikkala's avatar
Esko Ikkala committed
          <img className={classes.aaltoLogo} src='img/logos/aalto-logo-white-no-background-small.png' alt='Aalto University logo'/>
esikkala's avatar
esikkala committed
          <img className={classes.uhLogo} src='img/logos/university-of-helsinki-logo-white-no-background-small.png' alt='University of Helsinki logo'/>
Esko Ikkala's avatar
Esko Ikkala committed
          <img className={classes.secoLogo} src='img/logos/seco-logo-white-no-background-small.png' alt='SeCo logo'/>
esikkala's avatar
esikkala committed
          <img className={classes.heldigLogo} src='img/logos/heldig-logo-small.png' alt='HELDIG logo'/>
const mapStateToProps = (state) => {
  return {
    options: state.options,
    browser: state.browser,
    search: state.search,
    // results: getVisibleResults(state.search),
    manuscripts: state.search.results.manuscripts,
    creationPlaces: state.search.results.creationPlaces,
    //resultValues: getVisibleValues(state.search),
    resultValues: {},

const mapDispatchToProps = ({
  updateQuery,
Esko Ikkala's avatar
Esko Ikkala committed
  toggleDataset,
  fetchSuggestions,
  clearSuggestions,
  fetchResults,
Esko Ikkala's avatar
Esko Ikkala committed
  fetchAllResults,
esikkala's avatar
esikkala committed
  sortResults,
  getGeoJSON,
  updateResultFormat,
Esko Ikkala's avatar
Esko Ikkala committed
  updateResultsFilter,
});

MapApp.propTypes = {
  classes: PropTypes.object.isRequired,
  theme: PropTypes.object.isRequired,
  //error: PropTypes.object.isRequired,
  browser: PropTypes.object.isRequired,

  options: PropTypes.object.isRequired,
  search: PropTypes.object.isRequired,
  map: PropTypes.object.isRequired,
  manuscripts: PropTypes.array,
  creationPlaces: PropTypes.object,
  resultValues: PropTypes.object,

  updateQuery: PropTypes.func.isRequired,
Esko Ikkala's avatar
Esko Ikkala committed
  toggleDataset: PropTypes.func.isRequired,
  fetchSuggestions: PropTypes.func.isRequired,
  clearSuggestions: PropTypes.func.isRequired,
  fetchResults: PropTypes.func.isRequired,
Esko Ikkala's avatar
Esko Ikkala committed
  fetchAllResults: PropTypes.func.isRequired,
  clearResults: PropTypes.func.isRequired,
esikkala's avatar
esikkala committed
  sortResults: PropTypes.func.isRequired,
Esko Ikkala's avatar
Esko Ikkala committed
  getGeoJSON: PropTypes.func.isRequired,
Esko Ikkala's avatar
Esko Ikkala committed
  bounceMarker: PropTypes.func.isRequired,
  openMarkerPopup: PropTypes.func.isRequired,
  removeTempMarker: PropTypes.func.isRequired,
  updateResultFormat: PropTypes.func.isRequired,
  updateMapMode: PropTypes.func.isRequired,
  updateResultsFilter: PropTypes.func.isRequired,
export default compose(
  connect(
    mapStateToProps,
    mapDispatchToProps
  ),
  withWidth(),
  withStyles(styles, {withTheme: true}),
)(MapApp);