From ddf60f1de7a1632e5673806838aa1ef74fd3886b Mon Sep 17 00:00:00 2001 From: guonan <guonan201020@163.com> Date: 星期二, 06 五月 2025 14:20:33 +0800 Subject: [PATCH] 修改选中区域flyTo以及标红;避险场所面片未清除;存储方案模拟区域 --- src/views/GisView.vue | 126 +++++++++++++++++++++++++++++++++++++++++ 1 files changed, 124 insertions(+), 2 deletions(-) diff --git a/src/views/GisView.vue b/src/views/GisView.vue index 0efd30b..0e069fc 100644 --- a/src/views/GisView.vue +++ b/src/views/GisView.vue @@ -16,6 +16,8 @@ import { isVisibleDistance } from "@/utils/customEntity"; import { getDistrictCount, getDistrictCountByCity } from "@/api/index"; import { useRoute } from "vue-router"; +import { EventBus } from "@/eventBus"; // 寮曞叆浜嬩欢鎬荤嚎 + const route = useRoute(); let handler = null; function initMap() { @@ -37,7 +39,6 @@ // 3. 璁剧疆褰撳墠鏃堕棿骞堕攣瀹� earthCtrl.viewer.clock.currentTime = julianDate; - //鏄剧ずfps earthCtrl.showFPS = true; earthCtrl.factory.createImageryLayer({ @@ -54,6 +55,124 @@ // viewer.scene.globe.depthTestAgainstTerrain = false; } +const MULTIPOLYGON_COORDS = ref([]); +let previousEntities = []; // 鐢ㄤ簬瀛樺偍涔嬪墠鍒涘缓鐨勫疄浣� +const flyToHeight = ref(null); + +// 鐩戝惉鏂板缓鏂规閫夋嫨鐨勫尯鍩熻寖鍥� +EventBus.on("select-geom", ({ geom, flyHeight }) => { + flyToHeight.value = flyHeight; + const coordsStr = geom + .replace("MULTIPOLYGON(((", "") // 鍘绘帀寮�澶� + .replace(")))", ""); // 鍘绘帀缁撳熬 + + // 鍒嗗壊鎴� ["lon lat", "lon lat", ...] + const coordPairs = coordsStr.split(","); + + // 杞崲涓� [[[lon, lat], [lon, lat], ...]] 鏍煎紡 + MULTIPOLYGON_COORDS.value = [ + coordPairs.map((pair) => { + const [lon, lat] = pair.trim().split(" ").map(Number); + return [lon, lat]; + }), + ]; + + // 妫�鏌ユ槸鍚︽槸绌哄杈瑰舰,濡傛灉鏄┖锛屽垯鍘绘帀闈㈢墖棰滆壊锛屽苟椋炲洖鍒濆浣嶇疆 + if (geom === "MULTIPOLYGON EMPTY") { + clearPreviousEntities(); + flyToHomeView(); + return; // 涓嶆墽琛屽悗缁搷浣� + } + + // 娓呴櫎涔嬪墠鐨勬墍鏈夊疄浣� + clearPreviousEntities(); + // 閫変腑鍖哄煙鏍囪壊 + addCustomPolygon(); +}); + +// 娓呴櫎涔嬪墠鐨勬墍鏈夊疄浣� +function clearPreviousEntities() { + previousEntities.forEach((entity) => { + viewer.entities.remove(entity); + }); + previousEntities = []; +} + +// 璁$畻閫変腑鍖哄煙涓績鐐� +function calculateCenter(coordinates) { + const lons = coordinates.flat().map((coord) => coord[0]); + const lats = coordinates.flat().map((coord) => coord[1]); + return { + lon: (Math.min(...lons) + Math.max(...lons)) / 2, + lat: (Math.min(...lats) + Math.max(...lats)) / 2, + }; +} + +function convertToGeoJson(coords) { + return { + type: "Feature", + id: 0, + bbox: calculateCenter(MULTIPOLYGON_COORDS.value), // 鍙�� + properties: { + center: calculateCenter(MULTIPOLYGON_COORDS.value), // 绗竴涓偣浣滀负 center + centroid: MULTIPOLYGON_COORDS.value[0][0], // 鍙�� + level: "district", + code: 123456, + districtCount: 0, + }, + geometry: { + type: "MultiPolygon", + coordinates: [coords], // 鍖呰鎴� MultiPolygon + }, + }; +} + +function addCustomPolygon() { + // 灏� MULTIPOLYGON_COORDS.value 杞崲涓� GeoJSON 鏍煎紡 + const geoJson = convertToGeoJson(MULTIPOLYGON_COORDS.value); + const center = geoJson.properties.center; + + // 鍒涘缓澶氳竟褰㈠疄浣� + const polygonEntity = viewer.entities.add({ + // name: "鑷畾涔夊尯鍩�", + polygon: { + hierarchy: Cesium.Cartesian3.fromDegreesArray( + geoJson.geometry.coordinates[0][0].flat() + ), + material: Cesium.Color.RED.withAlpha(0.3), // 鍗婇�忔槑绾㈣壊濉厖 + outline: true, + outlineColor: Cesium.Color.RED, // 绾㈣壊杈规 + outlineWidth: 5, + clampToGround: true, // 璐村湴鏄剧ず + }, + }); + previousEntities.push(polygonEntity); + + // 椋炲悜涓績鐐� + viewer.camera.flyTo({ + destination: Cesium.Cartesian3.fromDegrees( + center.lon, + center.lat, + flyToHeight.value + ), // 鎻愰珮鍒� 100000绫抽珮搴� + orientation: { + heading: Cesium.Math.toRadians(0), // 姝e寳鏂瑰悜 + pitch: Cesium.Math.toRadians(-90), // 鍚戜笅鍊炬枩90搴︼紙鍨傜洿淇锛� + roll: 0.0, + }, + }); + + console.log( + flyToHeight.value, + "flyToHeight.value flyToHeight.value flyToHeight.value " + ); +} + +EventBus.on("close-selectArea", () => { + clearPreviousEntities(); + flyToHomeView(); +}); + function addCityPolygon() { const url = `/json/110000.geo.json`; let wallLayer = earthCtrl.factory.createTrailWallLayer({ @@ -67,8 +186,8 @@ }); return dataSourcePromise.then(function (dataSource) { viewer.dataSources.add(dataSource); + // 鎵�鏈夌殑鏁版嵁 const polygonEntity = dataSource.entities.values; - // console.log("polygonEntity", polygonEntity) const distanceDisplayCondition = new Cesium.DistanceDisplayCondition( 1000, 50000000 @@ -327,6 +446,7 @@ onMounted(() => { initMap(); + // 鍦ㄤ綘鐨勫垵濮嬪寲浠g爜涓皟鐢ㄨ繖涓嚱鏁� addCityPolygon(); initHandler(); // initView() @@ -340,6 +460,8 @@ }); onUnmounted(() => { removeCameraChange(); + EventBus.off("select-geom"); + EventBus.off("close-selectArea"); }); </script> -- Gitblit v1.9.3