function initJWPageFactoryAMap(t) {
  var e = {
    _keyStr:
      "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
    decode: function (t) {
      var a,
        r,
        o,
        n,
        d,
        i,
        s = "",
        c = 0;
      for (t = t.replace(/[^A-Za-z0-9+/=]/g, ""); c < t.length; )
        (a =
          (this._keyStr.indexOf(t.charAt(c++)) << 2) |
          ((n = this._keyStr.indexOf(t.charAt(c++))) >> 4)),
          (r =
            ((15 & n) << 4) | ((d = this._keyStr.indexOf(t.charAt(c++))) >> 2)),
          (o = ((3 & d) << 6) | (i = this._keyStr.indexOf(t.charAt(c++)))),
          (s += String.fromCharCode(a)),
          64 != d && (s += String.fromCharCode(r)),
          64 != i && (s += String.fromCharCode(o));
      return (s = e._utf8_decode(s));
    },
    _utf8_decode: function (t) {
      for (var e = "", a = 0, r = (c1 = c2 = 0); a < t.length; )
        (r = t.charCodeAt(a)) < 128
          ? ((e += String.fromCharCode(r)), a++)
          : r > 191 && r < 224
          ? ((c2 = t.charCodeAt(a + 1)),
            (e += String.fromCharCode(((31 & r) << 6) | (63 & c2))),
            (a += 2))
          : ((c2 = t.charCodeAt(a + 1)),
            (c3 = t.charCodeAt(a + 2)),
            (e += String.fromCharCode(
              ((15 & r) << 12) | ((63 & c2) << 6) | (63 & c3)
            )),
            (a += 3));
      return e;
    },
  };
  jQuery(".jwpf-addon-amap-canvas", t).each(function (a) {
    var r = jQuery(this).attr("id"),
      l = jQuery(this).attr("data-maplang"),
      s = jQuery(this).attr("data-mapstyle"),
      i = jQuery(this).attr("data-maptype"),
      u = jQuery(this).attr("data-lat"),
      g = jQuery(this).attr("data-lng"),
      m = jQuery(this).attr("data-marker"),
      n = jQuery(this).attr("data-infowindow"),
      z = Number(jQuery(this).attr("data-mapzoom")),
      d = "true" === jQuery(this).attr("data-mousescroll"),
      showinfo = jQuery(this).attr("data-showinfo"),
      c = new AMap.Map(t.getElementById(r), {
        center: new AMap.LngLat(Number(g), Number(u)),
        mapStyle: "amap://styles/" + s,
        zoom: z,
        lang: l,
        scrollWheel: d,
        resizeEnable: true,
      }),
      x = jQuery(this).attr("data-location"),
      a = [];
    switch (i) {
      case "roadnet":
        a.push(new AMap.TileLayer.RoadNet());
        break;
      case "satellite":
        a.push(new AMap.TileLayer.Satellite());
        break;
      case "hybrid":
        a.push(new AMap.TileLayer.Satellite());
        a.push(new AMap.TileLayer.RoadNet());
        break;
      case "traffic":
        a.push(new AMap.TileLayer.Traffic());
        a.push(new AMap.TileLayer());
        break;
      default:
        a.push(new AMap.TileLayer());
        break;
    }
    c.setLayers(a);
    AMap.plugin('AMap.ToolBar',function(){//异步加载插件
        var toolbar = new AMap.ToolBar();
        c.addControl(toolbar);
    });
    if (void 0 !== x) {
      var h = e.decode(n),
        l = JSON.stringify([
          { address: h, latitude: u, longitude: g, icon: m },
        ]),
        f = e.decode(x),
        p = JSON.parse(l),
        b = JSON.parse(f),
        o = p.concat(b),
        C = o.length;
      if (C > 0) {
        var n = new AMap.InfoWindow({ offset: new AMap.Pixel(5, -30) });
        for (var S = 0; S < C; S++) {
          q = new AMap.LngLat(o[S].longitude, o[S].latitude);
          w = new AMap.Marker({ position: q, map: c });
          if (o[S].icon) {
            var icon = new AMap.Icon({ image: o[S].icon });
            w.setIcon(icon);
          }
          if (o[S].address) {
            w.content = o[S].address;
            if (showinfo === "1") {
              n.setContent(
                '<div class="amap-info-window-content">' +
                  o[S].address +
                  "</div>"
              );
              n.open(c, w.getPosition());
            }
            w.on("click", function (e) {
              n.setContent(
                '<div class="amap-info-window-content">' +
                  e.target.content +
                  "</div>"
              );
              n.open(c, e.target.getPosition());
            });
          }
        }
        if (C > 1) c.setFitView();
      }
    }
  });
}
jQuery(window).on("load", function () {
  initJWPageFactoryAMap(document);
});
