<template>
  <div style='height:100%;'></div>
</template>

<script>
/**
 * 旧版本
 */
import Vue from "vue";
/**
 * DMap
 */
export default {
  props: {
    global: { default: true },
    platform: { default: "leaflet" }
  },
  mounted() {
    let { global } = this;
    let promise = new Promise((resolve, reject) => {
      let prefix = "dmap";
      let { platform } = this;
      //
      T.require(
        [`${prefix}/${platform}/${prefix}-${platform}`],
        L => {
          if (L.__esModule) {
            L = L.default;
          }
          let { $el, $route, $store, $attrs, $root } = this;
          let { assign } = T;
          let options = assign({}, $store.state.mapOptions, $attrs);
          this.$emit("init-pre", options);
          let map = (this.map = L.map($el, options));
          let viewer = (T.viewer = {
            DMap: L,
            Map: L.Map,
            map: map,
            $_map: map.map
          });
          // 非私有的地图模块
          global && assign(Vue.prototype, viewer);
          resolve(map);
          this.$emit("init", map);
        },
        reject
      );
    });
    if (global) T.dmap = promise;
  }
};
</script>