瀏覽代碼

低空三吉初始化加载250423-04

zhiyuan-007 2 天之前
父節點
當前提交
fc5ae8d006
共有 4 個文件被更改,包括 77 次插入53 次删除
  1. 二進制
      dist.zip
  2. 8 0
      src/components/mapJK.vue
  3. 3 2
      src/components/mapTest.vue
  4. 66 51
      src/units/map/InitMap.js

二進制
dist.zip


+ 8 - 0
src/components/mapJK.vue

@@ -73,9 +73,11 @@ import QueryIn2D from "../units/map/QueryIn2D.js";
 import AddFlowPathEvent from "../units/map/AddFlowPathEvent.js";
 import MovePointStreamEvent from "../units/map/MovePointStreamEvent.js";
 import AddRadarEffectEvent from "../units/map/AddRadarEffect.js";
+import {useRoute} from "vue-router";
 export default {
   name: "mapJK",
   setup(){
+    const route = useRoute();
     let socket = null;
     let virtualSocket = null;
     let flyPointSocket = null;
@@ -157,7 +159,12 @@ export default {
       bus.on('InvokeMethod',(data) =>{
         invokeMethod(data);
       })
+      function getRouteType (){
+        return route.query.type || '3D';
+      }
+
       function createMap(onReady) { // [!code focus]
+        let currentType = getRouteType();
         let setMapConfig = new SetMapConfig({
           m_spatialReference,
           m_fullExtent,
@@ -176,6 +183,7 @@ export default {
           m_view,
           m_spatialReference,
           bus,
+          currentType,
           onReady: () => { // [!code focus]
             console.log("地图完全初始化完成");
             onReady(); // 触发外部回调 // [!code focus]

+ 3 - 2
src/components/mapTest.vue

@@ -74,8 +74,9 @@ export default {
       //加载地图插件
       bridge = new CityGIS.Bridge({
         id:"i_map",
-        //url:'http://localhost:5173/map-tool-widget/#/jk_map',
-        url: 'http://116.236.218.30:9251/map-tool-widget/#/jk_map',
+        url:'http://localhost:5173/map-tool-widget/#/jk_map',
+        //url:'http://localhost:5173/map-tool-widget/#/jk_map?type=2D',
+        //url: 'http://116.236.218.30:9251/map-tool-widget/#/jk_map',
         onReady:function (){
           // console.log("地图创建完成");
         }

+ 66 - 51
src/units/map/InitMap.js

@@ -11,68 +11,83 @@ class InitMap {
         this.m_spatialReference = options.m_spatialReference;
         this.bus = options.bus;
         this.onReady = options.onReady; // 新增回调参数 // [!code ++]
+        this.currentType = options.currentType;
         this.intMap();
     }
 
     intMap() {
+        let that =this;
         this.m_map = new Map({});
-        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",
-            environment: {
-                starsEnabled: true,
-                atmosphereEnabled: true,
-                weather: {
-                    type: "sunny",
-                    cloudCover: 0.7,
-                    precipitation: 0.3
+        if(this.currentType === "2D") {
+            this.m_view = new MapView({
+                container: "viewDiv",
+                map: this.m_map,
+                logo: false,
+                background:{
+                    color:"#002F47"
                 },
-                atmosphere: {
-                    quality: "high"
+                ui: {
+                    components: []
                 },
-                lighting: {
-                    date: new Date().setHours(-3),
-                    directShadowsEnabled: true,
-                    cameraTrackingEnabled: true
-                }
-            }
-        });
-
-        // 关键修改:等待 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
-                        }
-                    });
+                spatialReference: this.m_spatialReference,
+            });
+            this.loadWatch()
+        }
+        if(this.currentType === '3D'){
+            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",
+                environment: {
+                    starsEnabled: true,
+                    atmosphereEnabled: true,
+                    weather: {
+                        type: "sunny",
+                        cloudCover: 0.7,
+                        precipitation: 0.3
+                    },
+                    atmosphere: {
+                        quality: "high"
+                    },
+                    lighting: {
+                        date: new Date().setHours(-3),
+                        directShadowsEnabled: true,
+                        cameraTrackingEnabled: true
+                    }
                 }
             });
-
             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 ++]
+            // 关键修改:等待 SceneView 加载完成 // [!code ++]
+            this.m_view.when(() => {
+                that.loadWatch();
+            }).catch(error => { // [!code ++]
+                console.error("SceneView 初始化失败:", error); // [!code ++]
+            }); // [!code ++]
+        }
+    }
+    loadWatch(){
+        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
+                    }
+                });
+            }
+        });
+        // 触发外部回调 // [!code ++]
+        if (this.onReady) this.onReady(); // [!code ++]
     }
 }