Explorar o código

fix(相机布局): 修复新添加的相机无法拖动问题

louhangfei hai 1 ano
pai
achega
230b7af3f4
Modificáronse 1 ficheiros con 7 adicións e 8 borrados
  1. 7 8
      src/views/map-config/mini-map/MapBase/KonvaMap.vue

+ 7 - 8
src/views/map-config/mini-map/MapBase/KonvaMap.vue

@@ -282,13 +282,14 @@
    * @param configHeight 相机Icon的高度
    * @author chauncey
    */
-  function dymamicdragBoundFunc(configWidth: number, configHeight: number) {
+  function dymamicdragBoundFunc() {
     return function (pos: { x: number; y: number }) {
-      const scaleX = this.attrs.scaleX;
-      const scaleY = this.attrs.scaleY;
+      // 如果没有发生缩放,则返回的scaleX为undefined,需要设置为默认缩放为1
+      const scaleX = this.attrs.scaleX || 1;
+      const scaleY = this.attrs.scaleY || 1;
+      const rotation = ((this.attrs.rotation || 0) * Math.PI) / 180; // 转换为弧度
       const width = cameraIconSize.width;
       const height = cameraIconSize.height;
-      const rotation = (this.attrs.rotation * Math.PI) / 180; // 转换为弧度
 
       // 计算旋转和缩放后的四个角点相对于左上角的偏移
       const points = [
@@ -342,7 +343,7 @@
     const row = index % maxColumn;
     const x = column * cameraIconSize.width;
     const y = row * cameraIconSize.height + 16;
-    const dragBoundFunc = dymamicdragBoundFunc(cameraIconSize.width, cameraIconSize.height);
+    const dragBoundFunc = dymamicdragBoundFunc();
     return {
       x,
       y,
@@ -562,13 +563,11 @@
         });
       }
       cameras.value = layout.cameraList.map((camera) => {
-        const width = camera.config.width * camera.groupConfig.scaleX;
-        const height = camera.config.height * camera.groupConfig.scaleY;
         return {
           ...camera,
           groupConfig: {
             ...camera.groupConfig,
-            dragBoundFunc: dymamicdragBoundFunc(width, height),
+            dragBoundFunc: dymamicdragBoundFunc(),
           },
         };
       });