activeLocation.vue 2.25 KB
<template>
  <v-full-layout class="active_location">
    <template slot="breadcrumb">
      <el-breadcrumb-item>激活位置</el-breadcrumb-item>
    </template>
    <template slot="main">
      <div id="map" class="map-container"></div>
    </template>
  </v-full-layout>
</template>
<script>
import mapService from 'utils/mapService.js'
import "utils/mapEvent.js";
	import EventBus from '../../event-bus'
import remoteLoad from "utils/remoteLoad.js";
import {CONSTANT} from '../../constant'
export default {
  data() {
    return {
      AMap: null,
      mapObj: null,
      checkLoadedTimeoutId: "",
    };
  },
  created() {
    console.log(history.state)
    if (window.AMap) {
      this.initMap();
    } else {
      remoteLoad(`${CONSTANT.AMAP_URL}`).then(() => {
        remoteLoad(`https://webapi.amap.com/ui/1.0/main.js?v=1.0.11`).then(
          () => {
            this.initMap();
          }
        );
      });
    }
  },
  methods: {
    // 初始化地图
    initMap() {
      let check = () => {
        if (this.checkLoadedTimeoutId) {
          window.clearTimeout(this.checkLoadedTimeoutId);
        }
        return setTimeout(() => {
          if (
            "AMap" in window &&
            typeof AMap.Map == "function" &&
            !this.mapObj
          ) {
            window.AMap = AMap;
            this.mapObj = mapService.init("map");
            this.isInitMap = true;
            let o = history.state;
            console.log(o)
            if (o.lng || o.bsLng) {
                o.elat = o.lat;
                o.elng = o.lng;
              this.addLocation(o);
            }
          } else {
            this.checkLoadedTimeoutId = check();
          }
        }, 100);
      };
      this.checkLoadedTimeoutId = check();
    },

    // 添加位置点
    addLocation(row) {
      let drawData = row;
      EventBus.$emit("uiMap.monitor.drawMaker", drawData, true);
    },
  },
};
</script>
<style lang="scss" scoped>
.active_location {
  .full-width {
    position: absolute;
    top: 0px;
    height: 100%;
    left: 0;
    width: 100%;
    bottom: 0;
    .map-container {
      width: 100%;
      height: 100%;
      z-index: 100;
      position: absolute;
      top: 0px;
      left: 0;
      bottom: 0;
      overflow: hidden;
    }
  }
}
</style>