index.js 1.47 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
import React from 'react';
import _ from 'lodash';
import { connect } from 'react-redux';
import AMapLoader from '@amap/amap-jsapi-loader';
import { store } from '@wisdom-utils/utils';
import { actionCreators } from '@/containers/App/store';
import MapComponent from '@/components/MapView';
class CreateMap extends React.Component {
  constructor(props) {
    super(props);
    this.mapManganerRef = React.createRef();
    [
      '_AMap_vectorlayer',
      '_AMap_AMap.MouseTool',
      '_AMap_AMap.DistrictSearch',
      '_AMap_AMap.Autocomplete',
      '_AMap_sync',
      '_AMap_AMap.PlaceSearch',
      '_AMap_wgl',
      '_AMap_overlay',
      '_AMap_mouse',
    ].forEach(item => {
      localStorage.removeItem(item);
    });
    AMapLoader.reset();
  }

  getView = view => {
    store.set('view', view);
    this.props.updageMapView(view);
  };

  render() {
    if (_.isNull(this.props.global.mapsettings.areasettings)) {
      return null;
    }

    const props = {
      loading: true,
      config: this.props.global.mapsettings,
      widgets: this.props.global.uiwidgets,
    };

    return (
      <>
        <MapComponent {...props} getMapInfo={this.getView} />
      </>
    );
  }
}

const mapStateToProps = state => ({
  global: state.getIn(['global', 'globalConfig']),
});

const mapDispatchToProps = dispatch => ({
  updageMapView(mapView) {
    dispatch(actionCreators.updageMapView(mapView));
  },
});

export default connect(
  mapStateToProps,
  mapDispatchToProps,
)(CreateMap);