欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

vue項(xiàng)目使用高德地圖時(shí)報(bào)錯(cuò):AMap?is?not?defined解決辦法

 更新時(shí)間:2023年12月04日 11:19:36   作者:前端-文龍剛  
這篇文章主要給大家介紹了關(guān)于vue項(xiàng)目使用高德地圖時(shí)報(bào)錯(cuò):AMap?is?not?defined的解決辦法,"AMap is not defined"是一個(gè)錯(cuò)誤提示,意思是在代碼中沒(méi)有找到定義的AMap,需要的朋友可以參考下

場(chǎng)景:

最近在使用高德地圖做軌跡回放的時(shí)候,遇到一個(gè)BUG,提示:AMap is not defined,大概就是沒(méi)找到你定義的AMap

網(wǎng)上找了很久,比如什么js加載順序問(wèn)題

還有說(shuō)要設(shè)置

統(tǒng)統(tǒng)試了,都沒(méi)用?。?! 

解決辦法: 

既然說(shuō)加載順序的問(wèn)題,那就在初始化的時(shí)候,給加個(gè)延遲吧

 結(jié)果發(fā)現(xiàn)好了!??!

 我這種投機(jī)取巧的方式也許沒(méi)有徹底解決問(wèn)題,目前沒(méi)找到更好的辦法,希望各位大神指點(diǎn)指點(diǎn)

下面是整個(gè)頁(yè)面的完整代碼 

<template>
	<div>
	    <div id="container"></div>
	    <div class="input-card">
	      <h4>軌跡回放控制</h4>
	      <div class="input-item">
	        <input type="button" class="btn" value="開始動(dòng)畫" id="start" @click="startAnimation()" />
	        <input type="button" class="btn" value="暫停動(dòng)畫" id="pause" @click="pauseAnimation()" />
	      </div>
	      <div class="input-item">
	        <input type="button" class="btn" value="繼續(xù)動(dòng)畫" id="resume" @click="resumeAnimation()" />
	        <input type="button" class="btn" value="停止動(dòng)畫" id="stop" @click="stopAnimation()" />
	      </div>
	    </div>
	  </div>
</template>
 
<script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.15&key=你自己的key"></script>
<script>
	//請(qǐng)求路徑
	//import {
		//playbacklist,
	//} from "@/api/obd/playback";
 
	export default {
	    mounted() {
	      this.initMap();
	    },
	    beforeDestroy() {
	      
        if (this.timer) {
          clearInterval(this.timer);
          this.timer = null;
          this.map && this.map.destroy();
        }
	    },
	    data() {
	      return {
	        map: null,
	        marker: null,
	        lineArr: [
	          [118.478939, 39.997768],
	          [116.478939, 39.997825],
	          [116.478912, 39.998549],
	          [116.478912, 39.998549],
	          [116.478998, 39.998555],
	          [116.478998, 39.998555],
	          [116.479282, 39.99856],
	          [116.479658, 39.998528],
	          [116.480151, 39.998453],
	          [116.480784, 39.998302],
	          [116.480784, 39.998302],
	          [116.481149, 39.998184],
	          [116.481573, 39.997997],
	          [116.481863, 39.997846],
	          [116.482072, 39.997718],
	          [116.482362, 39.997718],
	          [116.483633, 39.998935],
	          [116.48367, 39.998968],
	          [116.484648, 39.999861]
	        ]
	      };
	    },
	    methods: {
	      initMap() {
			setTimeout(()=>{
				var that = this
				that.map = new AMap.Map("container", {
					resizeEnable: true,
					center: [108.478939, 39.997768],
					zoom: 17
				});
	        
	
				that.marker = new AMap.Marker({
	          map: that.map,
	          position: [118.478939, 39.997768],
	          icon: "https://webapi.amap.com/images/car.png",
	          offset: new AMap.Pixel(-26, -15),
	          autoRotation: true,
	          angle: -90
	        });
	
	        // 繪制軌跡
	        var polyline = new AMap.Polyline({
	          map: that.map,
	          path: that.lineArr,
	          showDir: true,
	          strokeColor: "#28F", //線顏色
	          // strokeOpacity: 1,     //線透明度
	          strokeWeight: 6 //線寬
	          // strokeStyle: "solid"  //線樣式
	        });
	
	        var passedPolyline = new AMap.Polyline({
	          map: that.map,
	          // path: this.lineArr,
	          strokeColor: "#AF5", //線顏色
	          // strokeOpacity: 1,     //線透明度
	          strokeWeight: 6 //線寬
	          // strokeStyle: "solid"  //線樣式
	        });
	        this.marker.on("moving", function (e) {
	          passedPolyline.setPath(e.passedPath);
	        });
	
	        this.map.setFitView();
			},800)
	
	      },
	      startAnimation() {
	        this.marker.moveAlong(this.lineArr, 200);
	      },
	      pauseAnimation() {
	        this.marker.pauseMove();
	      },
	      resumeAnimation() {
	        this.marker.resumeMove();
	      },
	      stopAnimation() {
	        this.marker.stopMove();
	      }
	    }
	  };
</script>
 
<style scoped>
	
	  #container {
	    height: 1000px;
	    width: 100%;
	  }
	
	  .input-card .btn {
	    margin-right: 1.2rem;
	    width: 9rem;
	  }
	
	  .input-card .btn:last-child {
	    margin-right: 0;
	  }
	  
	  .btn {
	    display: inline-block;
	    font-weight: 400;
	    text-align: center;
	    white-space: nowrap;
	    vertical-align: middle;
	    -webkit-user-select: none;
	    -moz-user-select: none;
	    -ms-user-select: none;
	    user-select: none;
	    border: 1px solid transparent;
	    transition: color .15s ease-in-out, background-color .15s ease-in-out, border-color .15s ease-in-out, box-shadow .15s ease-in-out;
	    background-color: transparent;
	    background-image: none;
	    color: #25A5F7;
	    border-color: #25A5F7;
	    padding: .25rem .5rem;
	    line-height: 1.5;
	    border-radius: 1rem;
	    cursor:pointer;
	  }
	  
	  .input-item {
	    position: relative;
	    display: -ms-flexbox;
	    display: flex;
	    -ms-flex-wrap: wrap;
	    flex-wrap: wrap;
	    -ms-flex-align: center;
	    align-items: center;
	    width: 100%;
	    height: 3rem;
	  }
	  
	  .input-card {
	    display: flex;
	    flex-direction: column;
	    min-width: 0;
	    word-wrap: break-word;
	    background-color: #fff;
	    background-clip: border-box;
	    border-radius: .25rem;
	    width: 22rem;
	    border-width: 0;
	    border-radius: 0.4rem;
	    box-shadow: 0 2px 6px 0 rgba(114, 124, 245, .5);
	    position: fixed;
	    bottom: 1rem;
	    right: 1rem;
	    -ms-flex: 1 1 auto;
	    flex: 1 1 auto;
	    padding: 0.75rem 1.25rem;
	  }
</style>

總結(jié)

到此這篇關(guān)于vue項(xiàng)目使用高德地圖時(shí)報(bào)錯(cuò):AMap is not defined解決辦法的文章就介紹到這了,更多相關(guān)vue高德地圖報(bào)錯(cuò)AMap is not defined內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論