bill il y a 1 an
Parent
commit
46f5897460

+ 5 - 1
src/App.vue

@@ -1,11 +1,15 @@
 <template>
-  <QueryBoard :width="width" :height="height" />
+  <ElButton @click="mound = !mound">销毁测试</ElButton>
+  <QueryBoard :width="width" :height="height" v-if="mound" />
 </template>
 
 <script setup lang="ts">
+import { ref } from "vue";
+import { ElButton } from "element-plus";
 import QueryBoard from "./app/4dmap/example/index.vue";
 // import QueryBoard from "./app/liantong/example/index.vue";
 
+const mound = ref(true);
 const width = window.innerWidth;
 const height = window.innerHeight;
 </script>

+ 3 - 3
src/app/4dmap/index.ts

@@ -1,5 +1,5 @@
 import { Polygons } from "./polygons";
-import { register, BoundQueryPlugin } from "../../board";
+import { register, BoundQueryPlugin, setGenerateStartId } from "../../board";
 import { PolygonsAttrib } from "./type";
 import { Map } from "ol";
 import { boundingExtent } from "ol/extent";
@@ -67,7 +67,7 @@ const initBoard = register(
   { polygons: Polygons },
   { bound: new BoundQueryPlugin() }
 );
-
+setGenerateStartId(5000000);
 export const createBoard = (
   props: {
     dom?: HTMLDivElement;
@@ -97,7 +97,7 @@ export const createBoard = (
       }
     },
     getData() {
-      return board.getData().polygons;
+      return board.getData().polygons[0];
     },
     setData(polygon: PolygonsAttrib & { id: string }) {
       board.setData({ polygons: [polygon] });

+ 3 - 1
src/app/4dmap/path.ts

@@ -52,8 +52,10 @@ export class PoPath extends WholeLinePolygon<WholeLinePolygonAttrib, Group> {
         () => {
           if (polygons.status.editPolygonId === this.attrib.id) {
             this.bus.emit("statusChange", { active: true });
+          } else if (polygons.status.lightPolygonId === this.attrib.id) {
+            this.bus.emit("statusChange", { hover: true });
           } else {
-            this.bus.emit("statusChange", { active: false });
+            this.bus.emit("statusChange", { active: false, hover: false });
           }
         },
         { flush: "post" }

+ 19 - 11
src/app/4dmap/point.ts

@@ -122,6 +122,12 @@ const pointActShapeFactory = (attrib: PolygonsPointAttrib, tree: Point) => {
       group.x(data[0]);
       group.y(data[1]);
 
+      if (polygons.status.activePointId === attrib.id) {
+        label.visible(true);
+      } else {
+        label.visible(false);
+      }
+
       if (~tree.editPolygonNdx) {
         index.text((tree.editPolygonNdx + 1).toString()).visible(true);
         index.offsetX(-rect.width() / 2 + index.width() / 2);
@@ -200,17 +206,19 @@ export class Point extends WholeLinePoint<PolygonsPointAttrib, Group> {
             clearCursor = null;
           });
 
-          openEntityDrag(this, {
-            readyHandler: (attrib) => {
-              return [attrib.x, attrib.y];
-            },
-            moveHandler: (pointAttrib, move) => {
-              if (~this.editPolygonNdx) {
-                pointAttrib.x = move[0];
-                pointAttrib.y = move[1];
-              }
-            },
-          });
+          if (!this.attrib.rtk) {
+            openEntityDrag(this, {
+              readyHandler: (attrib) => {
+                return [attrib.x, attrib.y];
+              },
+              moveHandler: (pointAttrib, move) => {
+                if (~this.editPolygonNdx) {
+                  pointAttrib.x = move[0];
+                  pointAttrib.y = move[1];
+                }
+              },
+            });
+          }
 
           onCleanup(() => {
             anchor.off("mouseenter.anchor mouseleave.anchor");

+ 19 - 4
src/app/4dmap/polygons.ts

@@ -13,6 +13,8 @@ import {
   penWholeLinePoygonsEditWithHelperShapesMouse,
   getWholeLinePolygonLinesRaw,
   WholeLineLine,
+  getWholeLinePolygonPoints,
+  shapeParentsEq,
 } from "../../board";
 import { reactive } from "vue";
 import { Point } from "./point";
@@ -66,6 +68,7 @@ const lineActShapeFactory = (attrib: PolygonsLineAttrib, tree: any) => {
 
 export type PolygonsStatus = {
   newModel: boolean;
+  lightPolygonId?: string;
   activePointId?: string;
   editPolygonId?: string;
   selectPoiIds: string[];
@@ -135,6 +138,9 @@ export class Polygons extends WholeLine<
 
   private endEditPolygon: () => void;
   editPolygon(polygonId?: string) {
+    if (this.endEditPolygon) {
+      console.log(this.endEditPolygon);
+    }
     this.endEditPolygon && this.endEditPolygon();
     this.status.newModel = !polygonId;
     this.endEditPolygon = penWholeLinePoygonsEditWithHelperShapesMouse(
@@ -142,17 +148,26 @@ export class Polygons extends WholeLine<
         polygonId,
         pointAttribFactory: getPolygonPoint,
         canOper: (tree, operShape) => {
-          return (
-            !tree.name.includes(WholeLinePoint.namespace) ||
-            operShape.name() === "anchor-point"
+          if (!tree.name.includes(WholeLinePoint.namespace)) return true;
+          const polygonPoints = getWholeLinePolygonPoints(
+            this.attrib,
+            this.status.editPolygonId
+          );
+          const pointId = tree.attrib.id;
+          const exixts = polygonPoints.some(({ id }) => id === pointId);
+          return !!shapeParentsEq(
+            operShape,
+            (shape) =>
+              shape.name() === (exixts ? "anchor-point" : "anchor-move")
           );
         },
         quitHandler: () => {
           this.status.newModel = false;
           this.bus.emit("penEndHandler");
+          this.endEditPolygon = null;
         },
         canDelPoint: (p: any) => !p.rtk,
-        quotePoint: false,
+        quotePoint: (p: any) => p.rtk,
         closeAutoQuit: true,
         tree: this.container,
         autoAdd: false,

+ 10 - 2
src/board/packages/whole-line/service/whole-line-base.ts

@@ -5,11 +5,18 @@ import {
   WholeLinePolygonAttrib,
 } from "../view";
 
+let startId = 0;
+export const setGenerateStartId = (id: number) => (startId = id);
+
 export const generateWholeLineLineId = (config: WholeLineAttrib) =>
-  (Math.max(1, ...config.lines.map(({ id }) => Number(id))) + 1).toString();
+  (
+    Math.max(1, startId, ...config.lines.map(({ id }) => Number(id))) + 1
+  ).toString();
 
 export const generateWholeLinePointId = (config: WholeLineAttrib) =>
-  (Math.max(1, ...config.points.map(({ id }) => Number(id))) + 1).toString();
+  (
+    Math.max(1, startId, ...config.points.map(({ id }) => Number(id))) + 1
+  ).toString();
 
 export const generateWholeLinePoygonId = (
   config: WholeLineAttrib,
@@ -18,6 +25,7 @@ export const generateWholeLinePoygonId = (
   (
     Math.max(
       1,
+      startId,
       ...config.polygons.map(({ id }) => Number(id)),
       ...eIds.map(Number)
     ) + 1

+ 8 - 3
src/board/packages/whole-line/service/whole-line-edit.ts

@@ -42,7 +42,7 @@ export type PenWholeLinePoygonsEditProps<
   autoAdd?: boolean;
   closeAutoQuit?: boolean;
   pointAttribFactory?: (pos: number[]) => Omit<P, "id">;
-  quotePoint?: boolean;
+  quotePoint?: boolean | ((point: WholeLinePointAttrib) => boolean);
   canOper?: (
     tree: WholeLineLine | WholeLinePoint,
     operShape: ShapeType
@@ -163,13 +163,18 @@ export const penWholeLinePoygonsEdit = <
 
     let pointAttrib: P & Attrib;
     const polygonPoints = getWholeLinePolygonPoints(config, polyginAttrib.id);
+    let isQuotePoint;
 
     while (true) {
       if (child instanceof WholeLinePoint) {
         if (canOper && !canOper(child, evt.target)) {
           return { change, isClose: false };
         }
-        pointAttrib = quotePoint ? child.attrib : { ...child.attrib };
+        isQuotePoint =
+          typeof quotePoint === "function"
+            ? quotePoint(child.attrib)
+            : !!quotePoint;
+        pointAttrib = isQuotePoint ? child.attrib : { ...child.attrib };
 
         if (polyginAttrib.id === prevId) {
           return { change, isClose: false };
@@ -240,7 +245,7 @@ export const penWholeLinePoygonsEdit = <
       return { change, isClose };
     }
 
-    if (!quotePoint) {
+    if (!isQuotePoint) {
       delete pointAttrib.id;
     }