import { defineComponent as De, ref as fe, reactive as Me, computed as Q, watch as Te, resolveComponent as q, openBlock as W, createElementBlock as ne, normalizeClass as L, unref as b, withDirectives as we, createElementVNode as $, createVNode as _, withCtx as T, toDisplayString as J, createBlock as le, normalizeStyle as X, createCommentVNode as ie, vShow as _e, getCurrentInstance as st, onMounted as ot, onUnmounted as lt, onDeactivated as ct, markRaw as Le, toRefs as ut } from "vue";
import { b as Oe, u as pt, p as dt, g as ft, d as yt, f as Ce, q as ht, r as Fe, e as Pe, s as mt, n as gt } from "./layer-select-Ba4IEiWY.js";
import { a as ce, b as St, i as xe, h as Ge, c as It, _ as $e, u as bt } from "./utils-B4smQbM-.js";
import { i as vt, p as kt, b as wt, d as _t, m as Lt } from "./vendor-D4icwOYu.js";
import "ant-design-vue";
import { c as ye } from "./query-BQ2UHSN1.js";
import "@mapgis/webclient-common";
const Ct = {
  /**
   * @description 拾取的图层列表，默认拾取所有支持的图层，监听属性，pickLayers和pickLayerIds同时存在时优先使用pickLayers
   */
  pickLayers: {
    type: Array
  },
  /**
   * @description 拾取的图层ID列表，默认拾取所有支持的图层，监听属性
   */
  pickLayerIds: {
    type: Array
  },
  /**
   * @description 缓冲距离
   */
  bufferDistance: {
    type: Number,
    default: 1
  },
  /**
   * 缓冲单位，可取值为像素、厘米、米、千米，默认为像素
   */
  bufferUnit: {
    type: String,
    default: "pixel",
    validator: (l) => ["pixel", "centimeter", "meter", "kilometer"].includes(l)
  },
  /**
   * @description 是否开启拾取高亮效果
   */
  enableHighlight: {
    type: Boolean,
    default: !0
  },
  /**
   * @description 是否显示拾取气泡框
   */
  showPickPopup: {
    type: Boolean,
    default: !0
  },
  /**
   * @description 拾取显示样式
   */
  pickShowStyle: {
    type: Object,
    default: () => ({
      ...ye
    })
  }
}, Ft = {
  // 可拾取的图层列表
  pickLayers: (l) => ce(l),
  // 拾取到的要素信息
  pickedFeatures: ({ pickedFeatures: l, pickedFeaturesTree: S }) => ce(l) && ce(S),
  // 打开弹窗前
  beforePopupOpen: ({ pickedFeatures: l, popupOptions: { component: S, anchor: v, nameWidth: c, valueWidth: m, prevent: C } }) => ce(l) && (St(S) || xe(S) || vt(S)) && xe(v) && Ge(c) && Ge(m) && It(C),
  // 关闭弹窗后
  afterPopupClosed: () => !0
}, Pt = ["title"], xt = ["title"], Gt = ["title"], Dt = ["title"], Mt = ["title"], Tt = ["title"], Ot = /* @__PURE__ */ De({
  __name: "pick-popup",
  props: {
    pickedFeatures: {
      type: Array
    },
    nameWidth: {
      type: Number
    },
    valueWidth: {
      type: Number
    },
    featureTreeData: {
      type: Array
    },
    zoomIn: {
      type: Function
    },
    highlightStyleFeature: {
      type: Function
    },
    pickPopupClose: {
      type: Function
    },
    closePopup: {
      type: Function
    }
  },
  setup(l) {
    const S = l, v = Oe("pick-popup"), c = fe(0), m = fe(!1), C = fe(null), B = Me({ width: "0", height: "0", overflow: "hidden" }), O = Q(() => S.pickedFeatures[c.value]), Y = Q(() => !O.value.graphic), V = Q(() => {
      const { graphic: y, attributes: h } = O.value;
      return y ? Object.entries(y.attributes).map(([F, f]) => ({
        name: F,
        value: f
      })) : {
        listData: [
          {
            name: "坐标X",
            value: h.graphicCoordinates.x
          },
          {
            name: "坐标Y",
            value: h.graphicCoordinates.y
          },
          {
            name: "行",
            value: h.row
          },
          {
            name: "列",
            value: h.column
          },
          {
            name: "波段数",
            value: h.bounds.length
          }
        ].concat(
          h.bounds.map((f, M) => ({
            name: `波段${M + 1}`,
            value: f
          }))
        )
      };
    }), ee = Q(() => {
      const { layer: y } = O.value;
      return y.title;
    }), Z = Q(() => {
      const { layer: y } = O.value;
      return y.layer ? `${y.layer.title} / ${y.title}` : y.title;
    }), o = Q(() => `第${c.value + 1}条，共${S.pickedFeatures.length}条`), D = Q(() => S.pickedFeatures.length === 1), U = Q(() => {
      const { key: y } = O.value;
      return [y];
    });
    Te(
      () => c,
      (y) => {
        const h = S.pickedFeatures[y.value];
        S.highlightStyleFeature(h);
      },
      { deep: !0, immediate: !0 }
    );
    function H() {
      c.value + 1 === S.pickedFeatures.length ? c.value = 0 : c.value++;
    }
    function z() {
      c.value - 1 < 0 ? c.value = S.pickedFeatures.length - 1 : c.value--;
    }
    function K() {
      if (m.value = !m.value, m.value) {
        const { width: y, height: h } = C.value.getBoundingClientRect();
        B.width = y + "px", B.height = h + "px";
      }
    }
    function re(y, h) {
      const { id: F, isLeaf: f } = h.node.dataRef;
      if (f) {
        m.value = !m.value;
        const M = S.pickedFeatures.findIndex((N) => N.id === F);
        c.value = M;
      }
    }
    function u() {
      S.closePopup(), S.pickPopupClose();
    }
    return (y, h) => {
      const F = q("mapgis-ui-icon-identity"), f = q("a-flex"), M = q("a-list-item"), N = q("a-list"), se = q("mapgis-ui-color-picker"), E = q("a-tree");
      return W(), ne("div", {
        class: L([b(v).b()])
      }, [
        we($("div", {
          ref_key: "pickPopupContainerRef",
          ref: C
        }, [
          $("div", {
            class: L(b(v).e("header"))
          }, [
            _(f, {
              justify: "space-between",
              gap: "small"
            }, {
              default: T(() => [
                $("span", {
                  class: L(b(v).em("header", "title")),
                  title: Z.value
                }, J(ee.value), 11, Pt),
                _(f, {
                  gap: "small",
                  align: "center"
                }, {
                  default: T(() => [
                    _(F, {
                      title: "关闭",
                      class: L(b(v).em("header", "close")),
                      icon: "mapgis-close",
                      width: 16,
                      height: 16,
                      onClick: u
                    }, null, 8, ["class"])
                  ]),
                  _: 1
                })
              ]),
              _: 1
            })
          ], 2),
          Y.value ? (W(), le(N, {
            key: 1,
            class: L(b(v).e("content")),
            "item-layout": "horizontal",
            "data-source": V.value.listData,
            size: "small"
          }, {
            renderItem: T(({ item: P }) => [
              _(M, {
                class: L(b(v).em("content", "item"))
              }, {
                default: T(() => [
                  $("div", {
                    style: X({ width: `${l.nameWidth}px` }),
                    title: P.name
                  }, J(P.name), 13, Dt),
                  P.type ? ie("", !0) : (W(), ne("div", {
                    key: 0,
                    style: X({ width: `${l.valueWidth}px` }),
                    title: P.value
                  }, J(P.value), 13, Mt)),
                  P.type === "color" ? (W(), ne("div", {
                    key: 1,
                    style: X({ width: `${l.valueWidth}px`, height: "27px" }),
                    title: P.value
                  }, [
                    _(se, {
                      color: P.value,
                      size: "small",
                      disableAlpha: !0,
                      showBorder: !1
                    }, null, 8, ["color"])
                  ], 12, Tt)) : ie("", !0)
                ]),
                _: 2
              }, 1032, ["class"])
            ]),
            _: 1
          }, 8, ["class", "data-source"])) : (W(), le(N, {
            key: 0,
            class: L(b(v).e("content")),
            "item-layout": "horizontal",
            "data-source": V.value,
            size: "small"
          }, {
            renderItem: T(({ item: P }) => [
              _(M, {
                class: L(b(v).em("content", "item"))
              }, {
                default: T(() => [
                  $("div", {
                    style: X({ width: `${l.nameWidth}px` }),
                    title: P.name
                  }, J(P.name), 13, xt),
                  $("div", {
                    style: X({ width: `${l.valueWidth}px` }),
                    title: P.value
                  }, J(P.value), 13, Gt)
                ]),
                _: 2
              }, 1032, ["class"])
            ]),
            _: 1
          }, 8, ["class", "data-source"])),
          $("div", {
            class: L(b(v).e("footer"))
          }, [
            _(f, {
              justify: "space-between",
              gap: "middle",
              align: "center"
            }, {
              default: T(() => [
                _(f, {
                  gap: "middle",
                  align: "center"
                }, {
                  default: T(() => [
                    D.value ? ie("", !0) : (W(), le(f, {
                      key: 0,
                      gap: "middle"
                    }, {
                      default: T(() => [
                        _(F, {
                          title: "上一条",
                          class: L(b(v).em("footer", "icon")),
                          icon: "mapgis-left",
                          width: 16,
                          height: 16,
                          onClick: z
                        }, null, 8, ["class"]),
                        _(F, {
                          title: "下一条",
                          class: L(b(v).em("footer", "icon")),
                          icon: "mapgis-right",
                          width: 16,
                          height: 16,
                          onClick: H
                        }, null, 8, ["class"])
                      ]),
                      _: 1
                    })),
                    O.value.showZoomIn ? (W(), le(F, {
                      key: 1,
                      title: "缩放至",
                      class: L(b(v).em("footer", "icon")),
                      icon: "mapgis-map",
                      width: 16,
                      height: 16,
                      onClick: h[0] || (h[0] = (P) => l.zoomIn(O.value.graphic))
                    }, null, 8, ["class"])) : ie("", !0)
                  ]),
                  _: 1
                }),
                D.value ? ie("", !0) : (W(), ne("div", {
                  key: 0,
                  class: L(b(v).em("footer", "total")),
                  title: "显示列表",
                  onClick: K
                }, [
                  _(f, {
                    gap: "small",
                    align: "center"
                  }, {
                    default: T(() => [
                      _(F, {
                        icon: "mapgis-unorderedlist",
                        width: 16,
                        height: 16
                      }),
                      $("span", null, J(o.value), 1)
                    ]),
                    _: 1
                  })
                ], 2))
              ]),
              _: 1
            })
          ], 2)
        ], 512), [
          [_e, !m.value]
        ]),
        we($("div", {
          style: X(B)
        }, [
          _(f, {
            justify: "space-between",
            gap: "small"
          }, {
            default: T(() => [
              _(f, {
                gap: "middle",
                align: "center"
              }, {
                default: T(() => [
                  _(F, {
                    title: "返回",
                    class: L(b(v).em("footer", "icon")),
                    icon: "mapgis-left",
                    width: 16,
                    height: 16,
                    onClick: K
                  }, null, 8, ["class"]),
                  $("span", null, [
                    $("b", null, J(`要素（${l.pickedFeatures.length}）`), 1)
                  ])
                ]),
                _: 1
              })
            ]),
            _: 1
          }),
          _(E, {
            class: L(b(v).e("tree-content")),
            "tree-data": l.featureTreeData,
            selectedKeys: U.value,
            defaultExpandAll: "",
            onSelect: re
          }, null, 8, ["class", "tree-data", "selectedKeys"])
        ], 4), [
          [_e, m.value]
        ])
      ], 2);
    };
  }
}), $t = /* @__PURE__ */ $e(Ot, [["__scopeId", "data-v-151e42a8"]]), Nt = (l, S) => {
  const v = st(), { viewState: c, zondy: m, map: C } = pt(), { createMapElement: B, destroyMapElement: O } = dt(), { Cesium: Y, sceneView: V } = c.engineContext.cesium, { Feature: ee, FeatureSet: Z } = m, { LayerType: o, SubLayerType: D, ViewEventType: U, MapEventType: H, GeometryType: z } = m.enum, { Geometry: K, Projection: re } = m.geometry, u = Me({
    // 是否开启拾取
    enablePick: !1,
    // 拾取显示样式
    pickShowStyle: null,
    // 拾取要素树结构展示数据
    featureTreeData: [],
    // 当前显示的要素列表
    currentShowFeatures: null,
    // 构建多图层查询参数
    layersParams: null
  });
  let y, h = [];
  const F = {};
  let f, M, N;
  const se = "mapgis-pick--loading";
  let E;
  const P = [
    o.IGSImage,
    o.IGSMapImage,
    o.IGSFeature,
    o.ArcGISMapImage,
    o.M3DModelCache,
    o.IGSScene,
    o.cesium3DTilesModelCache
  ];
  !l.pickShowStyle || !Object.keys(l.pickShowStyle).length ? u.pickShowStyle = { ...ye } : u.pickShowStyle = { ...ye, ...l.pickShowStyle }, Te(
    () => [l.pickLayers, l.pickLayerIds],
    () => {
      he();
    }
  ), ot(() => {
    C.on(H.layerChange, me), C.on(H.layerLoaded, ge), Ae();
  }), lt(() => {
    oe(), C.off(H.layerChange, me), C.off(H.layerLoaded, ge);
  }), ct(() => {
    oe();
  });
  function Ne() {
    u.enablePick || (u.enablePick = !0, ue());
  }
  function oe() {
    u.enablePick = !1, te(), Re(), nt(), O(se);
  }
  function Ee() {
    u.enablePick = !u.enablePick, u.enablePick || oe(), u.enablePick && ue();
  }
  function Ae() {
    he(), u.enablePick && ue();
  }
  async function he() {
    if (l.pickLayers)
      h = [...l.pickLayers];
    else if (l.pickLayerIds) {
      h = [];
      const e = l.pickLayerIds.map(async (t) => {
        await ft({
          layerId: t.layerId,
          sublayerId: void 0,
          map: C,
          callback: (i) => {
            i && (t.sublayerIds && t.sublayerIds.length ? t.sublayerIds.forEach((a) => {
              const s = i.findSublayerById(a);
              h.push(s);
            }) : h.push(i));
          }
        });
      });
      await Promise.all(e);
    }
    pe();
  }
  function me(e) {
    (e.moved.length > 0 || e.added.length > 0 || e.removed.length > 0) && pe();
  }
  function ge() {
    pe();
  }
  function ue() {
    c.view.on(U.click, Se);
  }
  function Re() {
    c.view.off(U.click, Se);
  }
  async function Se(e) {
    ze(e.x, e.y), setTimeout(async () => {
      await je(e), Qe();
    }, 10);
  }
  async function je(e) {
    if (M && f.remove(M), !e)
      return;
    const t = c.view.hitTest({
      x: e.x,
      y: e.y
    }), i = h.filter((n) => {
      if ([D.ArcGISMapImageSub, D.IGSMapImageSub].includes(n.type) && !["Group", "Group Layer"].includes(n.originLayerType) || [o.ArcGISMapImage, o.IGSMapImage, o.IGSImage, o.IGSFeature].includes(n.type))
        return !(!n.visible || n.type === o.IGSFeature && C.findLayerById(n.id));
    });
    let a;
    c.viewMode === "3D" ? a = K.reduceDimension(e.mapPoint) : a = e.mapPoint;
    const s = yt(m, a), r = i.filter((n) => {
      const p = re.project(n.extent, a.spatialReference), { xmax: x, xmin: A, ymax: R, ymin: j } = p, ae = kt([
        [
          [Number(A), Number(j)],
          [Number(x), Number(j)],
          [Number(x), Number(R)],
          [Number(A), Number(R)],
          [Number(A), Number(j)]
        ]
      ]);
      if (!wt(ae, s) || _t(ae, s))
        return !0;
    }), g = r.filter(
      (n) => [o.ArcGISMapImage, o.IGSMapImage, o.IGSImage, o.IGSFeature].includes(n.type)
    ), I = g.map((n) => n.id);
    qe(g);
    const d = r.filter(
      (n) => [D.ArcGISMapImageSub, D.IGSMapImageSub].includes(n.type) && !["Group", "Group Layer"].includes(n.originLayerType) && n.visible
    ), w = Ve(d), G = [...I, ...w], k = {};
    for (const n of G)
      try {
        const { layerService: p, layerQueryMethodName: x, updateLayerQueryOptions: A } = F[n];
        let R = await p[x](
          A({ geometry: a, layer: p.layer })
        );
        if (R instanceof Array)
          p.layer.type === o.ArcGISMapImage && (R = Be(R)), k[n] = R.map((j) => {
            if ([o.IGSMapImage, o.ArcGISMapImage].includes(p.layer.type))
              return j.layer = p.layer.findSublayerById(j.id), j;
            if (p.layer.type === o.IGSFeature)
              return {
                graphic: j,
                layer: p.layer
              };
          });
        else {
          const j = {
            x: e.x,
            y: e.y
          }, ae = {
            x: a.coordinates[0],
            y: a.coordinates[1]
          }, rt = {
            attributes: { imageCoordinates: j, graphicCoordinates: ae, ...R },
            layer: p.layer
          };
          k[n] = [rt];
        }
      } catch {
      }
    if (t)
      for (const n of t) {
        const { layer: p } = n;
        if (n.graphic instanceof Promise)
          try {
            n.graphic = await n.graphic;
          } catch {
            continue;
          }
        k[p.id] ? k[p.id].push(Le(n)) : k[p.id] = [Le(n)];
      }
    He(k), Ye(We(e.mapPoint)), S("pickedFeatures", { pickedFeatures: u.currentShowFeatures, pickedFeaturesTree: u.featureTreeData });
  }
  function We(e) {
    let t;
    return e.spatialReference.wkid === 4326 ? t = e : t = re.project(
      e,
      new m.SpatialReference({
        wkid: 4326
      })
    ), t.coordinates;
  }
  function Be(e) {
    const t = [], i = {};
    return e.forEach((a) => {
      const s = String(a.layerId);
      i[s] || (i[s] = []), i[s].push(a.feature);
    }), Object.keys(i).forEach((a) => {
      const s = new Z({ features: i[a].reverse() });
      t.push({ id: String(a), featureSet: s });
    }), t;
  }
  function ze(e, t) {
    E || (E = B(
      "div",
      se,
      "position: absolute; left: 0; top: 0;padding: 8px"
    )), E.style.display = "block", E.style.left = e - 8 + "px", E.style.top = t - 8 + "px", E.style.animationPlayState = "running";
  }
  function Qe() {
    E && (E.style.display = "none", E.style.animationPlayState = "paused");
  }
  function pe() {
    const e = C.layers.items.filter((t) => P.includes(t.type) && t.visible);
    !l.pickLayers && !l.pickLayerIds && (h = e), S("pickLayers", h);
  }
  function qe(e) {
    e.forEach((t) => {
      const i = t.allSublayers ? Je(t.allSublayers.items) : [];
      be(
        t,
        i.filter((a) => a.visible).map((a) => a.id),
        !0
      );
    });
  }
  function Je(e) {
    let t = e.filter(
      (a) => a.visible && !["Group", "Group Layer"].includes(a.originLayerType)
    );
    const i = e.filter(
      (a) => ["Group", "Group Layer"].includes(a.originLayerType) && !a.visible
    );
    return i.length && i.forEach((a) => {
      t = t.filter((s) => !Ie(s, a));
    }), t;
  }
  function Ie(e, t) {
    var i, a;
    return ((i = e == null ? void 0 : e.parent) == null ? void 0 : i.id) === t.id ? !0 : (a = e == null ? void 0 : e.parent) != null && a.parent ? Ie(e.parent, t) : !1;
  }
  function Ve(e) {
    const t = {};
    return e.forEach((i) => {
      const a = i.layer.id;
      t[a] ? t[a].sublayerIds.push(i.id) : t[a] = { layer: i.layer, sublayerIds: [i.id] };
    }), Object.keys(t).forEach((i) => {
      const a = t[i];
      be(a.layer, a.sublayerIds);
    }), Object.keys(t);
  }
  function be(e, t, i = !1) {
    F[e.id] ? Ue(e, t, i) : Ze(e, t);
  }
  function Ze(e, t) {
    const i = e.type;
    let a, s, r, g;
    switch (i) {
      case o.IGSMapImage:
      case o.ArcGISMapImage:
        a = ht(e), s = "queryFeaturesInLayers";
        const I = [...new Set(t)].map((d) => ({ layerId: d }));
        r = {
          layerDefs: I.length ? I : null,
          geometry: null,
          distance: void 0
        }, i === o.ArcGISMapImage && (r.imageDisplay = `${c.view.width},${c.view.height},96`), g = {
          layerService: a,
          layerQueryMethodName: s,
          layerQueryOptions: r,
          updateLayerQueryOptions: ({ geometry: d, layer: w }) => (r.geometry = d, w.type === o.ArcGISMapImage ? (r.imageDisplay = `${c.view.width},${c.view.height},96`, r.distance = mt(
            m,
            c,
            d,
            l.bufferDistance,
            l.bufferUnit
          )) : r.distance = Pe(
            m,
            c,
            d,
            l.bufferDistance,
            l.bufferUnit
          ), r)
        };
        break;
      case o.IGSFeature:
        a = Ce(e), s = "queryFeatures", r = { geometry: null, distance: void 0 }, g = {
          layerService: a,
          layerQueryMethodName: s,
          layerQueryOptions: r,
          updateLayerQueryOptions: ({ geometry: d }) => (r.geometry = d, r.distance = Pe(
            m,
            c,
            d,
            l.bufferDistance,
            l.bufferUnit
          ), r)
        };
        break;
      case o.IGSImage:
        a = Ce(e), s = "getRasterValue", r = {
          x: 0,
          y: 0
        }, g = {
          layerService: a,
          layerQueryMethodName: s,
          layerQueryOptions: r,
          updateLayerQueryOptions: ({ geometry: d }) => {
            const { coordinates: w } = d;
            return r.x = w[0], r.y = w[1], r;
          }
        };
        break;
    }
    F[e.id] = g;
  }
  function Ue(e, t, i) {
    switch (e.type) {
      case o.IGSMapImage:
      case o.ArcGISMapImage:
        const { layerQueryOptions: s } = F[e.id];
        if (i)
          s.layerDefs = t.map((r) => ({ layerId: r }));
        else {
          const r = s.layerDefs ? t.filter((g) => !s.layerDefs.find((I) => I.layerId === g)) : t;
          r.length && (s.layerDefs ? s.layerDefs.push(
            ...r.map((g) => ({ layerId: g }))
          ) : s.layerDefs = r.map((g) => ({ layerId: g })));
        }
        break;
      case o.IGSFeature:
      case o.IGSImage:
        break;
    }
  }
  function He(e) {
    const t = Object.keys(e);
    if (u.featureTreeData = [], t && t.length) {
      let i = [];
      h.forEach((a) => {
        t.includes(a.id) && i.push(a.id);
      }), i = i.reverse(), i.forEach((a) => {
        const s = h.find((r) => r.id === a);
        Ke(s, e[a]);
      });
    }
  }
  function Ke(e, t) {
    const i = de(e, t);
    u.featureTreeData.push(i);
  }
  function de(e, t, i = "") {
    var a, s, r, g;
    if ((a = e.sublayers) != null && a.items && ((s = e.sublayers.items) != null && s.length) || Fe(e.type)) {
      if (e.layer)
        return e.sublayers.items.map((I) => ({
          id: `${i}-${I.id}`,
          key: `${i}-${I.id}`,
          title: I.title,
          children: de(I, t, i)
        })).filter((I) => I.children && I.children.length).reverse();
      {
        const I = Fe(e.type) ? (g = (r = e.activeScene) == null ? void 0 : r.sublayers) == null ? void 0 : g.items : e.sublayers.items;
        return {
          id: e.id,
          key: e.id,
          title: e.title,
          children: I.map((d) => ({
            id: `${e.id}-${d.id}`,
            key: `${e.id}-${d.id}`,
            title: d.title,
            children: de(d, t, e.id)
          })).filter((d) => d.children && d.children.length).reverse()
        };
      }
    } else {
      let I = [];
      const d = t.find((w) => w.layer.id === e.id);
      if (d) {
        let w;
        [D.IGSMapImageSub, D.ArcGISMapImageSub].includes(e.type) && (w = d.featureSet.features), w && w.length && (I = w.map((G) => {
          const k = G.attributes.FID || G.attributes.fid || G.attributes.OBJECTID || G.attributes.objectid;
          return {
            id: G.id,
            key: G.id,
            title: `要素ID: ${k}`,
            graphic: G,
            layer: d.layer,
            isLeaf: !0,
            showZoomIn: !0
          };
        }).reverse());
      }
      if (e.type === D.IGSSceneSubM3DCache) {
        const w = t.filter((G) => {
          var k;
          return ((k = G.sublayer) == null ? void 0 : k.id) === e.id;
        });
        w && w.length && (I = w.map((G) => {
          const { graphic: k, sublayer: n } = G;
          let p;
          return k.attributes.OID !== void 0 ? p = k.attributes.OID : k.attributes.tid !== void 0 && (p = k.attributes.tid), {
            id: k.id,
            key: k.id,
            title: `要素ID: ${p}`,
            graphic: k,
            layer: n,
            isLeaf: !0,
            showZoomIn: !1
          };
        }).reverse());
      }
      if (e.layer)
        return I;
      {
        const w = (n) => {
          const { attributes: p } = n.graphic;
          let x;
          return p.FID !== void 0 ? x = p.FID : p.OID !== void 0 ? x = p.OID : p.tid !== void 0 && (x = p.tid), x;
        }, G = (n) => {
          const { layer: p } = n;
          return ![o.M3DModelCache, o.cesium3DTilesModelCache, o.IGSImage].includes(p.type);
        }, k = (n) => {
          const { layer: p, attributes: x } = n;
          if (o.IGSImage === p.type) {
            const { row: A, column: R } = x;
            return `行: ${A}，列: ${R}`;
          } else
            return `要素ID: ${w(n)}`;
        };
        return {
          id: e.id,
          title: e.title,
          children: t.map((n) => {
            var A;
            const p = G(n), x = ((A = n.graphic) == null ? void 0 : A.id) || bt();
            return n.title = k(n), n.id = x, n.key = x, n.isLeaf = !0, n.showZoomIn = p, n;
          })
        };
      }
    }
  }
  function Xe(e, t, i, a, s) {
    te();
    const r = {
      pickedFeatures: e,
      popupOptions: {
        component: u.pickShowStyle.popupStyle.component,
        anchor: u.pickShowStyle.popupStyle.anchor,
        nameWidth: u.pickShowStyle.popupStyle.nameWidth,
        valueWidth: u.pickShowStyle.popupStyle.valueWidth,
        prevent: !l.showPickPopup
      }
    };
    S("beforePopupOpen", r), r.popupOptions.prevent || (y = gt(
      c.engine,
      c.engineContext,
      {
        longitude: t,
        latitude: i
      },
      {
        anchor: r.popupOptions.anchor,
        offset: [a, s],
        content: r.popupOptions.component || $t,
        props: {
          pickedFeatures: e,
          nameWidth: r.popupOptions.nameWidth,
          valueWidth: r.popupOptions.valueWidth,
          featureCount: u.currentShowFeatures.length,
          featureTreeData: u.featureTreeData,
          zoomIn: et,
          highlightStyleFeature: tt,
          pickPopupClose: at
        }
      },
      v
    ), y.openPopup());
  }
  function te() {
    y && (y.closePopup(), y = null), M && (f.remove(M), M = null), N && (N.style = null, N = null), S("afterPopupClosed");
  }
  function Ye(e) {
    u.featureTreeData && u.featureTreeData.length ? (u.currentShowFeatures = [], u.featureTreeData.forEach((t) => {
      const i = ve(t);
      u.currentShowFeatures.push(...i);
    }), u.currentShowFeatures.length ? Xe(u.currentShowFeatures, e[0], e[1], 0, 0) : te()) : te();
  }
  function ve(e) {
    if (!e.children && e.isLeaf)
      return [e];
    let t = [];
    for (const i of e.children)
      t = t.concat(ve(i));
    return t;
  }
  function et(e) {
    const t = K.fromJSON(e.geometry).extent;
    c.view.flyTo({ extent: t });
  }
  function tt(e) {
    if (!l.enableHighlight)
      return;
    const { graphic: t, layer: i } = e;
    if ([D.ArcGISMapImageSub, D.IGSMapImageSub, o.IGSFeature, o.IGSImage].includes(
      i.type
    )) {
      f ? f.remove(M) : (f = new m.layer.GraphicsLayer(), c.view.graphicsLayers.add(f));
      let a;
      if (t) {
        const s = t.toJSON();
        delete s.id, a = ee.fromJSON(s), ke(a), f.add(a);
      } else {
        const {
          graphicCoordinates: { x: s, y: r }
        } = e.attributes, g = 0.01, I = [
          s - g / 2,
          // 最小经度
          r - g / 2,
          // 最小纬度
          s + g / 2,
          // 最大经度
          r + g / 2
          // 最大纬度
        ], { geometry: d } = Lt(I);
        a = new ee({ geometry: K.fromJSON(d) }), ke(a), f.add(a);
      }
      M = a;
    } else {
      N && (N.style = null);
      const a = V.getInnerLayer(i.layer ? i.layer : i, i.layer ? i : void 0);
      let s, r;
      const g = u.pickShowStyle.highlightFeatureStyle.fill.color;
      a.version === "2.1" ? (s = t.attributes.tid, r = [["${tid} === ${id}", g]]) : (s = t.attributes.OID, r = [["${OID} === ${id}", g]]), a.style = new Y.Cesium3DTileStyle({
        defines: {
          id: s
        },
        color: {
          conditions: r
        }
      }), N = a;
    }
  }
  function at() {
    te();
  }
  function ke(e) {
    it(e, u.pickShowStyle.highlightFeatureStyle);
  }
  function it(e, t) {
    const { geometry: i } = e;
    let a;
    if (i !== null) {
      switch (i.type) {
        case z.point:
        case z.multiPoint:
          a = m.symbol.Symbol.fromJSON(t.marker);
          break;
        case z.lineString:
        case z.multiLineString:
          a = m.symbol.Symbol.fromJSON(t.line);
          break;
        case z.polygon:
        case z.multiPolygon:
          a = m.symbol.Symbol.fromJSON(t.fill);
          break;
      }
      e.symbol = a;
    }
  }
  function nt() {
    f && (c.view.graphicsLayers.remove(f), f = null);
  }
  return {
    ...ut(u),
    handlePickChangeClick: Ee,
    start: Ne,
    clearState: oe
  };
}, Et = /* @__PURE__ */ De({
  name: "MapgisPick",
  __name: "pick",
  props: Ct,
  emits: Ft,
  setup(l, { expose: S, emit: v }) {
    const c = l, m = v, C = Oe("pick"), { enablePick: B, handlePickChangeClick: O, start: Y, clearState: V } = Nt(c, m);
    return S({
      start: Y,
      clearState: V
    }), (ee, Z) => {
      const o = q("mapgis-ui-iconfont"), D = q("a-tooltip");
      return W(), ne("div", {
        class: L([b(C).b()])
      }, [
        _(D, {
          title: b(B) ? "关闭拾取" : "开启拾取"
        }, {
          default: T(() => [
            $("div", {
              class: L([b(C).e("button"), b(B) ? b(C).em("button", "pick") : ""]),
              onClick: Z[0] || (Z[0] = //@ts-ignore
              (...U) => b(O) && b(O)(...U))
            }, [
              _(o, { type: "mapgis-search" })
            ], 2)
          ]),
          _: 1
        }, 8, ["title"])
      ], 2);
    };
  }
}), qt = /* @__PURE__ */ $e(Et, [["__scopeId", "data-v-f6061a88"]]);
export {
  qt as P,
  Ct as a,
  Ft as p,
  Nt as u
};
