'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var index$2 = require('../../components/primitives/index.js');
var index$3 = require('../../components/geometry-instance/index.js');
var index$4 = require('../../components/geometries/index.js');
var index$6 = require('../../components/overlays/index.js');
var index$5 = require('../../components/primitive-collections/index.js');
var index$7 = require('../../components/ui/index.js');
var index$1 = require('../use-locale/index.js');
require('../../shared/index.js');
var cesiumHelpers = require('../../utils/cesium-helpers.js');
var vue = require('vue');
var index = require('../use-common/index.js');
var useDrawingAction = require('./use-drawing-action.js');
var DrawStatus = require('../../shared/src/DrawStatus.js');
var MeasureUnits = require('../../shared/src/MeasureUnits.js');

function useDrawingPolyline(props, ctx, cmpName) {
  const instance = vue.getCurrentInstance();
  const commonState = index["default"](props, ctx, instance);
  if (commonState === void 0) {
    return;
  }
  const { t } = index$1.useLocale();
  const { $services } = commonState;
  const { emit } = ctx;
  const {
    drawingType,
    drawTip,
    drawTipOpts,
    drawStatus,
    canShowDrawTip,
    drawTipPosition,
    showEditor,
    editorPosition,
    mouseoverPoint,
    editingPoint,
    primitiveCollectionRef,
    editorType,
    onMouseoverPoints,
    onMouseoutPoints,
    onMouseenterEditor,
    onMouseleaveEditor,
    onPrimitiveCollectionReady,
    onVcCollectionPointReady,
    onVcCollectionLabelReady,
    onVcPrimitiveReady
  } = useDrawingAction["default"](props, ctx, instance, cmpName, $services);
  let lastClickPosition;
  let restorePosition;
  const mouseDelta = 10;
  const renderDatas = vue.ref([]);
  if (props.preRenderDatas && props.preRenderDatas.length) {
    props.preRenderDatas.forEach((preRenderData) => {
      const polylineDrawing = {
        show: true,
        positions: cesiumHelpers.makeCartesian3Array(preRenderData),
        tempPositions: [],
        drawStatus: DrawStatus["default"].AfterDraw,
        loop: props.loop,
        distance: 0,
        area: 0,
        distances: [],
        labels: [],
        angles: []
      };
      renderDatas.value.push(polylineDrawing);
    });
  }
  const computedRenderDatas = vue.computed(() => {
    const { Cartesian3, createGuid, defined } = Cesium;
    const polylines = [];
    renderDatas.value.forEach((polyline, index) => {
      var _a, _b, _c, _d, _e, _f, _g, _h, _i;
      const labels = [];
      const distances = [];
      const angles = [];
      let distance = 0;
      const dashedLines = [];
      const positions = polyline.positions.slice();
      if (cmpName === "VcAnalysisSightline") {
        const observationPoint = positions.shift();
        const destinationPoints = positions;
        observationPoint && destinationPoints.forEach((destinationPoint) => {
          const positionsNew = [];
          positionsNew.push(observationPoint);
          const objectsToExclude = [];
          const primitiveCollection = primitiveCollectionRef.value.cesiumObject._primitives;
          primitiveCollection.forEach((primitive) => {
            if (primitive instanceof Cesium.PointPrimitiveCollection) {
              objectsToExclude.push(...primitive._pointPrimitives);
            }
            if (primitive instanceof Cesium.Primitive) {
              objectsToExclude.push(primitive);
            }
          });
          const intersection = cesiumHelpers.getFirstIntersection(observationPoint, destinationPoint, $services.viewer, objectsToExclude);
          if (defined(intersection)) {
            positionsNew.push(intersection);
          }
          positionsNew.push(destinationPoint);
          let distance2 = 0;
          const distances2 = [];
          for (let i = 0; i < positionsNew.length - 1; i++) {
            const s = Cartesian3.distance(positionsNew[i], positionsNew[i + 1]);
            distances2.push(s);
            distance2 = distance2 + s;
          }
          polylines.push({
            ...polyline,
            positions: positionsNew,
            distance: distance2,
            distances: distances2
          });
        });
      } else {
        props.loop && positions.length > 2 && positions.push(positions[0]);
        for (let i = 0; i < positions.length - 1; i++) {
          let s = 0;
          if (((_a = props.polylineOpts) == null ? void 0 : _a.arcType) === 0) {
            s = cesiumHelpers.getGeodesicDistance(positions[i], positions[i + 1], $services.viewer.scene.globe.ellipsoid);
          } else {
            s = Cartesian3.distance(positions[i], positions[i + 1]);
          }
          distances.push(s);
          distance = distance + s;
          if (s > 0 && positions.length > 2 && props.showDistanceLabel) {
            labels.push({
              text: MeasureUnits["default"].distanceToString(s, (_b = props.measureUnits) == null ? void 0 : _b.distanceUnits, props.locale, (_c = props.decimals) == null ? void 0 : _c.distance),
              position: Cartesian3.midpoint(positions[i], positions[i + 1], {}),
              id: createGuid(),
              ...props.labelsOpts
            });
          }
          if (positions.length > 2 && props.showAngleLabel) {
            if (i > 0 || props.loop) {
              const point0 = positions[i === 0 ? positions.length - 2 : i - 1];
              const point1 = positions[i];
              const point2 = positions[i + 1];
              const diffrence1 = Cartesian3.subtract(point0, point1, {});
              const diffrence2 = Cartesian3.subtract(point2, point1, {});
              let angle = 0;
              if (!(Cartesian3.ZERO.equals(diffrence1) || Cartesian3.ZERO.equals(diffrence2))) {
                angle = Cartesian3.angleBetween(diffrence1, diffrence2);
              }
              angles.push(angle);
              labels.push({
                text: MeasureUnits["default"].angleToString(angle, (_d = props.measureUnits) == null ? void 0 : _d.angleUnits, props.locale, (_e = props.decimals) == null ? void 0 : _e.angle),
                position: point1,
                id: createGuid(),
                ...props.labelsOpts
              });
            }
          }
          if (props.showDashedLine) {
            dashedLines.push({
              positions: [positions[i], getEndPostion(positions[i])]
            });
            if (i === positions.length - 2) {
              dashedLines.push({
                positions: [positions[i + 1], getEndPostion(positions[i + 1])]
              });
            }
          }
        }
        const area = cesiumHelpers.calculateAreaByPostions(positions);
        if (cmpName.includes("Area")) {
          labels.push({
            text: MeasureUnits["default"].areaToString(area, (_f = props.measureUnits) == null ? void 0 : _f.areaUnits, props.locale, (_g = props.decimals) == null ? void 0 : _g.area),
            position: positions[positions.length - 1],
            id: createGuid(),
            ...props.labelOpts
          });
        } else {
          labels.push({
            text: MeasureUnits["default"].distanceToString(distance, (_h = props.measureUnits) == null ? void 0 : _h.distanceUnits, props.locale, (_i = props.decimals) == null ? void 0 : _i.distance),
            position: positions[positions.length - 1],
            id: createGuid(),
            ...props.labelOpts
          });
        }
        polylines.push({
          ...polyline,
          labels,
          distance,
          distances,
          area,
          angles,
          dashedLines
        });
      }
    });
    return polylines;
  });
  instance.mount = async () => {
    const { viewer } = $services;
    cmpName.includes("VcMeasurement") && viewer.scene.preRender.addEventListener(updateLabelPosition);
    return true;
  };
  instance.unmount = async () => {
    const { viewer } = $services;
    cmpName.includes("VcMeasurement") && viewer.scene.preRender.removeEventListener(updateLabelPosition);
    return true;
  };
  const getEndPostion = (position) => {
    const { defined, defaultValue } = Cesium;
    const { viewer } = $services;
    const scene = viewer.scene;
    const globe = scene.globe;
    const ellipsoid = scene.frameState.mapProjection.ellipsoid;
    const positionCartographic = ellipsoid.cartesianToCartographic(position);
    positionCartographic.height = defined(globe) ? defaultValue(globe.getHeight(positionCartographic), 0) : 0;
    return ellipsoid.cartographicToCartesian(positionCartographic);
  };
  const updateLabelPosition = () => {
    computedRenderDatas.value.forEach((polyline, index) => {
      var _a;
      const positions = polyline.positions;
      if (!(positions.length < 2)) {
        const { defined, SceneTransforms, Cartesian2, HorizontalOrigin } = Cesium;
        const { viewer } = $services;
        const scene = viewer.scene;
        let startPosition = positions[0];
        const positionWindow = SceneTransforms.wgs84ToWindowCoordinates(scene, startPosition, {});
        let startPositionWindow = defined(positionWindow) ? Cartesian2.clone(positionWindow, {}) : Cartesian2.fromElements(Number.NEGATIVE_INFINITY, Number.POSITIVE_INFINITY, {});
        let startY = startPositionWindow.y;
        const primitiveCollection = (_a = primitiveCollectionRef.value) == null ? void 0 : _a.cesiumObject;
        const labelCollection = primitiveCollection._primitives.filter((v) => v instanceof Cesium.LabelCollection);
        const labels = labelCollection[index]._labels;
        const labelTotalLength = labels[labels.length - 1];
        for (let i = 1; i < positions.length; i++) {
          const positionWindow2 = SceneTransforms.wgs84ToWindowCoordinates(scene, positions[i], {});
          if (defined(positionWindow2)) {
            const l = (startPositionWindow.y - positionWindow2.y) / (positionWindow2.x - startPositionWindow.x);
            if (labels[i - 1] !== labelTotalLength) {
              labels[i - 1].horizontalOrigin = 0 < l ? HorizontalOrigin.LEFT : HorizontalOrigin.RIGHT;
            }
            if (positionWindow2.y < startY) {
              startY = positionWindow2.y;
              startPosition = positions[i];
            }
            startPositionWindow = Cartesian2.clone(positionWindow2, startPositionWindow);
          }
          polyline.drawStatus === DrawStatus["default"].AfterDraw && (labelTotalLength.position = startPosition);
        }
      }
    });
  };
  const startNew = () => {
    const polyline = {
      show: false,
      positions: [],
      tempPositions: [],
      drawStatus: DrawStatus["default"].BeforeDraw,
      loop: props.loop,
      distance: 0,
      area: 0,
      distances: [],
      labels: [],
      angles: []
    };
    if (cmpName === "VcMeasurementHorizontal") {
      const { Cartesian3, Plane } = Cesium;
      Object.assign(polyline, {
        dashedLines: [],
        heightPlane: new Plane(Cartesian3.UNIT_X, 0),
        heightPlaneCV: new Plane(Cartesian3.UNIT_X, 0),
        height: 0,
        firstMove: false,
        tempNextPos: new Cartesian3()
      });
    }
    drawStatus.value = DrawStatus["default"].BeforeDraw;
    renderDatas.value.push(polyline);
    canShowDrawTip.value = true;
    drawTip.value = drawTipOpts.value.drawingTipStart;
  };
  const stop = () => {
    if (drawStatus.value === DrawStatus["default"].Drawing) {
      renderDatas.value.pop();
    }
    drawStatus.value = DrawStatus["default"].BeforeDraw;
    canShowDrawTip.value = false;
    drawTipPosition.value = [0, 0, 0];
  };
  const handleMouseClick = (movement, options) => {
    const { viewer, drawingFabInstance, getWorldPosition, selectedDrawingActionInstance } = $services;
    if (options.button === 2 && options.ctrl) {
      const drawingsOption = (drawingFabInstance == null ? void 0 : drawingFabInstance.proxy).drawingActionInstances.find((v) => v.name === drawingType);
      (drawingFabInstance == null ? void 0 : drawingFabInstance.proxy).toggleAction(drawingsOption);
      vue.nextTick(() => {
        emit("drawEvt", {
          name: drawingType,
          finished: true,
          windowPoistion: movement,
          type: "cancel"
        }, viewer);
      });
      return;
    }
    if (drawStatus.value === DrawStatus["default"].AfterDraw) {
      startNew();
    }
    const { defined, Cartesian2, Plane, Cartesian3 } = Cesium;
    const index = editingPoint.value ? editingPoint.value._vcPolylineIndex : renderDatas.value.length - 1;
    const polyline = renderDatas.value[index];
    const tempPositions = polyline.tempPositions;
    if (options.button === 2 && editingPoint.value) {
      if (editorType.value === "insert") {
        polyline.positions.splice(editingPoint.value._index, 1);
      } else {
        polyline.positions[editingPoint.value._index] = restorePosition;
      }
      drawStatus.value = DrawStatus["default"].AfterDraw;
      polyline.drawStatus = DrawStatus["default"].AfterDraw;
      editingPoint.value = void 0;
      drawTip.value = drawTipOpts.value.drawingTipStart;
      (drawingFabInstance == null ? void 0 : drawingFabInstance.proxy).editingActionName = void 0;
      canShowDrawTip.value = defined(selectedDrawingActionInstance);
      vue.nextTick(() => {
        emit("drawEvt", Object.assign({
          index,
          name: drawingType,
          renderDatas,
          finished: true,
          windowPoistion: movement,
          type: "cancel"
        }, computedRenderDatas.value[index]), viewer);
      });
      return;
    }
    lastClickPosition = lastClickPosition || new Cesium.Cartesian2(Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY);
    if (Cartesian2.magnitude(Cartesian2.subtract(lastClickPosition, movement, {})) < mouseDelta) {
      return;
    }
    if (options.button === 2 && drawStatus.value === DrawStatus["default"].Drawing) {
      if (tempPositions.length > 1) {
        tempPositions.pop();
        handleMouseMove(movement);
      }
    }
    if (options.button !== 0) {
      return;
    }
    const scene = viewer.scene;
    const position = getWorldPosition(scene, movement, {});
    if (!defined(position)) {
      return;
    }
    let finished = false;
    let type = "new";
    if (cmpName === "VcMeasurementHorizontal") {
      if (editingPoint.value) {
        drawStatus.value = DrawStatus["default"].AfterDraw;
        editingPoint.value = void 0;
        finished = true;
        type = editorType.value;
        drawTip.value = drawTipOpts.value.drawingTipStart;
      } else if (tempPositions.length === 0) {
        const ellipsoid = scene.frameState.mapProjection.ellipsoid;
        tempPositions.push(position);
        polyline.positions = tempPositions;
        polyline.heightPlane = Plane.fromPointNormal(position, ellipsoid.geodeticSurfaceNormal(position, {}), polyline.heightPlane);
        const positionCartographic = ellipsoid.cartesianToCartographic(position, {});
        const positionProject = scene.mapProjection.project(positionCartographic, {});
        const positionCV = Cartesian3.fromElements(positionProject.z, positionProject.x, positionProject.y, positionProject);
        polyline.heightPlaneCV = Plane.fromPointNormal(positionCV, Cartesian3.UNIT_X, polyline.heightPlaneCV);
        polyline.height = positionCartographic.height;
        polyline.firstMove = true;
        polyline.drawStatus = DrawStatus["default"].Drawing;
        polyline.show = true;
        drawStatus.value = DrawStatus["default"].Drawing;
      } else {
        tempPositions.push(polyline.tempNextPos);
        polyline.positions = tempPositions;
        polyline.firstMove = true;
      }
      drawTip.value = drawTipOpts.value.drawingTipEnd;
    } else {
      if (editingPoint.value) {
        drawStatus.value = DrawStatus["default"].AfterDraw;
        editingPoint.value = void 0;
        finished = true;
        type = editorType.value;
        drawTip.value = drawTipOpts.value.drawingTipStart;
      } else {
        tempPositions.push(position);
        polyline.positions = tempPositions;
        polyline.show = true;
        polyline.drawStatus = DrawStatus["default"].Drawing;
        drawStatus.value = DrawStatus["default"].Drawing;
        canShowDrawTip.value = true;
        drawTip.value = drawTipOpts.value.drawingTipEnd;
      }
      if (type !== "new") {
        ;
        (drawingFabInstance == null ? void 0 : drawingFabInstance.proxy).editingActionName = void 0;
        canShowDrawTip.value = defined(selectedDrawingActionInstance);
      }
    }
    Cartesian2.clone(movement, lastClickPosition);
    vue.nextTick(() => {
      emit("drawEvt", Object.assign({
        index,
        name: drawingType,
        renderDatas,
        finished,
        position: cmpName === "VcMeasurementHorizontal" ? polyline.positions[polyline.positions.length - 1] : position,
        windowPoistion: movement,
        type
      }, computedRenderDatas.value[index]), viewer);
    });
  };
  const handleMouseMove = (movement, options) => {
    const { viewer, getWorldPosition } = $services;
    const scene = viewer.scene;
    const position = getWorldPosition(scene, movement, {});
    const { defined } = Cesium;
    if (!defined(position)) {
      return;
    }
    drawTipPosition.value = position;
    if (drawStatus.value !== DrawStatus["default"].Drawing) {
      return;
    }
    const index = editingPoint.value ? editingPoint.value._vcPolylineIndex : renderDatas.value.length - 1;
    const polyline = renderDatas.value[index];
    let type = "new";
    if (cmpName === "VcMeasurementHorizontal") {
      const { SceneMode, IntersectionTests, Cartesian3 } = Cesium;
      const ellipsoid = scene.frameState.mapProjection.ellipsoid;
      const positions = polyline.positions;
      const cameraRay = scene.camera.getPickRay(movement);
      let intersectionPosition, unprojectPosition;
      if (scene.mode === SceneMode.SCENE3D && polyline.heightPlane) {
        intersectionPosition = IntersectionTests.rayPlane(cameraRay, polyline.heightPlane);
      } else if (scene.mode === SceneMode.COLUMBUS_VIEW && polyline.heightPlaneCV) {
        intersectionPosition = IntersectionTests.rayPlane(cameraRay, polyline.heightPlaneCV);
        intersectionPosition = Cartesian3.fromElements(intersectionPosition.y, intersectionPosition.z, intersectionPosition.x, intersectionPosition);
        unprojectPosition = scene.mapProjection.unproject(intersectionPosition);
        intersectionPosition = ellipsoid.cartographicToCartesian(unprojectPosition);
      } else {
        intersectionPosition = scene.camera.pickEllipsoid(movement, ellipsoid);
        if (defined(intersectionPosition)) {
          const cartographicPosition = ellipsoid.cartesianToCartographic(intersectionPosition);
          cartographicPosition.height = polyline.height || 0;
          intersectionPosition = ellipsoid.cartographicToCartesian(cartographicPosition, intersectionPosition);
        }
      }
      if (!defined(intersectionPosition)) {
        return;
      }
      if (!polyline.firstMove && (options == null ? void 0 : options.shift)) {
        const lastPosition = positions[positions.length - 2];
        const tempNextPos = polyline.tempNextPos;
        const d1 = Cartesian3.subtract(tempNextPos, lastPosition, {});
        let d2 = Cartesian3.subtract(intersectionPosition, lastPosition, {});
        d2 = Cartesian3.projectVector(d2, d1, d2);
        intersectionPosition = Cartesian3.add(lastPosition, d2, intersectionPosition);
      }
      if (editingPoint.value) {
        const positions2 = polyline.positions;
        positions2.splice(editingPoint.value._index, 1, intersectionPosition);
        type = editorType.value;
      } else {
        const tempPositions = polyline.tempPositions.slice();
        tempPositions.push(intersectionPosition);
        polyline.positions = tempPositions;
        polyline.firstMove = false;
        polyline.tempNextPos = Object.assign(intersectionPosition);
        drawTip.value = drawTipOpts.value.drawingTipEnd;
      }
    } else {
      if (editingPoint.value) {
        const positions = polyline.positions;
        positions.splice(editingPoint.value._index, 1, position);
        type = editorType.value;
      } else {
        const tempPositions = polyline.tempPositions.slice();
        tempPositions.push(position);
        polyline.positions = tempPositions;
      }
    }
    vue.nextTick(() => {
      emit("drawEvt", Object.assign({
        index,
        name: drawingType,
        renderDatas,
        finished: false,
        position: cmpName === "VcMeasurementHorizontal" ? polyline.positions[polyline.positions.length - 1] : position,
        windowPoistion: movement,
        type
      }, computedRenderDatas.value[index]), viewer);
    });
  };
  const handleDoubleClick = (movement) => {
    const { drawingFabInstance, selectedDrawingActionInstance, viewer } = $services;
    if (drawStatus.value === DrawStatus["default"].Drawing) {
      const index = editingPoint.value ? editingPoint.value._vcPolylineIndex : renderDatas.value.length - 1;
      const polyline = renderDatas.value[index];
      polyline.positions = polyline.tempPositions;
      polyline.drawStatus = DrawStatus["default"].AfterDraw;
      drawStatus.value = DrawStatus["default"].AfterDraw;
      drawTip.value = drawTipOpts.value.drawingTipStart;
      vue.nextTick(() => {
        emit("drawEvt", Object.assign({
          index,
          name: drawingType,
          renderDatas,
          finished: true,
          position: polyline.positions[polyline.positions.length - 1],
          windowPoistion: movement,
          type: "new"
        }, computedRenderDatas.value[index]), viewer);
        if (props.mode === 1) {
          ;
          (drawingFabInstance == null ? void 0 : drawingFabInstance.proxy).toggleAction(selectedDrawingActionInstance);
        }
      });
    }
  };
  const getPointIndexes = () => {
    let polylineIndex = editingPoint.value._vcPolylineIndex;
    let pointIndex = editingPoint.value._index;
    if (cmpName === "VcAnalysisSightline") {
      for (let i = 0; i < renderDatas.value.length; i++) {
        const polyline = renderDatas.value[i];
        for (let j = 0; j < polyline.positions.length; j++) {
          const position = polyline.positions[j];
          if (editingPoint.value.position.equals(position)) {
            polylineIndex = i;
            pointIndex = j;
          }
        }
      }
    }
    return [polylineIndex, pointIndex];
  };
  const onEditorClick = (e) => {
    var _a, _b, _c;
    editorPosition.value = [0, 0, 0];
    showEditor.value = false;
    if (!props.editable) {
      return;
    }
    const { viewer, drawingFabInstance } = $services;
    editorType.value = e;
    if (e === "move") {
      drawTip.value = drawTipOpts.value.drawingTipEditing;
      drawStatus.value = DrawStatus["default"].Drawing;
      editingPoint.value = mouseoverPoint.value;
      canShowDrawTip.value = true;
      const indexes = getPointIndexes();
      editingPoint.value._vcPolylineIndex = indexes[0];
      editingPoint.value._index = indexes[1];
      restorePosition = renderDatas.value[indexes[0]].positions[indexes[1]];
      (drawingFabInstance == null ? void 0 : drawingFabInstance.proxy).editingActionName = drawingType;
    } else if (e === "insert") {
      const index = mouseoverPoint.value._vcPolylineIndex;
      const polyline = renderDatas.value[index];
      polyline.positions.splice(mouseoverPoint.value._index, 0, mouseoverPoint.value.position);
      editingPoint.value = mouseoverPoint.value;
      canShowDrawTip.value = true;
      drawStatus.value = DrawStatus["default"].Drawing;
      drawTip.value = drawTipOpts.value.drawingTipEditing;
      (drawingFabInstance == null ? void 0 : drawingFabInstance.proxy).editingActionName = drawingType;
    } else if (e === "remove") {
      const index = mouseoverPoint.value._vcPolylineIndex;
      const polyline = renderDatas.value[index];
      polyline.positions.length > 2 && polyline.positions.splice(mouseoverPoint.value._index, 1);
    } else if (e === "removeAll") {
      const index = mouseoverPoint.value._vcPolylineIndex;
      renderDatas.value.splice(index, 1);
    } else {
      const index = mouseoverPoint.value._vcPolylineIndex;
      const polyline = renderDatas.value[index];
      (_c = (_b = (_a = props.editorOpts) == null ? void 0 : _a[e]) == null ? void 0 : _b.callback) == null ? void 0 : _c.call(_b, index, polyline);
    }
    emit("editorEvt", {
      type: e,
      renderDatas,
      name: drawingType,
      index: mouseoverPoint.value._vcPolylineIndex
    }, viewer);
  };
  const clear = () => {
    renderDatas.value = [];
    stop();
  };
  const publicMethods = {
    renderDatas,
    startNew,
    stop,
    clear,
    handleMouseClick,
    handleMouseMove,
    handleDoubleClick
  };
  Object.assign(instance.proxy, publicMethods);
  return () => {
    var _a, _b, _c;
    const { PolylineMaterialAppearance, Ellipsoid, createGuid, defaultValue, Cartesian3 } = Cesium;
    const polylineOpts = {
      ...props.polylineOpts,
      ellipsoid: defaultValue((_a = props.polylineOpts) == null ? void 0 : _a.ellipsoid, Ellipsoid.WGS84),
      vertexFormat: PolylineMaterialAppearance.VERTEX_FORMAT
    };
    props.clampToGround && delete polylineOpts.arcType;
    const children = [];
    const points = [];
    computedRenderDatas.value.forEach((polyline, index) => {
      var _a2, _b2, _c2;
      const positions = polyline.positions.slice();
      if (positions.length > 1) {
        polyline.loop && positions.push(positions[0]);
        children.push(vue.h(props.clampToGround ? index$2.VcPrimitiveGroundPolyline : index$2.VcPrimitive, {
          ...props.primitiveOpts,
          show: polyline.show && props.primitiveOpts.show || props.editable || polyline.drawStatus === DrawStatus["default"].Drawing
        }, () => vue.h(index$3.VcGeometryInstance, {
          id: createGuid()
        }, () => vue.h(props.clampToGround ? index$4.VcGeometryGroundPolyline : index$4.VcGeometryPolyline, {
          positions,
          ...polylineOpts
        }))));
      }
      const dashLineOpts = {
        ...props.dashLineOpts,
        ellipsoid: defaultValue((_a2 = props.dashLineOpts) == null ? void 0 : _a2.ellipsoid, Ellipsoid.WGS84),
        vertexFormat: PolylineMaterialAppearance.VERTEX_FORMAT
      };
      (_b2 = polyline.dashedLines) == null ? void 0 : _b2.forEach((dashedLine) => {
        children.push(vue.h(index$2.VcPrimitive, {
          ...props.dashLinePrimitiveOpts,
          show: polyline.show && props.dashLinePrimitiveOpts.show || props.editable || polyline.drawStatus === DrawStatus["default"].Drawing
        }, () => vue.h(index$3.VcGeometryInstance, {
          id: createGuid()
        }, () => vue.h(index$4.VcGeometryPolyline, {
          positions: dashedLine.positions,
          ...dashLineOpts
        }))));
      });
      children.push(vue.h(index$5.VcCollectionPoint, {
        enableMouseEvent: props.enableMouseEvent,
        show: polyline.show,
        points: polyline.positions.map((position, subIndex) => {
          var _a3;
          let includes = false;
          for (let i = 0; i < points.length; i++) {
            Cartesian3.equals(position, points[i]) && (includes = true);
          }
          const show = (((_a3 = props.pointOpts) == null ? void 0 : _a3.show) || props.editable || polyline.drawStatus === DrawStatus["default"].Drawing) && (cmpName === "VcAnalysisSightline" && polyline.positions.length === 3 ? subIndex !== 1 : true) && !includes;
          if (cmpName === "VcAnalysisSightline") {
            points.push(position);
          }
          return {
            position,
            id: createGuid(),
            _vcPolylineIndex: index,
            ...props.pointOpts,
            show
          };
        }),
        onMouseover: onMouseoverPoints,
        onMouseout: onMouseoutPoints,
        onReady: onVcCollectionPointReady
      }));
      cmpName.includes("VcMeasurement") && children.push(vue.h(index$5.VcCollectionLabel, {
        enableMouseEvent: props.enableMouseEvent,
        show: polyline.show,
        labels: polyline.labels,
        onReady: onVcCollectionLabelReady
      }));
      if (positions.length > 2 && (cmpName.includes("Polygon") || cmpName.includes("Area"))) {
        children.push(vue.h(index$5.VcPolygon, {
          positions,
          onReady: onVcPrimitiveReady,
          clampToGround: props.clampToGround,
          ...props.polygonOpts,
          show: polyline.show && ((_c2 = props.polygonOpts) == null ? void 0 : _c2.show)
        }));
      }
    });
    if (((_b = props.drawtip) == null ? void 0 : _b.show) && canShowDrawTip.value) {
      const { viewer } = $services;
      children.push(vue.h(index$6.VcOverlayHtml, {
        position: drawTipPosition.value,
        pixelOffset: props.drawtip.pixelOffset,
        teleport: {
          to: viewer.container
        }
      }, () => vue.h("div", {
        class: "vc-drawtip vc-tooltip--style"
      }, drawTip.value)));
    }
    if (showEditor.value) {
      const buttons = [];
      if (mouseoverPoint.value) {
        const editorOpts = props.editorOpts;
        for (const key in editorOpts) {
          if (!Array.isArray(editorOpts[key]) && typeof editorOpts[key] !== "number") {
            const opts = {
              ...editorOpts[key]
            };
            delete opts.color;
            buttons.push(vue.h(index$7.VcBtn, {
              style: { color: editorOpts[key].color, background: editorOpts[key].background },
              ...opts,
              onclick: onEditorClick.bind("polyline", key)
            }, () => vue.h(index$7.VcTooltip, {
              ...editorOpts[key].tooltip
            }, () => {
              var _a2;
              return vue.h("strong", null, ((_a2 = editorOpts[key].tooltip) == null ? void 0 : _a2.tip) || t(`vc.drawing.editor.${key}`));
            })));
          }
        }
      }
      const { viewer } = $services;
      children.push(vue.h(index$6.VcOverlayHtml, {
        position: editorPosition.value,
        pixelOffset: (_c = props.editorOpts) == null ? void 0 : _c.pixelOffset,
        teleport: {
          to: viewer.container
        },
        onMouseenter: onMouseenterEditor,
        onMouseleave: onMouseleaveEditor
      }, () => vue.h("div", {
        class: "vc-editor"
      }, buttons)));
    }
    return vue.h(index$5.VcCollectionPrimitive, {
      ref: primitiveCollectionRef,
      show: props.show,
      onReady: onPrimitiveCollectionReady
    }, () => children);
  };
}

exports["default"] = useDrawingPolyline;
//# sourceMappingURL=use-drawing-polyline.js.map
