Map.vue 2.73 KB
<template>
	<div class="map-wrap" >
		<div id="map" class="map-container" v-loading="mapLoading"></div>
		<div class="menu-search">
			<el-input placeholder="请输入对应条件值" v-model="search.text" size="small" class="input-with-select">
			    <el-select v-model="search.type" slot="prepend" placeholder="请选择" size="small" >
			      <el-option label="设备号" value="1"></el-option>
			      <el-option label="车架号" value="2"></el-option>
			      <el-option label="姓名" value="3"></el-option>
			      <el-option label="工单号" value="4"></el-option>
			    </el-select>
			    
			 </el-input>
			 <el-button icon="el-icon-search" size="mini"  type="primary" :loading="search.isSearching" @click="searchSubmit">搜索</el-button>
			 <el-button :icon="search.showResult?'fa fa-caret-up':'fa fa-caret-down'" size="mini" type="primary" @click="toggleResult"></el-button>
		</div>
	</div>
</template>
<script>
	import remoteLoad from 'utils/remoteLoad.js'
	import mapService from 'utils/mapService.js'
	import 'utils/mapEvent.js'
	import MapMenu from './MapMenu.vue'
	import MapTable from './MapTable.vue'
	import MapControll from './MapControll.vue'

	import EventBus from '../../event-bus'

	import {services} from '../../api'
	import mock from '../../mock'
	const MONITOR_SERVICE =  services.monitor;

	import {CONSTANT} from '../../constant'

	export default{
		data(){
			return {
				AMap: null,
				mapObj: null,
				mapLoading: false,
				isInitMap: false
			}
		},
		methods: {
			initMap(){
				let check = ()=>{
					this.checkMapLoaded && window.clearTimeout(this.checkMapLoaded);

					return setTimeout(()=>{
				      	if('AMap' in window && typeof AMap.Map == 'function' && !this.mapObj){
				      		window.AMap = AMap;
				      		this.mapObj = mapService.init('map');
				      		
				      		//this.bindEvent();
				      		this.isInitMap = true;
						}else{
							this.checkMapLoaded = check()
						}
				    }, 100)
				}
				this.checkMapLoaded = check();
			},
			
		},
		async created () {
			if(window.AMap){
				this.initMap();
			}else{
		      	await remoteLoad(`${CONSTANT.AMAP_URL}`).then(()=>{
		      		remoteLoad(`https://webapi.amap.com/ui/1.0/main.js?v=1.0.11`).then(()=>{
		      			this.initMap();
		      		})
		      	})
		      	
		    }
		   
		},
		beforeDestroy(){
			this.offEvent();
			this.monitorInterval && window.clearTimeout(this.monitorInterval);
			

		},
		components: {
			
		}
	}
</script>
<style scoped>
	.map-wrap{
		position: absolute;
		top: 100px;
		left: 0;
		width: 100%;
		height: calc(100% - 100px);
		overflow: hidden;
	}
	.map-container{
		width: 100%;
		height: 100%;
		z-index: 100
	}
	.el-loading-mask{
		z-index: 101;
	}
	.menu-search{
		position: absolute;
		top: 20px;
		left: 20px;
	}
</style>