Browse Source

地图加载失败定时器处理

Shannon_mu 3 years ago
parent
commit
d022d2096b

+ 25 - 15
operationSupport/src/utils/AmapSearch.js

@@ -3,7 +3,17 @@ var jsapi = document.createElement('script');
 jsapi.charset = 'utf-8';
 jsapi.src = url;
 document.head.appendChild(jsapi);
-window.onLoad  = function(){
+let times = setInterval(() => {
+	if (!!AMap) {
+		const s = document.createElement('script');
+		s.charset = 'utf-8';
+		s.src = 'https://webapi.amap.com/ui/1.1/main.js';
+		document.head.appendChild(s);
+		clearInterval(times)
+	}
+}, 1000)
+
+window.onLoad = function () {
 	// var map = new AMap.Map('container');
 }
 
@@ -89,7 +99,7 @@ function RoadInfoSearch() {
 	})
 }
 
-  //经度转墨卡托
+//经度转墨卡托
 function handle_x(x) {
 	return (x / 180.0) * 20037508.34;
 }
@@ -114,8 +124,8 @@ function handle_y(y) {
  * @param {String} val 行政区域名
  * @param {Function} cb 回调函数
  */
-function getExtent(val,cb) {
-	if(!val)return;
+function getExtent(val, cb) {
+	if (!val) return;
 	var AmapCityBoundaries = {};
 	AMap.plugin('AMap.DistrictSearch', function () {
 		var districtSearch = new AMap.DistrictSearch({
@@ -125,25 +135,25 @@ function getExtent(val,cb) {
 			subdistrict: 1,
 			extensions: "all"
 		})
-		
+
 		// 搜索所有省/直辖市信息
 		districtSearch.search(val, function (status, result) {
 			let initWkid = 2360; // 默认xian80坐标系
-            //巴里坤的lessid 巴里坤的层级和坐标系
-            let blklessid = "912588c2a65543dca846";
-            let getblklessid = JSON.parse(sessionStorage.getItem("account")).lesseeId;
-            if (blklessid === getblklessid) {
-                initWkid = 102100;
-            }
+			//巴里坤的lessid 巴里坤的层级和坐标系
+			let blklessid = "912588c2a65543dca846";
+			let getblklessid = JSON.parse(sessionStorage.getItem("account")).lesseeId;
+			if (blklessid === getblklessid) {
+				initWkid = 102100;
+			}
 			// 查询成功时,result即为对应的行政区信息
 			if (status == "complete") {
 				let cruExtent = result.districtList[0].center;
 				AmapCityBoundaries.type = "point";
 				AmapCityBoundaries.x = handle_x(cruExtent.lng);
 				AmapCityBoundaries.y = handle_y(cruExtent.lat);
-				AmapCityBoundaries.spatialReference = {"wkid":initWkid};
+				AmapCityBoundaries.spatialReference = { "wkid": initWkid };
 				cb(AmapCityBoundaries);
-			}else{
+			} else {
 
 			}
 		})
@@ -153,7 +163,7 @@ function getExtent(val,cb) {
 
 
 // 高德测量面积接口
-function AmapGetArea(paths,callback){
-	var area =AMap.GeometryUtil.ringArea(paths);
+function AmapGetArea(paths, callback) {
+	var area = AMap.GeometryUtil.ringArea(paths);
 	callback(area);
 }

+ 0 - 4
operationSupport/src/views/patrolManagement/popups/mapValue.vue

@@ -95,10 +95,6 @@ export default {
     created() {
         this.$nextTick(() => {
             this.init();
-            const s = document.createElement('script');
-            s.style = 'text/javascript';
-            s.src = 'https://webapi.amap.com/ui/1.1/main.js';
-            document.body.appendChild(s);
         });
     }
 };