import { defineComponent as z, inject as F, ref as _, onMounted as P, watch as C, computed as k, createBlock as S, createCommentVNode as W, openBlock as N } from "vue";
import { e as V } from "./PictometryPanel-U4v9tQuT.js";
const f = {
  size: 100,
  fillColor: "rgba(0, 102, 255, 0.25)",
  strokeColor: "rgba(0, 102, 255, 0.6)",
  strokeWidth: 1
};
function L(r) {
  const {
    hFov: t,
    size: n = f.size,
    fillColor: s = f.fillColor,
    strokeColor: l = f.strokeColor,
    strokeWidth: o = f.strokeWidth
  } = r, u = Math.min(Math.max(t, 10), 170), m = 30, d = 120, a = 1 - (Math.min(Math.max(u, m), d) - m) / (d - m) * 0.6, c = (n - o * 2) * a, H = u / 2 * Math.PI / 180, g = c * Math.tan(H), h = Math.ceil(g * 2 + o * 2), v = Math.ceil(c + o * 2), p = document.createElement("canvas");
  p.width = h, p.height = v;
  const e = p.getContext("2d");
  if (!e)
    throw new Error("Failed to get canvas 2d context");
  e.clearRect(0, 0, h, v);
  const y = h / 2, I = v - o, w = o, M = y - g, b = y + g;
  return e.beginPath(), e.moveTo(y, I), e.lineTo(M, w), e.lineTo(b, w), e.closePath(), e.fillStyle = s, e.fill(), e.strokeStyle = l, e.lineWidth = o, e.stroke(), e.getImageData(0, 0, h, v);
}
function x(r) {
  return `cyclomedia-viewcone-${Math.round(r)}`;
}
const j = /* @__PURE__ */ z({
  __name: "CyclomediaViewcone",
  props: {
    position: {},
    yaw: { default: 0 },
    hFov: { default: 80 },
    iconSize: { default: 0.5 }
  },
  setup(r) {
    const t = r, n = F("map"), s = F("isLoaded"), l = _(!1);
    let o = null;
    async function u(i) {
      if (!n?.value) return;
      const a = x(i);
      if (n.value.hasImage(a)) {
        o = a, l.value = !0;
        return;
      }
      try {
        const c = L({ hFov: i, size: 100 });
        n.value.addImage(a, c), o = a, l.value = !0;
      } catch {
      }
    }
    P(async () => {
      !n || !n.value || s && (s.value || await new Promise((i) => {
        const a = C(s, (c) => {
          c && (a(), i());
        });
      }), await u(t.hFov));
    }), C(
      () => t.hFov,
      async (i) => {
        !n?.value || !s?.value || await u(i);
      }
    );
    const m = k(() => t.position ? {
      type: "geojson",
      data: {
        type: "Feature",
        geometry: {
          type: "Point",
          coordinates: t.position
        },
        properties: {}
      }
    } : {
      type: "geojson",
      data: {
        type: "FeatureCollection",
        features: []
      }
    }), d = k(() => ({
      "icon-image": o || x(t.hFov),
      "icon-size": t.iconSize,
      "icon-anchor": "bottom",
      "icon-rotate": t.yaw,
      "icon-rotation-alignment": "map",
      "icon-allow-overlap": !0,
      "icon-ignore-placement": !0
    }));
    return (i, a) => r.position && l.value ? (N(), S(V, {
      key: 0,
      id: "cyclomedia-viewcone",
      source: m.value,
      layout: d.value,
      "before-id": "cyclomedia-camera-icon"
    }, null, 8, ["source", "layout"])) : W("", !0);
  }
});
export {
  j as default
};
