Jelajahi Sumber

低空三吉初始化加载250522-01

zhiyuan-007 3 hari lalu
induk
melakukan
94dd89717c
5 mengubah file dengan 94 tambahan dan 54 penghapusan
  1. TEMPAT SAMPAH
      dist.zip
  2. 26 13
      src/components/mapJK.vue
  3. 5 3
      src/components/mapTest.vue
  4. 15 1
      src/config/basicTool.json
  5. 48 37
      src/units/map/InitMap.js

TEMPAT SAMPAH
dist.zip


+ 26 - 13
src/components/mapJK.vue

@@ -137,38 +137,51 @@ export default {
     onMounted(() =>{
       bus.on('CreateMap',() =>{
         MapReady = $.Deferred();
-        createMap();
-        $.when((MapReady).done(()=>{
-          //发送消息
-          bus.emit('SendMessage',{
-            action:"MapIsReady",
-            data:{
-              "message":"地图初始化完成"
-            }
-          })
-        }))
+        createMap(() => { // [!code focus]
+          MapReady.resolve(); // 确保在此处触发 // [!code focus]
+        });
+        // 错误处理
+        MapReady.fail((error) => {
+          console.error("地图初始化失败:", error);
+        });
+        // 发送 MapReady 消息
+        MapReady.done(() => {
+          console.log("触发 MapReady 消息");
+          bus.emit('SendMessage', {
+            action: "MapReady",
+            data: { message: "地图初始化完成" }
+          });
+        });
       })
       //调用方法
       bus.on('InvokeMethod',(data) =>{
         invokeMethod(data);
       })
-      function createMap(){
+      function createMap(onReady) { // [!code focus]
         let setMapConfig = new SetMapConfig({
           m_spatialReference,
           m_fullExtent,
           m_initialExtent,
           m_handles
-        })
+        });
+
         m_spatialReference = setMapConfig.m_spatialReference;
         m_fullExtent = setMapConfig.m_fullExtent;
         m_initialExtent = setMapConfig.m_initialExtent;
         m_handles = setMapConfig.m_handles;
+
+        // 初始化地图并传递回调
         let initMap = new InitMap({
           m_map,
           m_view,
           m_spatialReference,
-          bus
+          bus,
+          onReady: () => { // [!code focus]
+            console.log("地图完全初始化完成");
+            onReady(); // 触发外部回调 // [!code focus]
+          }
         });
+
         m_map = initMap.m_map;
         m_view = initMap.m_view;
       }

+ 5 - 3
src/components/mapTest.vue

@@ -75,15 +75,17 @@ export default {
       bridge = new CityGIS.Bridge({
         id:"i_map",
         //url:'https://cimweb.zjw.sh.cegn.cn:2007/map-tool-widget/#/jk_map',
-        //url:'http://localhost:5173/map-tool-widget/#/jk_map',
-        url: 'http://192.168.2.137:9251/map-tool-widget/#/jk_map',
+        url:'http://localhost:5173/map-tool-widget/#/jk_map',
+        //url: 'http://192.168.2.137:9251/map-tool-widget/#/jk_map',
         onReady:function (){
           // console.log("地图创建完成");
         }
       });
       bridge.addEventListener((arg) =>{
+        debugger
+        console.log('arg.action',arg.action)
         switch (arg.action){
-          case "MapIsReady":
+          case "MapReady":
             t_result.value = JSON.stringify(arg.data,null,4);
             break;
           case "LayerIsReady":

+ 15 - 1
src/config/basicTool.json

@@ -42,7 +42,7 @@
             "title":"BaseMap",
             "visible": true,
             "opacity": 1,
-            "url": "https://cimweb.zjw.sh.cegn.cn:2008/MapServiceProxy/eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3NDQ4NzM1NTEsImtleSI6IjkzNDkzMzIxIiwic2VydmljZU5vIjoiRDkwMDEwMDcxMjAyMzA4MDEiLCJ1c2VybmFtZSI6InB0Z2wifQ.iS-1EWEiyvULfvTU8NmfWatoSPBYK0SOg5ytx4usO4E",
+            "url": "https://cimweb.zjw.sh.cegn.cn:2008/MapServiceProxy/eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3NDUzODY4MzQsImtleSI6IjkzNDkzMzIxIiwic2VydmljZU5vIjoiRDkwMDEwMDcxMjAyMzA4MDEiLCJ1c2VybmFtZSI6InB0Z2wifQ.rg_Dd4CSpnSm87vGW_quTjEHOjKZvI3suDofBgDBkc0",
             "token": ""
           }
         }
@@ -2661,6 +2661,20 @@
             "token": ""
           }
         }
+      },
+      {
+        "code": "1-60",
+        "title": "",
+        "data": {
+          "ActionName": "RadarEffect",
+          "Parameters": {
+            "id" : "radar1",
+            "status" : "show",
+            "radius": 2000,
+            "point": [2900.62,1008,20],
+            "token": ""
+          }
+        }
       }
     ]
   }

+ 48 - 37
src/units/map/InitMap.js

@@ -1,32 +1,34 @@
+// InitMap 修改后代码
 import Map from '@arcgis/core/Map'
 import MapView from '@arcgis/core/views/MapView'
 import SceneView from '@arcgis/core/views/SceneView'
 import dojoConfig from '../../config/tsconfig.json'
-class InitMap{
+
+class InitMap {
     constructor(options) {
         this.m_map = options.m_map;
         this.m_view = options.m_view;
         this.m_spatialReference = options.m_spatialReference;
         this.bus = options.bus;
-        this.intMap()
+        this.onReady = options.onReady; // 新增回调参数 // [!code ++]
+        this.intMap();
     }
-    intMap(){
+
+    intMap() {
         this.m_map = new Map({});
-        this.m_map.ground.surfaceColor = "#002F47"
-        // this.m_map.ground.navigationConstraint = {
-        //     type: "none"
-        // };
+        this.m_map.ground.surfaceColor = "#002F47";
+
         this.m_view = new SceneView({
-            container:"viewDiv",
-            map:this.m_map,
-            logo:false,
-            viewingMode:"global",
-            scale:dojoConfig["scale"],
-            spatialReference:this.m_spatialReference,
-            qualityProfile:"high",
+            container: "viewDiv",
+            map: this.m_map,
+            logo: false,
+            viewingMode: "global",
+            scale: dojoConfig["scale"],
+            spatialReference: this.m_spatialReference,
+            qualityProfile: "high",
             environment: {
                 starsEnabled: true,
-                atmosphereEnabled: true, //大气层
+                atmosphereEnabled: true,
                 weather: {
                     type: "sunny",
                     cloudCover: 0.7,
@@ -42,27 +44,36 @@ class InitMap{
                 }
             }
         });
-        // this.m_view.constraints = {
-        //     collision: {
-        //         enabled: false
-        //     }
-        // };
-        this.m_view.watch("stationary",(stationary) =>{
-            if(stationary){
-                this.bus.emit('SendMessage', {
-                    action: "MapExtentChanged",
-                    data: {
-                        "extent": this.m_view.extent,
-                        "scale": this.m_view.scale,
-                        "camera": this.m_view.camera,
-                        "rotation": this.m_view.viewpoint.rotation,
-                        "center": this.m_view.center
-                    }
-                })
-            }
-        })
-        this.m_view.ui.empty("top-left");
-        this.m_view.ui.remove("attribution");
+
+        // 关键修改:等待 SceneView 加载完成 // [!code ++]
+        this.m_view.when(() => {
+            console.log("SceneView 初始化完成");
+
+            // 初始化其他逻辑
+            this.m_view.watch("stationary", (stationary) => {
+                if (stationary) {
+                    this.bus.emit('SendMessage', {
+                        action: "MapExtentChanged",
+                        data: {
+                            extent: this.m_view.extent,
+                            scale: this.m_view.scale,
+                            camera: this.m_view.camera,
+                            rotation: this.m_view.viewpoint.rotation,
+                            center: this.m_view.center
+                        }
+                    });
+                }
+            });
+
+            this.m_view.ui.empty("top-left");
+            this.m_view.ui.remove("attribution");
+
+            // 触发外部回调 // [!code ++]
+            if (this.onReady) this.onReady(); // [!code ++]
+        }).catch(error => { // [!code ++]
+            console.error("SceneView 初始化失败:", error); // [!code ++]
+        }); // [!code ++]
     }
 }
-export default  InitMap
+
+export default InitMap;