Koishi hai 1 semana
pai
achega
8f306a2979
Modificáronse 1 ficheiros con 64 adicións e 3 borrados
  1. 64 3
      src/views/cesium.vue

+ 64 - 3
src/views/cesium.vue

@@ -139,6 +139,8 @@ import windPro from "@/components/windProDetail/windProblem.vue";
 import cesiumwindView from "./cesiumComponents/cesiumwindView.vue";
 import timeControl from "@/components/timeControl/index.vue";
 
+import * as turf from "@turf/turf";
+
 export default {
   name: "CesiumMap",
 
@@ -233,9 +235,12 @@ export default {
       controlMode: "",
     };
   },
+
   created() {
     this.getWeatherData();
+    // console.log(1111, this.findLocation(109.6429758178942, 34.10868446715471));
   },
+
   mounted() {
     this.initEventListener();
     this.initCesium();
@@ -257,6 +262,60 @@ export default {
   },
 
   methods: {
+    // 传入经纬度,获取经纬度所在的行政区信息
+    findLocation(lng, lat) {
+      const point = turf.point([lng, lat]);
+      let foundProvince = null;
+      let foundCity = null;
+
+      // 遍历所有要素查找包含点的多边形
+      for (const feature of basicGeoJson.features) {
+        try {
+          if (
+            feature.geometry &&
+            turf.booleanPointInPolygon(point, feature.geometry)
+          ) {
+            const properties = feature.properties;
+
+            // 根据你的GeoJSON结构调整属性名
+            // 常见的有:name, NAME, 省, 市, province, city等
+            const province =
+              properties.province || properties.省 || properties.name;
+            const city = properties.city || properties.市 || properties.name;
+
+            // 如果是省级数据(没有city属性)
+            if (city === province || !properties.city) {
+              if (!foundProvince) {
+                foundProvince = {
+                  province: province,
+                  adcode: properties.adcode || properties.code,
+                  geometry: feature.geometry,
+                  properties: properties,
+                };
+              }
+            } else {
+              // 市级数据
+              foundCity = {
+                province: province,
+                city: city,
+                adcode: properties.adcode || properties.code,
+                geometry: feature.geometry,
+                properties: properties,
+              };
+              break; // 找到市级就停止
+            }
+          }
+        } catch (error) {
+          console.warn("处理要素时出错:", error);
+          continue;
+        }
+      }
+
+      const result = foundCity || foundProvince;
+
+      return result;
+    },
+
     changeType(value) {
       this.stationValue = value;
       this.allStationentitys.forEach(({ entity, handler }) => {
@@ -401,7 +460,9 @@ export default {
 
       // 隐藏 Cesium Logo
       viewer.cesiumWidget.creditContainer.style.display = "none";
-      viewer.scene.globe.baseColor = Cesium.Color.BLACK;
+      viewer.scene.globe.baseColor = new Cesium.Color.fromCssColorString(
+        "#1890ff"
+      );
       // 禁用 Viewer 默认的双击缩放
       viewer.cesiumWidget.screenSpaceEventHandler.removeInputAction(
         Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK
@@ -413,7 +474,7 @@ export default {
 
       // this.setMapImageryProvider();
       // this.initCesiumTerrain();
-      this.initCesiumBaseMapImage();
+      // this.initCesiumBaseMapImage();
       //   this.switchWindLayer();
       this.showAllStation(viewer, allStationJson.station);
       this.initGeoJsonData();
@@ -928,7 +989,7 @@ export default {
 
           entity.polyline = {
             positions: positions,
-            width: 2,
+            width: 0.5,
             outline: false,
             // clampToGround: true,
             show: true,