import { defineComponent as L, watch as d, openBlock as Q, createElementBlock as X, normalizeClass as Y, unref as ee, shallowRef as M, ref as f, onMounted as ae, onUnmounted as te, pushScopeId as se, popScopeId as le, createElementVNode as re } from "vue";
import ne from "@amap/amap-jsapi-loader";
import oe from "axios";
import { nanoid as ie } from "nanoid";
import { debounce as z } from "lodash";
const ce = (g) => (se("data-v-8bca31f5"), g = g(), le(), g), de = /* @__PURE__ */ ce(() => /* @__PURE__ */ re("div", {
  id: "zerov-amap-3d",
  class: "zerov-amap-container"
}, null, -1)), ue = [
  de
], ye = L({ name: "zv-scene-amap3d" }), be = /* @__PURE__ */ L({
  ...ye,
  props: {
    basicOption: {},
    sources: {},
    useEvents: {},
    uuid: {}
  },
  emits: [
    "amap3d-scene-success",
    "amap3d-scene-zoomstart",
    "amap3d-scene-zoomend",
    "amap3d-scene-mapclick",
    "amap3d-scene-dragstart",
    "amap3d-scene-dragging",
    "amap3d-scene-dragend",
    "amap3d-scene-pulseLinkLayer"
  ],
  setup(g, { expose: A, emit: P }) {
    const s = g, u = P, I = () => {
      const n = M(), c = M(), S = f(!1), v = f(), p = f(), h = f(), b = f(), C = (a) => {
        E(), window._AMapSecurityConfig = {
          securityJsCode: a.basic.securityJsCode
        }, ne.load({
          key: a.basic.key,
          // 申请好的Web端开发者Key，首次调用 load 时必填
          version: "2.0",
          // 指定要加载的 JSAPI 的版本，缺省时默认为 1.4.15
          Loca: {
            version: "2.0.0"
          },
          plugins: ["AMap.ControlBar", "AMap.ToolBar", "AMap.Scale", "AMap.HeatMap", "AMap.GeoJSON"]
        }).then((e) => {
          b.value = e, n.value = new e.Map("zerov-amap-3d", {
            rotateEnable: a.config.rotateEnable,
            // 是否开启地图旋转交互 鼠标右键 + 鼠标画圈移动 或 键盘Ctrl + 鼠标画圈移动
            pitchEnable: a.config.pitchEnable,
            // 是否开启地图倾斜交互 鼠标右键 + 鼠标上下移动或键盘Ctrl + 鼠标上下移动
            resizeEnable: a.config.resizeEnable,
            zoomEnable: a.config.zoomEnable,
            dragEnable: a.config.dragEnable,
            zoom: a.config.zoom,
            // 初始化地图层级
            viewMode: "3D",
            // 开启3D视图,默认为关闭
            zooms: a.config.zooms,
            // 地图显示的缩放级别范围
            center: a.config.center,
            // 初始地图中心经纬度
            mapStyle: a.config.mapStyle,
            features: a.config.features,
            pitch: a.config.pitch,
            // 0-83
            rotation: a.config.rotation,
            // 0-360
            wallColor: a.config.floors.wallColor,
            roofColor: a.config.floors.roofColor,
            skyColor: a.config.skyColor
          }), c.value = new window.Loca.Container({
            map: n.value
          }), h.value = new b.value.Scale({
            visible: a.config.plugin.scale.visible,
            position: {
              left: a.config.plugin.scale.position.left + "px",
              bottom: a.config.plugin.scale.position.bottom + "px"
            }
          }), n.value.addControl(h.value), v.value = new e.ControlBar({
            visible: a.config.plugin.controlBar.visible,
            showControlButton: a.config.plugin.controlBar.showControlButton,
            position: {
              right: a.config.plugin.controlBar.position.right + "px",
              top: a.config.plugin.controlBar.position.top + "px"
            }
          }), n.value.addControl(v.value), p.value = new e.ToolBar({
            visible: a.config.plugin.toolBar.visible,
            position: {
              left: a.config.plugin.toolBar.position.left + "px",
              top: a.config.plugin.toolBar.position.top + "px"
            }
          }), n.value.addControl(p.value), x(e), n.value.on("complete", () => {
            setTimeout(() => {
              S.value = !0, u("amap3d-scene-success"), window.SHJParseEvent(s.useEvents, "amap3d-scene-success", null);
            }, 666);
          }), n.value.on("zoomstart", () => {
            u("amap3d-scene-zoomstart"), window.SHJParseEvent(s.useEvents, "amap3d-scene-zoomstart", null);
          }), n.value.on("zoomend", () => {
            u("amap3d-scene-zoomend"), window.SHJParseEvent(s.useEvents, "amap3d-scene-zoomend", null);
          }), n.value.on("click", (t) => {
            u("amap3d-scene-mapclick", t.lnglat), window.SHJParseEvent(s.useEvents, "amap3d-scene-mapclick", t.lnglat);
          }), n.value.on("dragstart", (t) => {
            u("amap3d-scene-dragstart", t.lnglat), window.SHJParseEvent(s.useEvents, "amap3d-scene-dragstart", t.lnglat);
          }), n.value.on("dragend", (t) => {
            u("amap3d-scene-dragend", t.lnglat), window.SHJParseEvent(s.useEvents, "amap3d-scene-dragend", t.lnglat);
          });
        }).catch((e) => {
        });
      }, x = z((a) => {
        s.sources && s.sources.length > 0 ? window.SHJDatasourceV2({
          tId: s.uuid,
          sources: s.sources,
          callback: (e) => {
            try {
              const t = s.basicOption.widgets.find((l) => l._sourceId === e.id);
              t && t.type === "heatmap" && D(window.Loca, t, y(e.data[0].data, "Point")), t && t.type === "dotlayers" && F(window.Loca, t, y(e.data[0].data, "Point")), t && t.type === "scatter" && N(window.Loca, t, y(e.data[0].data, "Point")), t && t.type === "labelsLayer" && G(window.Loca, t, y(e.data[0].data, "Point")), t && t.type === "signagePoints" && Z(window.Loca, t, y(e.data[0].data, "Point")), t && t.type === "pulseLinkLayer" && R(window.Loca, t, y(e.data[0].data, "LineString"));
            } catch {
            }
            s.basicOption.widgets.filter((t) => t.type === "boundary").forEach((t) => {
              O(a, t);
            });
          }
        }) : s.basicOption.widgets.filter((e) => e.type === "boundary").forEach((e) => {
          O(a, e);
        });
      }, 200), H = (a) => {
        const t = a.slice(a.indexOf("(") + 1, a.lastIndexOf(")")).split(",").map((r) => r.trim()), l = {};
        for (let r = 1; r < t.length; r++) {
          const o = t[r].split(" "), i = o[0], w = parseFloat(o[1]) / 100, K = Math.round(w * 100) / 100;
          l[K] = i;
        }
        return l;
      }, D = (a, e, t) => {
        try {
          const l = new a.HeatMapLayer({
            zIndex: 10,
            opacity: e.opacity,
            visible: !0,
            zooms: [2, 22]
          }), r = new a.GeoJSONSource({
            data: t
          });
          l.setSource(r, {
            radius: e.style.radius,
            unit: e.style.unit,
            height: e.style.height,
            opacity: e.style.opacity,
            gradient: H(e.style.gradient),
            value: function(o, i) {
              return i.coordinates[2] || 0;
            },
            min: e.style.min,
            max: e.style.max,
            // 4.6
            heightBezier: [0, 0.53, 0.37, 0.98]
          }), c.value.add(l);
        } catch {
        }
      }, O = async (a, e) => {
        try {
          const t = await oe.get(e.geojson);
          if (t.status === 200) {
            const l = new a.GeoJSON({
              geoJSON: t.data,
              getPolygon: function(r, o) {
                const i = new a.Polygon({
                  path: o,
                  zIndex: e.zIndex,
                  fillColor: e.style.fillColor,
                  // 填充色
                  strokeOpacity: e.style.strokeOpacity,
                  // 轮廓线透明度
                  fillOpacity: e.style.fillOpacity,
                  // 填充色透明度
                  strokeColor: e.style.strokeColor,
                  // 线条颜色
                  strokeWeight: e.style.strokeWeight,
                  // 线条宽度
                  strokeStyle: e.style.strokeStyle
                  // 线条样式
                });
                return i.on("mouseover", () => {
                  i.setOptions({
                    fillOpacity: e.mouseover.fillOpacity,
                    fillColor: e.mouseover.fillColor,
                    strokeOpacity: e.mouseover.strokeOpacity,
                    strokeColor: e.mouseover.strokeColor,
                    strokeStyle: e.mouseover.strokeStyle,
                    strokeWeight: e.mouseover.strokeWeight
                  });
                }), i.on("mouseout", () => {
                  i.setOptions({
                    fillColor: e.style.fillColor,
                    // 填充色
                    strokeOpacity: e.style.strokeOpacity,
                    // 轮廓线透明度
                    fillOpacity: e.style.fillOpacity,
                    // 填充色透明度
                    strokeColor: e.style.strokeColor,
                    // 线条颜色
                    strokeWeight: e.style.strokeWeight,
                    // 线条宽度
                    strokeStyle: e.style.strokeStyle
                    // 线条样式
                  });
                }), i;
              }
            });
            n.value.add(l);
          }
        } catch {
        }
      }, F = (a, e, t) => {
        try {
          const l = new a.GeoJSONSource({
            data: t
          }), r = new a.PointLayer({
            zIndex: e.zIndex,
            blend: e.blend,
            visible: e.visible,
            opacity: e.opacity
          }), o = {
            radius: e.style.radius,
            unit: e.style.unit,
            color: e.style.color,
            borderWidth: e.style.borderWidth,
            blurWidth: e.style.blurWidth,
            borderColor: e.style.borderColor
          };
          r.setSource(l), r.setStyle(o), c.value.add(r), r.addAnimate({
            key: e.animate.key,
            value: e.animate.value,
            duration: e.animate.duration,
            easing: e.animate.easing,
            transform: e.animate.transform,
            random: e.animate.random,
            delay: e.animate.delay,
            yoyo: e.animate.yoyo,
            repeat: e.animate.repeat
          });
        } catch {
        }
      }, N = (a, e, t) => {
        try {
          const l = new a.GeoJSONSource({
            data: t
          }), r = new a.ScatterLayer({
            loca: c.value,
            zIndex: e.zIndex,
            opacity: e.opacity,
            visible: e.visible,
            zooms: e.zooms
          });
          r.setSource(l), r.setStyle({
            unit: e.style.unit,
            size: e.style.size,
            borderWidth: e.style.borderWidth,
            texture: e.style.texture,
            duration: e.style.duration,
            animate: e.style.animate
          }), c.value.animate.start();
        } catch {
        }
      }, G = (a, e, t) => {
        try {
          const l = new a.GeoJSONSource({
            data: t
          }), r = new a.LabelsLayer({
            eventSupport: !0,
            visible: e.visible,
            zooms: e.zooms,
            opacity: e.opacity,
            collision: e.collision,
            allowCollision: e.allowCollision,
            zIndex: e.zIndex
          });
          r.on("click", (o) => {
          }), r.setSource(l), r.setStyle({
            icon: {
              image: e.icon.image,
              size: e.icon.size,
              clipOrigin: e.icon.clipOrigin,
              offset: e.icon.offset,
              anchor: e.icon.anchor
            },
            text: {
              // 每项配置都可使用回调函数来动态配置
              content: (o, i) => i.properties[e.text.content],
              zooms: e.text.zooms,
              offset: e.text.offset,
              direction: e.text.direction,
              style: {
                fontSize: e.text.style.fontSize,
                fillColor: e.text.style.fillColor,
                strokeColor: e.text.style.strokeColor,
                strokeWidth: e.text.style.strokeWidth,
                padding: e.text.style.padding,
                backgroundColor: e.text.style.backgroundColor,
                borderColor: e.text.style.borderColor,
                borderWidth: e.text.style.borderWidth,
                fold: e.text.style.fold,
                fontWeight: e.text.style.fontWeight
              }
            }
          }), c.value.add(r);
        } catch {
        }
      }, Z = (a, e, t) => {
        try {
          const l = new a.GeoJSONSource({
            data: t
          }), r = new a.ZMarkerLayer({
            zIndex: e.signs.zIndex,
            visible: e.signs.visible,
            zooms: e.signs.zooms,
            opacity: e.signs.opacity,
            depth: !1
          });
          r.setSource(l), r.setStyle({
            content: (i, w) => `<div style="
                                width: ${e.signs.style.width}px; 
                                height: ${e.signs.style.height + 148}px;
                            ">
                            <p style="
                                display: block;
                                height:${e.signs.style.height}px;
                                background-image:${e.signs.style.background};
                                border:${e.signs.style.borderWidth}px ${e.signs.style.borderStyle} ${e.signs.style.borderColor};
                                border-radius: ${e.signs.style.borderRadius}px;
                                line-height:${e.signs.style.lineHeight}px;
                                text-align:${e.signs.style.textAlign};
                                font-size:${e.signs.style.fontSize}px;
                                color:${e.signs.style.fillColor};
                                margin:0;
                            ">
                                ${w.properties.name}
                            </p>
                        </div>`,
            unit: e.signs.style.unit,
            rotation: e.signs.style.rotation,
            alwaysFront: e.signs.style.alwaysFront,
            size: [e.signs.style.width, e.signs.style.height + 148],
            altitude: e.signs.style.altitude
          }), c.value.add(r);
          const o = new a.ZMarkerLayer({
            zIndex: e.landmark.zIndex,
            visible: e.landmark.visible,
            zooms: e.landmark.zooms,
            opacity: e.landmark.opacity,
            depth: !1
          });
          o.setSource(l), o.setStyle({
            content: (i, w) => `<div style="
                            width: ${e.landmark.style.size[0]}px;
                            height: ${e.landmark.style.size[1]}px;
                            background: url(${e.landmark.style.image});
                            background-size:contain;
                        ">
                        </div>`,
            unit: e.landmark.style.unit,
            rotation: e.landmark.style.rotation,
            alwaysFront: e.landmark.style.alwaysFront,
            size: e.landmark.style.size,
            altitude: e.landmark.style.altitude
          }), o.addAnimate({
            key: "altitude",
            value: [0, 1],
            random: e.landmark.animate.random,
            duration: e.landmark.animate.duration,
            transform: e.landmark.animate.transform,
            delay: e.landmark.animate.delay,
            yoyo: e.landmark.animate.yoyo,
            repeat: e.landmark.animate.repeat
          }), c.value.add(o), c.value.animate.start();
        } catch {
        }
      }, R = (a, e, t) => {
        const l = new a.PulseLinkLayer({
          zIndex: e.zIndex,
          opacity: e.opacity,
          visible: e.visible,
          zooms: e.zooms,
          depth: e.depth
        }), r = new a.GeoJSONSource({
          data: t
        });
        l.setSource(r), l.setStyle({
          unit: e.style.unit,
          dash: [4e4, 0, 4e4, 0],
          lineWidth: e.style.lineWidth,
          height: function(o, i) {
            return i.distance / 3 + e.style.height;
          },
          // altitude: 1000,
          smoothSteps: 30,
          speed: function(o, i) {
            return 1e5 + Math.random() * e.style.speed;
          },
          flowLength: e.style.flowLength,
          lineColors: e.style.lineColors,
          maxHeightScale: e.style.maxHeightScale,
          // 弧顶位置比例
          headColor: e.style.headColor,
          trailColor: e.style.trailColor
        }), n.value.on("click", (o) => {
          const i = l.queryFeature(o.pixel.toArray());
          i && (u("amap3d-scene-pulseLinkLayer", i), window.SHJParseEvent(s.useEvents, "amap3d-scene-pulseLinkLayer", i));
        }), c.value.add(l), c.value.animate.start();
      }, y = (a, e) => {
        const t = {
          type: "FeatureCollection",
          features: []
        };
        return a.forEach((l, r) => {
          const o = {
            type: "Feature",
            id: ie(),
            properties: {
              type: e === "Point" ? e : 0,
              ...l
            },
            geometry: {
              type: e,
              coordinates: l.value
            }
          };
          t.features.push(o);
        }), t;
      }, T = (a) => {
        n.value.setFeatures(a.config.features), n.value.setPitch(a.config.pitch), n.value.setRotation(a.config.rotation), n.value.setStatus({
          dragEnable: a.config.dragEnable,
          zoomEnable: a.config.zoomEnable,
          rotateEnable: a.config.rotateEnable,
          pitchEnable: a.config.pitchEnable
        }), a.config.plugin.scale.visible ? h.value.show() : h.value.hide(), a.config.plugin.toolBar.visible ? p.value.show() : p.value.hide(), a.config.plugin.controlBar.visible ? v.value.show() : v.value.hide();
      }, j = () => {
        n.value.clearMap(), c.value.clear(), x(b.value);
      }, V = (a) => {
        n.value.setMapStyle(a.config.mapStyle);
      }, q = (a) => {
        n.value.setZoom(a.config.zoom, !1, 200);
      }, U = (a) => {
        n.value.setCenter(a.config.center, !1, 200);
      }, E = () => {
        n.value && (n.value.clearMap(), n.value.destroy(), n.value = null, c.value && (c.value.clear(), c.value.destroy(), c.value = null));
      };
      return ae(() => {
        setTimeout(() => {
          C(s.basicOption);
        }, 0);
      }), te(() => E()), {
        initAMap3d: C,
        updateAMapStyle: V,
        updateAMapConfig: T,
        updateAMapComponents: j,
        updateAMapZoom: q,
        updateAMapCenter: U,
        amap3d: n,
        loading: S,
        AMapPrototype: b
      };
    }, {
      initAMap3d: m,
      updateAMapStyle: B,
      updateAMapConfig: k,
      updateAMapComponents: W,
      updateAMapZoom: J,
      updateAMapCenter: $,
      loading: _,
      AMapPrototype: ge
    } = I();
    return d(() => s.basicOption.config, () => {
      k(s.basicOption);
    }, { deep: !0 }), d(() => s.basicOption.config.zoom, () => {
      J(s.basicOption);
    }, { deep: !0 }), d(() => s.basicOption.config.center, () => {
      $(s.basicOption);
    }, { deep: !0 }), d(() => s.basicOption.config.floors, z(() => {
      m(s.basicOption);
    }, 300), { deep: !0 }), d(() => s.basicOption.config.skyColor, z(() => {
      m(s.basicOption);
    }, 300), { deep: !0 }), d(() => s.basicOption.widgets, () => {
      W();
    }, { deep: !0 }), d(() => s.basicOption.config.mapStyle, () => {
      B(s.basicOption);
    }, { deep: !0 }), d(() => s.basicOption.basic, () => {
      m(s.basicOption);
    }, { deep: !0 }), d(() => s.sources, () => {
      m(s.basicOption);
    }, { deep: !0 }), A({
      refresh: () => m(s.basicOption),
      refreshView: () => k(s.basicOption),
      refreshData: () => k(s.basicOption)
    }), (n, c) => (Q(), X("div", {
      class: Y(["amap-3d-wrap", { show: ee(_) }])
    }, ue, 2));
  }
});
export {
  be as default
};
