import { defineComponent, inject, computed, ref, watch, resolveComponent, openBlock, createBlock, unref, withCtx, createElementVNode, createVNode, createTextVNode, toDisplayString, createElementBlock, Fragment, renderList, normalizeClass } from "vue";
import { X, f as formatMeasurementResult, b as _export_sfc } from "./index-e8d5fc75.mjs";
import "@element-plus/icons-vue";
import "ol";
import "proj4";
import "@supermapgis/iclient-ol";
import "element-plus";
const encodeBase64 = (value) => {
  const btoaFn = globalThis == null ? void 0 : globalThis.btoa;
  if (typeof btoaFn === "function") {
    try {
      return btoaFn(unescape(encodeURIComponent(value)));
    } catch {
      try {
        return btoaFn(value);
      } catch {
        return null;
      }
    }
  }
  const BufferCtor = globalThis == null ? void 0 : globalThis.Buffer;
  if (BufferCtor == null ? void 0 : BufferCtor.from) {
    try {
      return BufferCtor.from(value, "utf-8").toString("base64");
    } catch {
      return null;
    }
  }
  return null;
};
const createSvgIcon = (content, viewBox = "0 0 24 24", fill = "currentColor", stroke = "none", strokeWidth = "0") => {
  const svg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="${viewBox}" width="24" height="24" fill="${fill}" stroke="${stroke}" stroke-width="${strokeWidth}" stroke-linecap="round" stroke-linejoin="round">${content}</svg>`;
  const base64 = encodeBase64(svg);
  if (base64)
    return `data:image/svg+xml;base64,${base64}`;
  return `data:image/svg+xml;charset=utf-8,${encodeURIComponent(svg)}`;
};
const svgPaths = {
  // 空间距离 - 尺子图标
  distance: '<path d="M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm0 16H5V5h14v14zM7 10h2v7H7zm4-3h2v10h-2zm4 3h2v7h-2z" fill="#409eff"/>',
  // 水平面积 - 多边形网格图标
  area: '<path d="M19 5H5c-1.1 0-2 .9-2 2v10c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 12H5V7h14v10z" fill="none" stroke="#67c23a" stroke-width="2"/><path d="M7 9h2v2H7zm4 0h2v2h-2zm4 0h2v2h-2zm-8 4h2v2H7zm4 0h2v2h-2zm4 0h2v2h-2z" fill="#67c23a"/>',
  // 坐标测量 - 定位针图标
  coordinate: '<path d="M12 2C8.13 2 5 5.13 5 9c0 5.25 7 13 7 13s7-7.75 7-13c0-3.87-3.13-7-7-7zm0 9.5c-1.38 0-2.5-1.12-2.5-2.5s1.12-2.5 2.5-2.5 2.5 1.12 2.5 2.5-1.12 2.5-2.5 2.5z" fill="#e6a23c"/>',
  // 角度测量 - 量角器图标
  angle: '<path d="M20 18v-2H6.8l5.6-9.7l1.7 1l-4.2 7.2h10.1z" fill="none" stroke="#f56c6c" stroke-width="2"/><circle cx="12" cy="12" r="2" fill="#f56c6c"/>',
  // 区域导航 - 指南针/地图图标
  location: '<path d="M12 2L4.5 20.29l.71.71L12 18l6.79 3 .71-.71z" fill="#409eff"/>',
  // 标记 - 简单的图钉图标
  marker: '<path d="M12 2C8.14 2 5 5.14 5 9c0 5.25 7 13 7 13s7-7.75 7-13c0-3.86 3.14-7 7-7zm0 2c2.76 0 5 2.24 5 5s-2.24 5-5 5-5-2.24-5-5 2.24-5 5-5zm0 2c-1.66 0-3 1.34-3 3s1.34 3 3 3 3-1.34 3-3-1.34-3-3-3z" fill="#f56c6c"/>',
  // 清除 - 垃圾桶/扫帚图标
  clear: '<path d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z" fill="#909399"/>',
  // 关闭
  close: '<path d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z" fill="#606266"/>',
  // 全屏
  fullscreen: '<path d="M7 14H5v5h5v-2H7v-3zm-2-4h2V7h3V5H5v5zm12 7h-3v2h5v-5h-2v3zM14 5v2h3v3h2V5h-5z" fill="#606266"/>',
  // 退出全屏
  exitFullscreen: '<path d="M5 16h3v3h2v-5H5v2zm3-8H5v2h5V5H8v3zm6 11h2v-3h3v-2h-5v5zm2-11V5h-2v5h5V8h-3z" fill="#606266"/>',
  // 额外的图形图标 (for ICON_PATHS)
  pin: '<path d="M12 2C8.13 2 5 5.13 5 9c0 5.25 7 13 7 13s7-7.75 7-13c0-3.87-3.13-7-7-7z" fill="#ff4444"/>',
  circle: '<circle cx="12" cy="12" r="8" fill="#3399CC"/>',
  square: '<rect x="6" y="6" width="12" height="12" fill="#3399CC"/>',
  triangle: '<polygon points="12,4 4,20 20,20" fill="#3399CC"/>',
  star: '<polygon points="12,2 15,9 22,9 17,14 19,21 12,17 5,21 7,14 2,9 9,9" fill="#FFD700"/>'
};
const getIcon = (name) => {
  const path = svgPaths[name];
  if (!path)
    return "";
  return createSvgIcon(path);
};
const icons = {
  distance: getIcon("distance"),
  area: getIcon("area"),
  coordinate: getIcon("coordinate"),
  angle: getIcon("angle"),
  location: getIcon("location"),
  marker: getIcon("marker"),
  clear: getIcon("clear"),
  close: getIcon("close"),
  fullscreen: getIcon("fullscreen"),
  exitFullscreen: getIcon("exitFullscreen"),
  // Additional icons
  pin: getIcon("pin"),
  circle: getIcon("circle"),
  square: getIcon("square"),
  triangle: getIcon("triangle"),
  star: getIcon("star")
};
const _hoisted_1 = { class: "measurement-content h-full flex flex-col" };
const _hoisted_2 = { class: "measurement-header flex justify-between items-center px-6 py-4" };
const _hoisted_3 = { class: "measurement-result py-8 text-center" };
const _hoisted_4 = { class: "result-value" };
const _hoisted_5 = { class: "tool-grid flex-1 py-5" };
const _hoisted_6 = ["onClick"];
const _hoisted_7 = ["src", "alt"];
const _hoisted_8 = { class: "tool-label" };
const _sfc_main = /* @__PURE__ */ defineComponent({
  __name: "MeasurementDialog",
  props: {
    modelValue: { type: Boolean },
    defaultUnits: { default: () => ({
      distance: "auto",
      area: "auto",
      angle: "auto"
    }) }
  },
  emits: ["update:modelValue"],
  setup(__props, { expose: __expose, emit: __emit }) {
    const props = __props;
    const emit = __emit;
    const measurementToolRef = inject("measurementTool");
    const measurementTool = computed(() => measurementToolRef == null ? void 0 : measurementToolRef.value);
    const dialogVisible = computed({
      get: () => props.modelValue,
      set: (value) => emit("update:modelValue", value)
    });
    const activeTool = ref(null);
    const measurementResult = ref(null);
    const measurementTools = [
      { type: "distance", icon: icons.distance, label: "空间距离" },
      { type: "area", icon: icons.area, label: "水平面积" },
      { type: "coordinate", icon: icons.coordinate, label: "坐标测量" },
      { type: "angle", icon: icons.angle, label: "角度" }
    ];
    const selectedUnit = ref("auto");
    const onUnitChange = () => {
      console.log("单位变化:", selectedUnit.value);
      if (!measurementResult.value)
        return;
      const resultType = measurementResult.value.type || activeTool.value;
      if (resultType === "distance" && measurementResult.value.value !== void 0) {
        const result = formatMeasurementResult(
          measurementResult.value.value,
          "length",
          selectedUnit.value
        );
        measurementResult.value = {
          ...measurementResult.value,
          distance: result.formatted
        };
      } else if (resultType === "area" && measurementResult.value.value !== void 0) {
        const result = formatMeasurementResult(
          measurementResult.value.value,
          "area",
          selectedUnit.value
        );
        measurementResult.value = {
          ...measurementResult.value,
          area: result.formatted
        };
      } else if (resultType === "angle" && measurementResult.value.value !== void 0) {
        const result = formatMeasurementResult(
          measurementResult.value.value,
          "angle",
          selectedUnit.value
        );
        measurementResult.value = {
          ...measurementResult.value,
          angle: result.formatted
        };
      }
    };
    const isMouseActive = ref(false);
    const mouseTooltip = ref("");
    const setActiveTool = (tool) => {
      if (!measurementTool.value) {
        console.warn("measurementTool未初始化");
        return;
      }
      measurementResult.value = null;
      if (measurementTool.value) {
        measurementTool.value.stopMeasurement();
      }
      activeTool.value = tool;
      const defaultUnit = tool === "distance" ? props.defaultUnits.distance : tool === "area" ? props.defaultUnits.area : tool === "angle" ? props.defaultUnits.angle : "auto";
      selectedUnit.value = defaultUnit;
      isMouseActive.value = true;
      switch (tool) {
        case "distance":
          mouseTooltip.value = "点击地图上两点或多点测量距离";
          measurementTool.value.startDistanceMeasurement(
            (result) => {
              handleMeasurementResult(result);
            },
            selectedUnit.value
          );
          break;
        case "area":
          mouseTooltip.value = "点击地图绘制多边形测量面积";
          measurementTool.value.startAreaMeasurement(
            (result) => {
              handleMeasurementResult(result);
            },
            selectedUnit.value
          );
          break;
        case "coordinate":
          mouseTooltip.value = "点击地图获取坐标信息";
          measurementTool.value.startCoordinateMeasurement(
            (result) => {
              handleMeasurementResult(result);
            }
          );
          break;
        case "angle":
          mouseTooltip.value = "点击地图测量角度";
          measurementTool.value.startAngleMeasurement(
            (result) => {
              handleMeasurementResult(result);
            },
            selectedUnit.value
          );
          break;
      }
    };
    const getDisplayValue = () => {
      if (!measurementResult.value)
        return "0";
      const resultType = measurementResult.value.type || activeTool.value;
      if (resultType === "distance" && measurementResult.value.distance) {
        return measurementResult.value.distance;
      } else if (resultType === "area" && measurementResult.value.area) {
        return measurementResult.value.area;
      } else if (resultType === "angle" && measurementResult.value.angle) {
        return measurementResult.value.angle;
      } else if (resultType === "coordinate" && measurementResult.value.longitude) {
        return `${measurementResult.value.longitude}°, ${measurementResult.value.latitude}°`;
      }
      return "0";
    };
    const handleMeasurementResult = (result) => {
      var _a, _b, _c;
      console.log("接收到测量结果:", result);
      activeTool.value = null;
      if (result.type === "length") {
        measurementResult.value = {
          type: "distance",
          value: result.value,
          // 保存原始数值用于单位转换
          unit: result.unit,
          distance: result.distance || ((_a = result.value) == null ? void 0 : _a.toString()) || "0",
          area: null
        };
      } else if (result.type === "area") {
        measurementResult.value = {
          type: "area",
          value: result.value,
          // 保存原始数值用于单位转换
          unit: result.unit,
          distance: null,
          area: result.area || ((_b = result.value) == null ? void 0 : _b.toString()) || "0"
        };
      } else if (result.type === "angle") {
        measurementResult.value = {
          type: "angle",
          value: result.value,
          // 保存原始数值用于单位转换
          unit: result.unit,
          angle: result.angle || ((_c = result.value) == null ? void 0 : _c.toString()) || "0"
        };
      } else if (result.type === "coordinate") {
        measurementResult.value = {
          type: "coordinate",
          longitude: result.longitude,
          latitude: result.latitude
        };
      } else {
        measurementResult.value = result;
      }
      isMouseActive.value = false;
    };
    const handleMapMeasurementResult = (result) => {
      console.log("接收到地图测量结果:", result);
      if (result.type === "distance") {
        measurementResult.value = {
          type: "distance",
          distance: result.value,
          area: null
        };
      } else if (result.type === "area") {
        measurementResult.value = {
          type: "area",
          distance: null,
          area: result.value
        };
      } else if (result.type === "angle") {
        measurementResult.value = {
          type: "angle",
          angle: result.value
        };
      } else if (result.type === "coordinate") {
        measurementResult.value = {
          type: "coordinate",
          longitude: result.longitude,
          latitude: result.latitude,
          elevation: result.elevation
        };
      } else {
        measurementResult.value = result;
      }
      isMouseActive.value = false;
    };
    __expose({
      handleMapMeasurementResult
    });
    const clearMeasurement = () => {
      measurementResult.value = null;
      if (measurementTool.value) {
        measurementTool.value.clearMeasurements();
      }
      activeTool.value = null;
      isMouseActive.value = false;
      mouseTooltip.value = "";
    };
    const stopAllMeasurement = () => {
      measurementResult.value = null;
      if (measurementTool.value) {
        measurementTool.value.clearMeasurements();
      }
      activeTool.value = null;
      isMouseActive.value = false;
      mouseTooltip.value = "";
    };
    const handleClose = () => {
      dialogVisible.value = false;
      stopAllMeasurement();
      mouseTooltip.value = "";
    };
    watch(dialogVisible, (newVal) => {
      if (!newVal) {
        handleClose();
      }
    });
    return (_ctx, _cache) => {
      const _component_el_option = resolveComponent("el-option");
      const _component_el_option_group = resolveComponent("el-option-group");
      const _component_el_select = resolveComponent("el-select");
      const _component_el_button = resolveComponent("el-button");
      return openBlock(), createBlock(unref(X), {
        modelValue: dialogVisible.value,
        "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => dialogVisible.value = $event),
        title: "图上量算",
        width: "400px",
        "before-close": handleClose,
        "show-modal": false,
        "modal-class": "pointer-events-none",
        "cache-id": "measurement-dialog",
        "append-to-body": ""
      }, {
        default: withCtx(() => [
          createElementVNode("div", _hoisted_1, [
            createElementVNode("div", _hoisted_2, [
              createVNode(_component_el_select, {
                modelValue: selectedUnit.value,
                "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => selectedUnit.value = $event),
                placeholder: "自动",
                size: "small",
                style: { "width": "120px" },
                onChange: onUnitChange
              }, {
                default: withCtx(() => [
                  createVNode(_component_el_option, {
                    label: "自动",
                    value: "auto"
                  }),
                  createVNode(_component_el_option_group, { label: "距离单位" }, {
                    default: withCtx(() => [
                      createVNode(_component_el_option, {
                        label: "米",
                        value: "m"
                      }),
                      createVNode(_component_el_option, {
                        label: "千米",
                        value: "km"
                      })
                    ]),
                    _: 1
                  }),
                  createVNode(_component_el_option_group, { label: "面积单位" }, {
                    default: withCtx(() => [
                      createVNode(_component_el_option, {
                        label: "平方米",
                        value: "m²"
                      }),
                      createVNode(_component_el_option, {
                        label: "平方千米",
                        value: "km²"
                      })
                    ]),
                    _: 1
                  }),
                  createVNode(_component_el_option_group, { label: "角度单位" }, {
                    default: withCtx(() => [
                      createVNode(_component_el_option, {
                        label: "度",
                        value: "°"
                      }),
                      createVNode(_component_el_option, {
                        label: "弧度",
                        value: "rad"
                      })
                    ]),
                    _: 1
                  })
                ]),
                _: 1
              }, 8, ["modelValue"]),
              createVNode(_component_el_button, {
                link: "",
                size: "small",
                style: { "color": "var(--el-color-danger)" },
                onClick: clearMeasurement
              }, {
                default: withCtx(() => [..._cache[2] || (_cache[2] = [
                  createTextVNode(" 清除 ", -1)
                ])]),
                _: 1
              })
            ]),
            createElementVNode("div", _hoisted_3, [
              createElementVNode("div", _hoisted_4, toDisplayString(getDisplayValue()), 1)
            ]),
            createElementVNode("div", _hoisted_5, [
              (openBlock(), createElementBlock(Fragment, null, renderList(measurementTools, (tool) => {
                return createElementVNode("div", {
                  key: tool.type,
                  class: normalizeClass(["tool-item", { active: activeTool.value === tool.type }]),
                  onClick: ($event) => setActiveTool(tool.type)
                }, [
                  createElementVNode("img", {
                    src: tool.icon,
                    alt: tool.label,
                    class: "tool-icon"
                  }, null, 8, _hoisted_7),
                  createElementVNode("span", _hoisted_8, toDisplayString(tool.label), 1)
                ], 10, _hoisted_6);
              }), 64))
            ])
          ])
        ]),
        _: 1
      }, 8, ["modelValue"]);
    };
  }
});
const MeasurementDialog = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-3caa3266"]]);
export {
  MeasurementDialog as default
};
