index.tsx 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import { useEffect, useRef, useState } from 'react';
  2. import AMapLoader from '@amap/amap-jsapi-loader';
  3. import classNames from 'classnames';
  4. import { LeftOutlined } from '@ant-design/icons';
  5. import './index.less';
  6. const AMapComponent = () => {
  7. const mapRef = useRef({});
  8. useEffect(() => {
  9. AMapLoader.load({
  10. key: '4a8929c85e2a1a8a1eae4ebc7d519ba4',
  11. version: '2.0',
  12. plugins: ['AMap.ToolBar', 'AMap.Driving'],
  13. AMapUI: {
  14. version: '1.1',
  15. plugins: [],
  16. },
  17. Loca: {
  18. version: '2.0.0',
  19. },
  20. })
  21. .then((AMap) => {
  22. const map = new AMap.Map('map-container', {
  23. viewMode: '3D',
  24. zoom: 5,
  25. zooms: [2, 22],
  26. center: [105.602725, 37.076636],
  27. });
  28. const positionArr = [
  29. [113.357224, 34.977186],
  30. [114.555528, 37.727903],
  31. [112.106257, 36.962733],
  32. [109.830097, 31.859027],
  33. [116.449181, 39.98614],
  34. ];
  35. for (const item of positionArr) {
  36. const marker = new AMap.Marker({
  37. position: [item[0], item[1]],
  38. });
  39. map.add(marker);
  40. }
  41. mapRef.current = map;
  42. })
  43. .catch((e) => {
  44. console.log(e);
  45. });
  46. }, []);
  47. const [show, setShow] = useState<boolean>(false);
  48. return (
  49. <div className="home">
  50. <div id="map-container" className="map" style={{ height: '600px' }} />
  51. <div className="draw">
  52. <div
  53. className={classNames('draw-warp', {
  54. show: show,
  55. })}
  56. >
  57. <div
  58. className={classNames('draw-button')}
  59. onClick={() => {
  60. setShow(!show);
  61. }}
  62. >
  63. <LeftOutlined className={classNames('draw-button-icon', { active: show })} />
  64. </div>
  65. <div className="draw-content">....内容信息</div>
  66. </div>
  67. </div>
  68. </div>
  69. );
  70. };
  71. export default AMapComponent;