index.js 1.22 KB
Newer Older
邓晓峰's avatar
邓晓峰 committed
1
import React from 'react';
2
import { AMapScene } from '@wisdom-map/amap';
邓晓峰's avatar
邓晓峰 committed
3
import { connect } from 'react-redux';
4
import { store } from '@wisdom-utils/utils';
邓晓峰's avatar
邓晓峰 committed
5
import { actionCreators } from '../../../containers/App/store';
6

邓晓峰's avatar
邓晓峰 committed
7
const AMap = props => {
邓晓峰's avatar
邓晓峰 committed
8
  const getMap = (obj, current) => {
9
    store.set('amapView', {
邓晓峰's avatar
邓晓峰 committed
10 11 12
      Amap: obj,
      map: current,
    });
lihonglin's avatar
lihonglin committed
13
    props.updageAMapView({
邓晓峰's avatar
邓晓峰 committed
14 15
      Amap: obj,
      map: current,
lihonglin's avatar
lihonglin committed
16
    });
邓晓峰's avatar
邓晓峰 committed
17
  };
18

lihonglin's avatar
lihonglin committed
19
  const mapOptions = {
20
    config: window.globalConfig.mapsettings,
邓晓峰's avatar
邓晓峰 committed
21
    theme: 'amap://styles/74fae00a851749793870b658f9f22d55',
22 23 24
    mapOptions: {
      plugins: ['AMap.MarkerClusterer'],
    },
邓晓峰's avatar
邓晓峰 committed
25
  };
26

邓晓峰's avatar
邓晓峰 committed
27
  return (
邓晓峰's avatar
邓晓峰 committed
28 29
    <div
      style={{
lihonglin's avatar
lihonglin committed
30 31 32 33 34
        position: 'absolute',
        top: 0,
        right: 0,
        bottom: 0,
        left: 0,
邓晓峰's avatar
邓晓峰 committed
35 36 37
      }}
    >
      <AMapScene {...mapOptions} getMapInfo={getMap} />
lihonglin's avatar
lihonglin committed
38
    </div>
邓晓峰's avatar
邓晓峰 committed
39 40
  );
};
lihonglin's avatar
lihonglin committed
41
const mapStateToProps = state => ({
邓晓峰's avatar
邓晓峰 committed
42
  global: state.getIn(['global', 'globalConfig']),
43
  amapView: state.getIn(['global', 'amapView']),
lihonglin's avatar
lihonglin committed
44 45 46 47
});

const mapDispatchToProps = dispatch => ({
  updageAMapView(amapView) {
邓晓峰's avatar
邓晓峰 committed
48
    // eslint-disable-next-line no-undef
lihonglin's avatar
lihonglin committed
49 50 51 52 53 54 55 56
    dispatch(actionCreators.updageAMapView(amapView));
  },
});

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