index.jsx 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import React, { useEffect, useRef, useState } from 'react';
  2. import loader from '@/components/AMap/loader';
  3. import getMarker from './marker';
  4. import geoPolygon from './geoPolygon';
  5. import Styles from './style.less';
  6. const plugins = [];
  7. export default (props) => {
  8. const container = useRef();
  9. const amapRef = useRef();
  10. const [map, setMap] = useState();
  11. useEffect(() => {
  12. loader(plugins).then((AMap) => {
  13. amapRef.current = AMap;
  14. const mapInst = new AMap.Map(container.current, {
  15. mapStyle: 'amap://styles/669a7d8709a9bab0945747a1a1db3327',
  16. // mapStyle: 'amap://styles/blue',
  17. zoom: 10,
  18. resizeEnable: true,
  19. center: [112.092716, 32.681642],
  20. });
  21. // 遮罩层;
  22. geoPolygon(AMap, mapInst);
  23. //
  24. setMap(mapInst);
  25. });
  26. }, []);
  27. useEffect(() => {
  28. if (!map) return;
  29. // 先搞一个 marker demo
  30. getMarker(amapRef.current, map, {
  31. position: [112.092716, 32.681642],
  32. extData: { value: '68辆' },
  33. });
  34. }, [map]);
  35. return (
  36. <div className={Styles['geo-map-container']}>
  37. {/* 占位图片 */}
  38. <div className={Styles['geo-map-header']}>
  39. <div />
  40. <div />
  41. <div />
  42. </div>
  43. <div className={Styles['geo-map-body']}>
  44. <div ref={container} />
  45. </div>
  46. {/* 占位图片 */}
  47. <div className={Styles['geo-map-footer']}>
  48. <div />
  49. <div />
  50. <div />
  51. </div>
  52. </div>
  53. );
  54. };