Navigator.tsx 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import React, { useEffect } from "react";
  2. import { useModel } from "umi";
  3. import { MiniMap } from "@antv/x6-plugin-minimap";
  4. import { useSessionStorageState } from "ahooks";
  5. export default function Navigator() {
  6. const { graph } = useModel("erModel");
  7. const mapRef = React.useRef<HTMLDivElement>(null);
  8. const [show, setShow] = useSessionStorageState('show-navigator', {
  9. defaultValue: true,
  10. listenStorageChange: true,
  11. });
  12. useEffect(() => {
  13. if (graph && mapRef.current) {
  14. console.log('mini map');
  15. graph.use(
  16. new MiniMap({
  17. container: mapRef.current,
  18. width: mapRef.current.offsetWidth || 300,
  19. height: mapRef.current.offsetHeight || 200,
  20. padding: 10,
  21. maxScale: 2,
  22. minScale: 0.2
  23. })
  24. );
  25. }
  26. }, [graph, mapRef.current]);
  27. return (
  28. <div className="absolute right-20px bottom-20px bg-#fafafa w-300px z-2">
  29. <div className="text-12px color-#333 px-10px py-4px flex items-center cursor-pointer justify-between" onClick={() => setShow(!show)}>
  30. <span>导航</span>
  31. <i className="iconfont icon-open cursor-pointer" style={ show ? { transform: "rotate(180deg)" } : {}}/>
  32. </div>
  33. <div className="w-300px h-300px" ref={mapRef} style={{ height: show ? 300 : 0, overflow: "hidden" }}>
  34. </div>
  35. </div>
  36. );
  37. }