import { reactive as O, toRefs as S, defineComponent as _, resolveComponent as I, openBlock as V, createElementBlock as B, normalizeClass as w, unref as e, renderSlot as z, createVNode as C, withCtx as h, createElementVNode as k } from "vue";
import { u as L, E as c, b as R } from "./layer-select-Ba4IEiWY.js";
import "@mapgis/webclient-common";
var i = /* @__PURE__ */ ((a) => (a[a.ZoomIn = 0] = "ZoomIn", a[a.ZoomOut = 1] = "ZoomOut", a))(i || {});
const E = {
  /**
   * @description 是否开启级别吸附，当前只对mapboxgl引擎有效，默认关闭，开启后，放大缩小滚轮，都会确保缩放级别为整数
   */
  enableZoomSnap: {
    type: Boolean,
    default: !1
  }
}, N = {}, G = (a, M) => {
  const { viewState: o } = L(), m = O({
    // mapboxgl级别吸附配置是否已配置到引擎上
    mapboxglZoomSnapConfigured: !1
  });
  let s = null;
  function p() {
    switch (o.engine) {
      case c.Cesium:
        n(i.ZoomIn);
        break;
      case c.MapboxGL:
        Z(i.ZoomIn);
        break;
      case c.Leaflet:
        g(i.ZoomIn);
        break;
    }
  }
  function f() {
    switch (o.engine) {
      case c.Cesium:
        n(i.ZoomOut);
        break;
      case c.MapboxGL:
        Z(i.ZoomOut);
        break;
      case c.Leaflet:
        g(i.ZoomOut);
        break;
    }
  }
  function b() {
    s = setInterval(() => p(), 50);
  }
  function r() {
    s = setInterval(() => f(), 50);
  }
  function v() {
    s && (clearInterval(s), s = null);
  }
  function n(l) {
    const u = o.engineContext.cesium.viewer.camera.position, x = o.engineContext.cesium.viewer.scene.globe.ellipsoid.cartesianToCartographic(u).height / 20;
    l === i.ZoomIn ? o.engineContext.cesium.viewer.camera.moveForward(x) : o.engineContext.cesium.viewer.camera.moveBackward(x);
  }
  function Z(l) {
    let u = o.view.zoom;
    if (a.enableZoomSnap) {
      if (!m.mapboxglZoomSnapConfigured && o.engineContext.mapboxgl) {
        const d = o.engineContext.mapboxgl.mapView.getInnerView();
        d && (d.scrollZoom.setWheelZoomRate(1), d.scrollZoom.setZoomRate(1), d.transform.resetZoomScale = !1), m.mapboxglZoomSnapConfigured = !0;
      }
      u = Math.ceil(o.view.zoom);
    }
    t(u, l);
  }
  function g(l) {
    t(o.view.zoom, l);
  }
  function t(l, u) {
    o.view.goTo({
      center: o.view.center,
      zoom: u === i.ZoomIn ? Math.min(l + 1, o.view.maxZoom ?? 19) : Math.max(l - 1, o.view.minZoom ?? 0)
    });
  }
  return {
    ...S(m),
    handleZoomIn: p,
    handleZoomOut: f,
    handleContinueZoomIn: b,
    handleContinueZoomOut: r,
    handleClearZoomTimer: v
  };
}, F = /* @__PURE__ */ _({
  name: "MapgisZoom",
  __name: "zoom",
  props: E,
  emits: N,
  setup(a, { emit: M }) {
    const o = a, m = R("zoom"), { handleZoomOut: s, handleZoomIn: p, handleContinueZoomIn: f, handleContinueZoomOut: b, handleClearZoomTimer: r } = G(
      o
    );
    return (v, n) => {
      const Z = I("mapgis-ui-iconfont"), g = I("a-tooltip");
      return V(), B("div", {
        class: w([e(m).b()])
      }, [
        z(v.$slots, "before"),
        C(g, {
          title: "放大",
          placement: "right"
        }, {
          default: h(() => [
            k("div", {
              class: w([e(m).e("button"), e(m).em("button", "zoom-in")]),
              onClick: n[0] || (n[0] = //@ts-ignore
              (...t) => e(p) && e(p)(...t)),
              onMousedown: n[1] || (n[1] = //@ts-ignore
              (...t) => e(f) && e(f)(...t)),
              onMouseup: n[2] || (n[2] = //@ts-ignore
              (...t) => e(r) && e(r)(...t))
            }, [
              C(Z, { type: "mapgis-plus" })
            ], 34)
          ]),
          _: 1
        }),
        C(g, {
          title: "缩小",
          placement: "right"
        }, {
          default: h(() => [
            k("div", {
              class: w([e(m).e("button"), e(m).em("button", "zoom-out")]),
              onClick: n[3] || (n[3] = //@ts-ignore
              (...t) => e(s) && e(s)(...t)),
              onMousedown: n[4] || (n[4] = //@ts-ignore
              (...t) => e(b) && e(b)(...t)),
              onMouseup: n[5] || (n[5] = //@ts-ignore
              (...t) => e(r) && e(r)(...t))
            }, [
              C(Z, { type: "mapgis-minus" })
            ], 34)
          ]),
          _: 1
        }),
        z(v.$slots, "after")
      ], 2);
    };
  }
});
export {
  i as Z,
  F as _,
  E as a,
  G as u,
  N as z
};
