import { defineComponent as E, watch as u, createElementBlock as X, openBlock as Y, normalizeClass as $, unref as ee, shallowRef as L, ref as g, onMounted as ae, onUnmounted as te, createElementVNode as se, pushScopeId as oe, popScopeId as re } from "vue";
import le from "@amap/amap-jsapi-loader";
import ne from "axios";
import { nanoid as ce } from "nanoid";
import { SHJDatasourceV2 as ie } from "../../commons/plugins/datasource/index.mjs";
import { SHJParseEvent as y } from "../../commons/plugins/event/index.mjs";
const de = (m) => (oe("data-v-1495d842"), m = m(), re(), m), ue = /* @__PURE__ */ de(() => /* @__PURE__ */ se("div", {
  id: "zerov-amap-2d",
  class: "zerov-amap-container"
}, null, -1)), ye = [
  ue
], pe = E({ name: "zv-scene-amap2d" }), ze = /* @__PURE__ */ E({
  ...pe,
  props: {
    basicOption: {},
    sources: {},
    useEvents: {},
    uuid: {}
  },
  emits: [
    "amap2d-scene-success",
    "amap2d-scene-zoomstart",
    "amap2d-scene-zoomend",
    "amap2d-scene-mapclick",
    "amap2d-scene-dragstart",
    "amap2d-scene-dragging",
    "amap2d-scene-dragend"
  ],
  setup(m, { expose: M, emit: I }) {
    const o = m, p = I;
    y.parseEvents(o.useEvents, "on-page-loaded", null);
    const A = () => {
      const r = L(), n = L(), w = g(!1), f = g(), v = g(), b = g(), c = g(), C = (a) => {
        O(), window._AMapSecurityConfig = {
          securityJsCode: a.basic.securityJsCode
        }, le.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", "AMap.ImageLayer", "AMap.TileLayer"]
        }).then((e) => {
          c.value = e;
          const s = new c.value.createDefaultLayer({
            visible: !0,
            // 是否可见
            opacity: 1,
            // 透明度
            zIndex: 0
            // 叠加层级
          });
          r.value = new e.Map("zerov-amap-2d", {
            rotateEnable: a.config.rotateEnable,
            // 是否开启地图旋转交互 鼠标右键 + 鼠标画圈移动 或 键盘Ctrl + 鼠标画圈移动
            pitchEnable: a.config.pitchEnable,
            // 是否开启地图倾斜交互 鼠标右键 + 鼠标上下移动或键盘Ctrl + 鼠标上下移动
            zoomEnable: a.config.zoomEnable,
            dragEnable: a.config.dragEnable,
            zoom: a.config.zoom,
            // 初始化地图层级
            viewMode: "2D",
            // 开启3D视图,默认为关闭
            zooms: a.config.zooms,
            // 地图显示的缩放级别范围
            center: a.config.center,
            // 初始地图中心经纬度
            mapStyle: a.config.mapStyle,
            features: a.config.features,
            layers: [s]
          }), n.value = new window.Loca.Container({
            map: r.value
          }), b.value = new c.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"
            }
          }), r.value.addControl(b.value), f.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"
            }
          }), r.value.addControl(f.value), v.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"
            }
          }), r.value.addControl(v.value), S(e), r.value.on("complete", () => {
            setTimeout(() => {
              w.value = !0, p("amap2d-scene-success"), y.parseEvents(o.useEvents, "amap2d-scene-success", null);
            }, 666);
          }), r.value.on("zoomstart", () => {
            p("amap2d-scene-zoomstart"), y.parseEvents(o.useEvents, "amap2d-scene-zoomstart", null);
          }), r.value.on("zoomend", () => {
            p("amap2d-scene-zoomend"), y.parseEvents(o.useEvents, "amap2d-scene-zoomend", null);
          }), r.value.on("click", (t) => {
            p("amap2d-scene-mapclick", t.lnglat), y.parseEvents(o.useEvents, "amap2d-scene-mapclick", t.lnglat);
          }), r.value.on("dragstart", (t) => {
            p("amap2d-scene-dragstart", t.lnglat), y.parseEvents(o.useEvents, "amap2d-scene-dragstart", t.lnglat);
          }), r.value.on("dragend", (t) => {
            p("amap2d-scene-dragend", t.lnglat), y.parseEvents(o.useEvents, "amap2d-scene-dragend", t.lnglat);
          });
        }).catch((e) => {
        });
      }, S = (a) => {
        o.sources && o.sources.length > 0 ? ie.parse({
          tId: o.uuid,
          sources: o.sources,
          callback: (s) => {
            try {
              const t = o.basicOption.widgets.find((l) => l._sourceId === s.id);
              t && t.type === "heatmap" && F(a, t, s.data[0].data), t && t.type === "dotlayers" && G(window.Loca, t, k(s.data[0].data)), t && t.type === "scatter" && H(window.Loca, t, k(s.data[0].data)), t && t.type === "labelsLayer" && Z(window.Loca, t, k(s.data[0].data));
            } catch {
            }
            o.basicOption.widgets.filter((t) => t.type === "boundary").forEach((t) => {
              x(a, t);
            });
          }
        }) : o.basicOption.widgets.filter((s) => s.type === "boundary").forEach((s) => {
          x(a, s);
        });
        const e = r.value.getLayers();
        for (let s = 0; s < e.length; s++)
          (e[s].type === "sketchTileLayer" || e[s]._opts.type === "sketchImageLayer") && r.value.removeLayer(e[s]);
        o.basicOption.widgets.filter((s) => s.type === "sketchTile").forEach((s) => {
          const t = P(s);
          t && r.value.addLayer(t);
        }), o.basicOption.widgets.filter((s) => s.type === "sketchImage").forEach((s) => {
          const t = N(s);
          r.value.addLayer(t);
        });
      }, J = (a) => {
        const s = a.slice(a.indexOf("(") + 1, a.lastIndexOf(")")).split(",").map((l) => l.trim()), t = {};
        for (let l = 1; l < s.length; l++) {
          const i = s[l].split(" "), d = i[0], K = parseFloat(i[1]) / 100, Q = Math.round(K * 100) / 100;
          t[Q] = d;
        }
        return t;
      }, P = (a) => {
        try {
          return new c.value.TileLayer({
            bounds: new c.value.Bounds(
              a.bounds[0],
              a.bounds[1]
            ),
            getTileUrl: function(s, t, l) {
              try {
                return a.url.replace("{z}", l).replace("{x}", s).replace("{y}", t);
              } catch {
              }
            },
            type: "sketchTileLayer",
            tileSize: a.tileSize,
            opacity: a.opacity,
            zIndex: a.zIndex,
            zooms: a.zooms
          });
        } catch {
        }
        return null;
      }, N = (a) => {
        try {
          return new c.value.ImageLayer({
            bounds: new c.value.Bounds(
              a.bounds[0],
              // 左下  手绘图左下相对于地图的经纬度
              a.bounds[1]
              // 右上  手绘图右上相对于地图的经纬度
            ),
            type: "sketchImageLayer",
            opacity: a.opacity,
            url: a.url,
            zIndex: a.zIndex,
            zooms: a.zooms
            // 设置可见级别，[最小级别，最大级别]
          });
        } catch {
        }
        return null;
      }, F = (a, e, s) => {
        try {
          const t = new a.HeatMap(r.value, {
            radius: e.radius,
            // 给定半径
            opacity: e.opacity,
            gradient: J(e.gradient)
          });
          setTimeout(() => {
            t.setDataSet({
              data: s,
              max: e.max
            });
          }, 0);
        } catch {
        }
      }, x = async (a, e) => {
        try {
          const s = await ne.get(e.geojson);
          if (s.status === 200) {
            const t = new a.GeoJSON({
              geoJSON: s.data,
              getPolygon: function(l, i) {
                const d = new a.Polygon({
                  path: i,
                  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 d.on("mouseover", () => {
                  d.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
                  });
                }), d.on("mouseout", () => {
                  d.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
                    // 线条样式
                  });
                }), d;
              }
            });
            r.value.add(t);
          }
        } catch {
        }
      }, G = (a, e, s) => {
        try {
          const t = new a.GeoJSONSource({
            data: s
          }), l = new a.PointLayer({
            zIndex: e.zIndex,
            blend: e.blend,
            visible: e.visible,
            opacity: e.opacity
          }), i = {
            radius: e.style.radius,
            unit: e.style.unit,
            color: e.style.color,
            borderWidth: e.style.borderWidth,
            blurWidth: e.style.blurWidth,
            borderColor: e.style.borderColor
          };
          l.setSource(t), l.setStyle(i), n.value.add(l), l.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 {
        }
      }, H = (a, e, s) => {
        try {
          const t = new a.GeoJSONSource({
            data: s
          }), l = new a.ScatterLayer({
            loca: n.value,
            zIndex: e.zIndex,
            opacity: e.opacity,
            visible: e.visible,
            zooms: e.zooms
          });
          l.setSource(t), l.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
          }), n.value.animate.start();
        } catch {
        }
      }, Z = (a, e, s) => {
        try {
          const t = new a.GeoJSONSource({
            data: s
          }), l = new a.LabelsLayer({
            eventSupport: !0,
            visible: e.visible,
            zooms: e.zooms,
            opacity: e.opacity,
            collision: e.collision,
            allowCollision: e.allowCollision,
            zIndex: e.zIndex
          });
          l.on("click", (i) => {
          }), l.setSource(t), l.setStyle({
            icon: {
              image: e.icon.image,
              size: e.icon.size,
              clipOrigin: e.icon.clipOrigin,
              offset: e.icon.offset,
              anchor: e.icon.anchor
            },
            text: {
              // 每项配置都可使用回调函数来动态配置
              content: (i, d) => d.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
              }
            }
          }), n.value.add(l);
        } catch {
        }
      }, k = (a) => {
        const e = {
          type: "FeatureCollection",
          features: []
        };
        return a.forEach((s, t) => {
          const l = {
            type: "Feature",
            id: ce(),
            properties: {
              name: s.name || "",
              _draw_type: "point"
            },
            geometry: {
              type: "Point",
              coordinates: s.value
            }
          };
          e.features.push(l);
        }), e;
      }, j = (a) => {
        r.value.setFeatures(a.config.features), r.value.setStatus({
          dragEnable: a.config.dragEnable,
          zoomEnable: a.config.zoomEnable,
          rotateEnable: a.config.rotateEnable
        }), a.config.plugin.scale.visible ? b.value.show() : b.value.hide(), a.config.plugin.toolBar.visible ? v.value.show() : v.value.hide(), a.config.plugin.controlBar.visible ? f.value.show() : f.value.hide();
      }, R = () => {
        r.value.clearMap(), n.value.clear(), S(c.value);
      }, V = (a) => {
        r.value.setMapStyle(a.config.mapStyle);
      }, U = (a) => {
        r.value.setZoom(a.config.zoom, !1, 200);
      }, q = (a) => {
        r.value.setCenter(a.config.center, !1, 200);
      }, O = () => {
        r.value && (r.value.clearMap(), r.value.destroy(), r.value = null, n.value && (n.value.clear(), n.value.destroy(), n.value = null));
      };
      return ae(() => {
        setTimeout(() => {
          C(o.basicOption);
        }, 0);
      }), te(() => O()), {
        initAMap2d: C,
        updateAMapStyle: V,
        updateAMapConfig: j,
        updateAMapComponents: R,
        updateAMapZoom: U,
        updateAMapCenter: q,
        amap2d: r,
        loading: w,
        AMapPrototype: c
      };
    }, {
      initAMap2d: h,
      updateAMapStyle: B,
      updateAMapConfig: z,
      updateAMapComponents: W,
      updateAMapZoom: _,
      updateAMapCenter: D,
      loading: T
    } = A();
    return u(() => o.basicOption.config, () => {
      z(o.basicOption);
    }, { deep: !0 }), u(() => o.basicOption.config.zoom, () => {
      _(o.basicOption);
    }, { deep: !0 }), u(() => o.basicOption.config.center, () => {
      D(o.basicOption);
    }, { deep: !0 }), u(() => o.basicOption.widgets, () => {
      W();
    }, { deep: !0 }), u(() => o.basicOption.config.mapStyle, () => {
      B(o.basicOption);
    }, { deep: !0 }), u(() => o.basicOption.basic, () => {
      h(o.basicOption);
    }, { deep: !0 }), u(() => o.sources, () => {
      h(o.basicOption);
    }, { deep: !0 }), M({
      refresh: () => h(o.basicOption),
      refreshView: () => z(o.basicOption),
      refreshData: () => z(o.basicOption)
    }), (r, n) => (Y(), X("div", {
      class: $(["amap-2d-wrap", { show: ee(T) }])
    }, ye, 2));
  }
});
export {
  ze as default
};
