From 6c75df824742c446e8230391bac7dc356817fd39 Mon Sep 17 00:00:00 2001
From: liuyg <376836862@qq.com>
Date: Wed, 29 Dec 2021 14:34:18 +0800
Subject: [PATCH] +适应2.5d 2d图层

---
 src/components/mobilemap/index.vue |  230 +++++++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 191 insertions(+), 39 deletions(-)

diff --git a/src/components/mobilemap/index.vue b/src/components/mobilemap/index.vue
index dc5a753..70a3c30 100644
--- a/src/components/mobilemap/index.vue
+++ b/src/components/mobilemap/index.vue
@@ -46,6 +46,7 @@
       "iconHide",
       "popupsDom",
       "MobileWindowsHideFixed",
+      "dimension",
     ]),
   },
   watch: {
@@ -195,9 +196,59 @@
         if (!that.MobileWindowsHide) {
           // that.$store.dispatch("closeMobileWindowsDom"); //关闭随地图弹窗
         }
+        // let height = Math.ceil(viewer.camera.positionCartographic.height);
+        // console.log(height);
       });
 
-      //自带白模型↓
+      viewer.on(that.DC.SceneEventType.CAMERA_CHANGED, (e) => {
+        //控制高度
+        const height = Math.ceil(viewer.camera.positionCartographic.height);
+        let orientation = {
+          heading: that.DC.Namespace.Cesium.Math.toRadians(0), // 方向
+          pitch: that.DC.Namespace.Cesium.Math.toRadians(
+            that.dimension == "2D" ? -90 : that.dimension == "2.5D" ? -45 : -45
+          ), // 倾斜角度
+          roll: 0,
+        };
+        if (height < 300) {
+          viewer.camera.setView({
+            destination: that.DC.Namespace.Cesium.Cartesian3.fromRadians(
+              viewer.camera.positionCartographic.longitude,
+              viewer.camera.positionCartographic.latitude,
+              300
+            ),
+            orientation: orientation,
+          });
+        }
+        if (height > 2000) {
+          viewer.camera.setView({
+            destination: that.DC.Namespace.Cesium.Cartesian3.fromRadians(
+              viewer.camera.positionCartographic.longitude,
+              viewer.camera.positionCartographic.latitude,
+              2000
+            ),
+            orientation: orientation,
+          });
+        }
+      });
+
+      // 地图点击事件
+      viewer.on(DC.MouseEventType.CLICK, (e) => {
+        // console.log(e);
+        // 定制化窗体
+        that.openPopupS(
+          e.position,
+          [e.wgs84SurfacePosition.lng, e.wgs84SurfacePosition.lat],
+          {
+            name: "地图点击",
+            address: [e.wgs84SurfacePosition.lng, e.wgs84SurfacePosition.lat],
+            introduce: [e.windowPosition.x, e.windowPosition.y],
+            from: "地图点击",
+          }
+        );
+      });
+
+      //白模型↓
       // const layer = new DC.TilesetLayer("layer");
       // viewer.addLayer(layer);
       // const tileset = new DC.Tileset(
@@ -222,35 +273,123 @@
       // tileset.setStyle(style);
       // layer.addOverlay(tileset);
       // viewer.flyTo(tileset);
-      //自带白模型↑
+      //白模型↑
 
       //精细模型↓
-      const tilesetLayer = new that.DC.TilesetLayer("tilesetLayer");
-      viewer.addLayer(tilesetLayer);
-      const tileset = new that.DC.Tileset(
-        "http://data.mars3d.cn/3dtiles/max-shihua/tileset.json",
-        {
-          luminanceAtZenith: 0.5,
-        }
-      );
-      tilesetLayer.addOverlay(tileset);
+      // const tilesetLayer = new that.DC.TilesetLayer("tilesetLayer");
+      // viewer.addLayer(tilesetLayer);
+      // const tileset = new that.DC.Tileset(
+      //   "http://data.mars3d.cn/3dtiles/max-shihua/tileset.json",
+      //   {
+      //     luminanceAtZenith: 0.5,
+      //   }
+      // );
+      // tilesetLayer.addOverlay(tileset);
       //精细模型↑
 
-      setTimeout((res) => {
-        //转圈
-        that.$store.dispatch("mapFlyTo", {
-          lntLat: [111.25036579, 34.83767277, 11443175.85],
-          heading: 0,
-          pitch: -90,
-          roll: 0,
-          noOpen: true,
-          fn: function () {
-            viewer.flyTo(tileset);
-          },
+      // 2.5D贴图↓
+      var provider =
+        new that.DC.Namespace.Cesium.WebMapTileServiceImageryProvider({
+          url: "http://www.tdtfz.com/OneMapServer/rest/services/fzsw2019/MapServer/WMTS/tile/1.0.0/fzsw2019/{Style}/{TileMatrixSet}/{TileMatrix}/{TileRow}/{TileCol}",
+          layer: "fzsw2019",
+          style: "default",
+          tileMatrixSetID: "default028mm",
+          format: "image/jpgpng",
+          tilingScheme: new that.DC.Namespace.Cesium.GeographicTilingScheme(),
+          maximumLevel: 19,
+          tileMatrixLabels: [
+            "0",
+            "1",
+            "2",
+            "3",
+            "4",
+            "5",
+            "6",
+            "7",
+            "8",
+            "9",
+            "10",
+            "11",
+            "12",
+            "13",
+            "14",
+            "15",
+            "16",
+            "17",
+            "18",
+            "19",
+          ],
         });
 
-        // viewer.flyTo(tileset);
-      }, 2500);
+      viewer.imageryLayers.addImageryProvider(provider);
+      // 2.5D贴图↑
+      let startPoint;
+      if (false) {
+        setTimeout((res) => {
+          //转圈
+          that.$store.dispatch("mapFlyTo", {
+            lntLat: [111.25036579, 34.83767277, 11443175.85],
+            heading: 0,
+            pitch: -90,
+            roll: 0,
+            noOpen: true,
+            fn: function () {
+              // viewer.flyTo(tileset);
+              // viewer.flyTo(provider);
+              //飞入起始点
+              // that.$store.dispatch("mapFlyTo", {
+              //   lntLat: [115.87186406, 28.74449337, 1200],
+              //   heading: 0,
+              //   pitch: -45,
+              //   roll: 0,
+              //   noOpen: true,
+              // });
+              startPoint = () => {
+                that.$store.dispatch("mapFlyTo", {
+                  //飞入
+                  lntLat: [115.87988885, 28.72502592, 2100],
+                  // lntLat: [115.87186406, 28.74449337, 1200],
+                  // lntLat: [121.50492752204283, 31.21567802276832, 2530],
+                  heading: 0,
+                  pitch: -45,
+                  roll: 0,
+                  noOpen: true,
+                });
+              };
+              startPoint();
+            },
+          });
+          // viewer.flyTo(tileset);
+        }, 2500);
+      } else {
+        startPoint = (val) => {
+          console.log(val);
+          // viewer.zoomToPosition(
+          //   new DC.Position(115.86798885, 28.72502592, 2100, 0, -45)
+          // );
+          viewer.camera.setView({
+            // Cesium的坐标是以地心为原点,一向指向南美洲,一向指向亚洲,一向指向北极州
+            // fromDegrees()方法,将经纬度和高程转换为世界坐标
+            destination: that.DC.Namespace.Cesium.Cartesian3.fromDegrees(
+              116.390060025,
+              27.95649473,
+              2000.0
+            ),
+            orientation: {
+              // 指向
+              heading: that.DC.Namespace.Cesium.Math.toRadians(0, 0),
+              // 视角
+              pitch: that.DC.Namespace.Cesium.Math.toRadians(
+                val == "2D" ? -90 : val == "2.5D" ? -45 : -45
+              ),
+              roll: 0.0,
+            },
+          });
+        };
+        startPoint(that.dimension);
+      }
+      //传递默认位置
+      that.$store.commit("MSET_MORENWEIZHI", startPoint);
       // let position = Cesium.Cartesian3.fromDegrees(108, 25, 0); //中心点位置
       // let cameraLimit = new xt3d.CameraDominate.CameraLimit(
       //   viewer,
@@ -288,7 +427,8 @@
       const wall = new that.DC.Wall(arr);
       wall.setStyle({
         material: new that.DC.WallTrailMaterialProperty({
-          color: that.DC.Color.DEEPSKYBLUE,
+          color: that.DC.Namespace.Cesium.Color.fromBytes(0, 142, 255, 150),
+          // color: that.DC.Color.DEEPSKYBLUE,
           speed: 4,
         }),
       });
@@ -308,26 +448,38 @@
       //地图渲染完成执行srore中MSET_CREADE
       // that.$store.dispatch("MSET_CREADE");
 
-      tileset.on(DC.MouseEventType.CLICK, (e) => {
-        viewer.scene.globe.depthTestAgainstTerrain = false;
-        // console.log(e);
+      // tileset.on(DC.MouseEventType.CLICK, (e) => {
+      //   viewer.scene.globe.depthTestAgainstTerrain = false;
+      //   // console.log(e);
 
-        // 定制化窗体
-        that.openPopupS(
-          e.position,
-          [e.wgs84Position.lng, e.wgs84Position.lat],
-          {
-            name: e.layer._bid,
-            address: e.layer.type,
-            introduce: e.layer._id,
-          }
-        );
-      });
+      // viewer.flyToPosition(
+      //   new that.DC.Position(115.87186406, 28.74449337, 1800, 0, 45, 0)
+      // );
+
+      //   // 定制化窗体
+      //   that.openPopupS(
+      //     e.position,
+      //     [e.wgs84Position.lng, e.wgs84Position.lat],
+      //     {
+      //       name: e.layer._bid,
+      //       address: e.layer.type,
+      //       introduce: e.layer._id,
+      //     }
+      //   );
+      // });
 
       viewer.compass.enable = false;
       viewer.zoomController.enable = true;
       viewer.locationBar.enable = false;
       viewer.distanceLegend.enable = false;
+      if (true) {
+        // viewer.scene.screenSpaceCameraController.enableZoom = false; //控制视角缩放
+        viewer.scene.screenSpaceCameraController.enableTilt = false; //控制视角旋转
+        // viewer.scene.screenSpaceCameraController.minimumZoomDistance = 200; //最小缩放
+        // viewer.scene.screenSpaceCameraController.maximumZoomDistance = 1900; //最大缩放
+        // 2D和哥伦布视图
+        // 控制视角平移:scene.screenSpaceCameraController.enableTranslate = true;
+      }
     }
 
     DC.ready(initViewer);

--
Gitblit v1.9.3