import { reactive as Z, watch as ee, onMounted as te, onUnmounted as le, onDeactivated as ae, toRefs as ne, defineComponent as ie, resolveComponent as v, openBlock as b, createElementBlock as _, normalizeClass as M, unref as t, createVNode as s, withCtx as f, Fragment as J, renderList as T, createBlock as H, isRef as oe, createCommentVNode as B, renderSlot as se, toDisplayString as ue } from "vue";
import { u as re, a as ce, b as me } from "./layer-select-Ba4IEiWY.js";
import { i as K, b as E, _ as de } from "./utils-B4smQbM-.js";
import "./vendor-D4icwOYu.js";
import "ant-design-vue";
import { ElevationMode as pe, LinearUnits as ge, AreaUnits as fe, SketchStyle as ve, SimpleFillSymbol as be, SimpleLineSymbol as Q, Color as N, GeometryEngine as w } from "@mapgis/webclient-common";
const X = {
  lineStyle: "solid",
  // 线样式
  lineColor: "rgba(24, 144, 255, 1)",
  // 线颜色
  lineWidth: 2,
  // 线宽度
  fillColor: "rgba(24, 144, 255, 0.3)"
  // 面填充颜色
}, ye = {
  /**
   * @description 测量功能项，[{id,label,icon,unit,action}]
   */
  measureItems: {
    type: Array
  },
  /**
   * @description 绘制样式
   */
  measureStyle: {
    type: Object,
    default: () => ({
      ...X
    })
  },
  /**
   * @description 是否开启连续绘制
   */
  continueDrawing: {
    type: Boolean,
    default: !0
  }
}, he = {
  // 样式变化，扩展量算里的样式也需同步更新，目前cesium的量算不是用的草图编辑
  styleChange: (u) => E(u),
  // 量算功能项变化，扩展量算可能会基于这个增加特定的配置
  itemChange: (u, m) => K(u) && E(m),
  // 单位变化
  unitChange: (u, m) => K(u) && E(m),
  // 抛出清除事件，点击清除按钮，需要同步清除扩展量算绘制内容
  clear: () => !0
}, _e = (u, m) => {
  const { viewState: q } = re(), { addPolyline: O, addPolygon: L, asyncDrawWrapper: d, removeAllDraw: R, stopDraw: p, setSketchStyle: x } = ce(
    q,
    { editable: !1, elevationMode: pe.absoluteHeight }
  ), e = Z({
    // 测量功能项
    measureItems: u.measureItems,
    // 绘制样式
    measureStyle: u.measureStyle,
    // 是否连续绘制
    continueDrawing: u.continueDrawing,
    // 当前激活的测量项id
    activeId: void 0,
    // 当前激活的测量项
    activeItem: null,
    // 单位
    unit: void 0,
    // 单位可选项
    unitOptions: [],
    // 显示设置面板
    showSettingPanel: !1,
    // 量算结果
    measureResult: void 0,
    // 线样式选项
    lineOptions: [
      {
        label: "实线",
        value: "solid"
      },
      {
        label: "虚线",
        value: "dash"
      }
    ]
  });
  let n, r;
  const k = [
    { label: "米", value: "meters" },
    { label: "千米", value: "kilometers" },
    { label: "英尺", value: "feet" },
    { label: "英里", value: "miles" },
    { label: "码", value: "yards" }
  ], F = [
    { label: "平方米", value: "square-meters" },
    { label: "平方千米", value: "square-kilometers" },
    { label: "平方英尺", value: "square-feet" },
    { label: "平方英里", value: "square-miles" },
    { label: "平方码", value: "square-yards" }
  ], G = {
    ...X
  }, U = [
    {
      id: "length",
      label: "长度",
      icon: "mapgis-ruler",
      unit: ge.meters,
      unitOptions: [...k],
      action: D
    },
    {
      id: "area",
      label: "面积",
      icon: "mapgis-area",
      unit: fe.squareMeters,
      unitOptions: [...F],
      action: z
    }
  ];
  !e.measureItems || e.measureItems.length === 0 ? e.measureItems = [...U] : e.measureItems = e.measureItems.map((l) => {
    const i = U.find((c) => c.id === l.id);
    return i ? { ...i, ...l } : l;
  }), (!e.measureStyle || !Object.keys(e.measureStyle).length) && (e.measureStyle = { ...G }), ee(
    () => e.measureStyle,
    () => {
      S(), m("styleChange", e.measureStyle);
    },
    {
      deep: !0
    }
  ), te(() => {
    S();
  }), le(() => {
    o();
  }), ae(() => {
    o();
  });
  function P(l) {
    o(), e.activeId = l.id, e.activeItem = l, m("itemChange", e.activeId, l), JSON.stringify(e.unitOptions) !== JSON.stringify(l.unitOptions) && (e.unitOptions = [...l.unitOptions], e.unit = l.unit), R(), e.measureResult = void 0, l.action();
  }
  function A(l, i) {
    m("unitChange", l, i), e.measureResult && e.measureResult.length && e.activeItem && e.activeItem.action(!0);
  }
  function W(l) {
    e.activeId = l;
  }
  function o() {
    e.activeId = "", e.activeItem = null, e.unit = void 0, e.unitOptions = [], p(), R(), e.measureResult = void 0, m("clear");
  }
  function S() {
    const l = new ve({
      lineStyle: new Q({
        color: new N.fromColor(e.measureStyle.lineColor),
        width: e.measureStyle.lineWidth,
        style: e.measureStyle.lineStyle
      }),
      fillStyle: new be({
        color: new N.fromColor(e.measureStyle.fillColor),
        outline: new Q({
          color: new N.fromColor(e.measureStyle.lineColor),
          width: e.measureStyle.lineWidth,
          style: e.measureStyle.lineStyle
        })
      })
    });
    x(l);
  }
  function I(l, i) {
    if (e.continueDrawing && r) {
      const c = l.findGraphicById(r);
      c && l.remove(c);
    }
  }
  async function D(l) {
    var a;
    l || (n = await d(O), r = n.id);
    const i = (a = n.spatialReference) == null ? void 0 : a.isGeographic, c = w.planarLength(
      // 要计算长度的几何对象
      n,
      ...i ? [] : [e.unit]
    ), C = w.geodesicLength(
      // 要计算长度的几何对象
      n,
      e.unit
    ), y = e.unitOptions.find((g) => g.value === e.unit).label;
    e.measureResult = [
      { label: "图面长度", value: c, unit: i ? "度" : y },
      { label: "实地长度", value: C, unit: y }
    ], e.continueDrawing ? (n = await d(O, I), r = n.id, D(!0)) : e.activeId = "";
  }
  async function z(l) {
    var V;
    l || (n = await d(L), r = n.id);
    const i = (V = n.spatialReference) == null ? void 0 : V.isGeographic, c = w.planarArea(
      // 要计算长度的几何对象
      n,
      ...i ? [] : [e.unit]
    ), C = w.geodesicArea(n, e.unit), y = e.unitOptions.find((h) => h.value === e.unit).label, a = [
      { label: "图面面积", value: c, unit: i ? "平方度" : y },
      { label: "实地面积", value: C, unit: y }
    ], g = y.split("平方")[1], $ = e.measureItems.find((h) => h.id == "length").unitOptions.find((h) => h.label == g);
    if ($) {
      const h = w.planarLength(
        // 要计算长度的几何对象
        n,
        ...i ? [] : [$.value]
      ), Y = w.geodesicLength(n, $.value);
      a.push({ label: "图面周长", value: h, unit: i ? "度" : g }), a.push({ label: "实地周长", value: Y, unit: g });
    }
    e.measureResult = a, e.continueDrawing ? (n = await d(L, I), r = n.id, z(!0)) : e.activeId = "";
  }
  return {
    ...ne(e),
    handleMeasureClick: P,
    handleUnitChange: A,
    updateActiveMeasureItem: W,
    clearState: o
  };
}, Se = { key: 0 }, Ce = /* @__PURE__ */ ie({
  name: "MapgisBasicMeasure",
  __name: "basic-measure",
  props: ye,
  emits: he,
  setup(u, { expose: m, emit: q }) {
    const O = u, L = q, d = me("basic-measure"), {
      measureItems: R,
      measureStyle: p,
      activeId: x,
      unit: e,
      unitOptions: n,
      showSettingPanel: r,
      measureResult: k,
      lineOptions: F,
      handleMeasureClick: G,
      handleUnitChange: U,
      updateActiveMeasureItem: P,
      clearState: A
    } = _e(O, L);
    return m({
      updateActiveMeasureItem: P,
      clearState: A
    }), (W, o) => {
      const S = v("mapgis-ui-toolbar-command"), I = v("mapgis-ui-toolbar-command-group"), D = v("mapgis-ui-toolbar-space"), z = v("mapgis-ui-toolbar"), l = v("a-select"), i = v("a-form-item"), c = v("mapgis-ui-setting-form"), C = v("mapgis-ui-color-picker"), y = v("a-input-number");
      return b(), _("div", {
        class: M([t(d).b()])
      }, [
        s(z, {
          bordered: !1,
          size: "small"
        }, {
          default: f(() => [
            s(I, { removeLastCommandRightMargin: !1 }, {
              default: f(() => [
                (b(!0), _(J, null, T(t(R), (a) => (b(), H(S, {
                  key: a.label,
                  title: a.label,
                  icon: a.icon,
                  active: t(x) === a.id,
                  size: "small",
                  onClick: (g) => t(G)(a)
                }, null, 8, ["title", "icon", "active", "onClick"]))), 128))
              ]),
              _: 1
            }),
            s(D),
            s(I, { removeFirstCommandLeftMargin: !1 }, {
              default: f(() => [
                s(S, {
                  title: "清除",
                  icon: "mapgis-delete",
                  onClick: t(A),
                  size: "small"
                }, null, 8, ["onClick"]),
                s(S, {
                  onClick: o[0] || (o[0] = (a) => r.value = !t(r)),
                  active: t(r),
                  title: "设置",
                  icon: "mapgis-setting",
                  size: "small"
                }, null, 8, ["active"])
              ]),
              _: 1
            })
          ]),
          _: 1
        }),
        s(c, {
          layout: "horizontal",
          itemLayout: "grid",
          size: "default",
          class: M(t(d).e("form"))
        }, {
          default: f(() => [
            t(n) && t(n).length ? (b(), H(i, {
              key: 0,
              label: "单位"
            }, {
              default: f(() => [
                s(l, {
                  value: t(e),
                  "onUpdate:value": o[1] || (o[1] = (a) => oe(e) ? e.value = a : null),
                  options: t(n),
                  class: M(t(d).e("unit")),
                  size: "small",
                  placeholder: "单位选择",
                  onChange: t(U)
                }, null, 8, ["value", "options", "class", "onChange"])
              ]),
              _: 1
            })) : B("", !0),
            se(W.$slots, "config", {}, void 0, !0)
          ]),
          _: 3
        }, 8, ["class"]),
        t(k) && t(k).length ? (b(), _("div", {
          key: 0,
          class: M(t(d).e("result"))
        }, [
          (b(!0), _(J, null, T(t(k), ({ label: a, value: g, unit: j }) => (b(), _("div", { key: g }, [
            g !== void 0 ? (b(), _("span", Se, ue(`${a}：${g}${j}`), 1)) : B("", !0)
          ]))), 128))
        ], 2)) : B("", !0),
        t(r) ? (b(), _("div", {
          key: 1,
          class: M(t(d).e("setting"))
        }, [
          s(c, {
            layout: "horizontal",
            itemLayout: "grid",
            size: "default"
          }, {
            default: f(() => [
              s(i, { label: "线样式" }, {
                default: f(() => [
                  s(l, {
                    value: t(p).lineStyle,
                    "onUpdate:value": o[2] || (o[2] = (a) => t(p).lineStyle = a),
                    options: t(F),
                    "auto-width": !0
                  }, null, 8, ["value", "options"])
                ]),
                _: 1
              }),
              s(i, { label: "线颜色" }, {
                default: f(() => [
                  s(C, {
                    disableAlpha: !1,
                    showColorText: !1,
                    color: t(p).lineColor,
                    "onUpdate:color": o[3] || (o[3] = (a) => t(p).lineColor = a)
                  }, null, 8, ["color"])
                ]),
                _: 1
              }),
              s(i, { label: "线宽度" }, {
                default: f(() => [
                  s(y, {
                    value: t(p).lineWidth,
                    "onUpdate:value": o[4] || (o[4] = (a) => t(p).lineWidth = a),
                    min: 1,
                    "auto-width": !0
                  }, null, 8, ["value"])
                ]),
                _: 1
              }),
              s(i, { label: "填充颜色" }, {
                default: f(() => [
                  s(C, {
                    disableAlpha: !1,
                    showColorText: !1,
                    color: t(p).fillColor,
                    "onUpdate:color": o[5] || (o[5] = (a) => t(p).fillColor = a)
                  }, null, 8, ["color"])
                ]),
                _: 1
              })
            ]),
            _: 1
          })
        ], 2)) : B("", !0)
      ], 2);
    };
  }
}), Re = /* @__PURE__ */ de(Ce, [["__scopeId", "data-v-d5909559"]]);
export {
  Re as B,
  ye as a,
  he as b,
  X as d,
  _e as u
};
