utils.ts 614 B

1234567891011121314151617181920212223
  1. import { fabric } from 'fabric';
  2. export function getRandomPosition() {
  3. return 100 + Math.floor(Math.random() * 30);
  4. }
  5. /** 根据camera位置得到fav icon的位置 */
  6. export function getFavPositionByCamera(target?: fabric.Object | null) {
  7. if (!target || !target.oCoords) return null;
  8. return { left: target.oCoords?.tr.x, top: target.oCoords?.tr.y };
  9. }
  10. export function createSelectedPositionHash(target) {
  11. if (!target) return '';
  12. return (
  13. target.cameraId +
  14. String(target.oCoords.tr.x) +
  15. '_' +
  16. String(target.oCoords.tr.y) +
  17. '_' +
  18. String(target.angle)
  19. );
  20. }