From 8f85627f215bd0ee61db7a35ca9a83eaca1e892c Mon Sep 17 00:00:00 2001 From: surprise <15810472099@163.com> Date: 星期三, 10 一月 2024 15:42:34 +0800 Subject: [PATCH] 代码更新 --- src/assets/js/Layer/mapGeo.js | 146 ++++++++++++++++++++++++++++++++++-------------- 1 files changed, 104 insertions(+), 42 deletions(-) diff --git a/src/assets/js/Layer/mapGeo.js b/src/assets/js/Layer/mapGeo.js index 83da005..72700d9 100644 --- a/src/assets/js/Layer/mapGeo.js +++ b/src/assets/js/Layer/mapGeo.js @@ -1,7 +1,15 @@ var source = [] +import { Grid_SelectById ,Grid_DeleteByIds} from '@/api/api' const mapGeo = { source1: null, + type: null, + feature: [], + gridId: null, init(res) { + if (this.type && this.type === res) { + return this.type = null + } + this.type = res; switch (res.type) { case "WangGe": this.addWangGeGeoJson(res); @@ -17,26 +25,105 @@ break; case "zhaiHai": this.addzhaiHaiGeoJson(res) - + break; + case "ZhongPo": + this.addZhongPoGeoJson(res) break; } }, - delGeoSource(res) { - if (res.type == "zhaiHai") { - Viewer.dataSources.remove(Viewer.dataSources.getByName("zhaiHai2")[0]) - Viewer.dataSources.remove(Viewer.dataSources.getByName("zhaiHai1")[0]) - Viewer.dataSources.remove(Viewer.dataSources.getByName("zhaiHai3")[0]) - } else { - if (!res.type) return; - Viewer.dataSources.remove(Viewer.dataSources.getByName(res.type)[0]) + addGridLayer(res) { + var ids = res.style.ids; + var length = ids.length; + if (res.id == this.gridId) { + this.gridId = null; + return } + this.gridId = res.id; + this.feature = []; + for (var i = 0; i < length; i++) { + this.getGridids(ids[i], length); + } + }, + delGridLayer(res) { + if(!res)return + Viewer.dataSources.remove(Viewer.dataSources.getByName(res.id)[0]) + }, + removeGridData(res) { + this.delGridLayer(res); + var ids = res.style.ids; + for (var i = 0; i < ids.length; i++) { + this.delGridIds(ids[i]); + } + }, + async delGridIds(res) { + console.log(res) + const data = await Grid_DeleteByIds(res); + }, + async getGridids(id, length, index) { + const data = await Grid_SelectById(id) + if (data.status == 200) { + var val_data = data.data.features[0]; + val_data.properties["gid"] = id; + this.feature.push(val_data) + if (this.feature.length == length) { + var feature = { + "type": "FeatureCollection", + "name": "wangge", + "crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } }, + "features": this.feature, + } + + this.addGridMenuGeoJson(feature) + } + } + + + }, + addGridMenuGeoJson(res) { + var data = Cesium.GeoJsonDataSource.load(res, //瑕佸姞杞界殑 url銆丟eoJSON 瀵硅薄鎴� TopoJSON 瀵硅薄銆� + { + stroke: Cesium.Color.ORANGE, //鎶樼嚎鍜屽杈瑰舰杞粨鐨勯粯璁ら鑹层�� + fill: Cesium.Color.WHITE.withAlpha(0.2), //澶氳竟褰㈠唴閮ㄧ殑榛樿棰滆壊銆� + strokeWidth: 3, //鎶樼嚎鍜屽杈瑰舰杞粨鐨勯粯璁ゅ搴︺�� + } + ) + data.then((dataSource) => { + dataSource.name = this.gridId; + Viewer.dataSources.add( + dataSource + ); + }) + }, + addZhongPoGeoJson(res) { + var url = layerData.config.Model_URL + res.urls; + var data = Cesium.GeoJsonDataSource.load(url, //瑕佸姞杞界殑 url銆丟eoJSON 瀵硅薄鎴� TopoJSON 瀵硅薄銆� + { + stroke: Cesium.Color.ORANGE, //鎶樼嚎鍜屽杈瑰舰杞粨鐨勯粯璁ら鑹层�� + fill: Cesium.Color.WHITE.withAlpha(0.2), //澶氳竟褰㈠唴閮ㄧ殑榛樿棰滆壊銆� + strokeWidth: 3, //鎶樼嚎鍜屽杈瑰舰杞粨鐨勯粯璁ゅ搴︺�� + } + ) + data.then((dataSource) => { + dataSource.name = res.type + Viewer.dataSources.add( + dataSource + ); + }) + }, + delGeoSource(res) { + if (this.type && this.type == res) { + this.type = null + } + + if (!res.type) return; + Viewer.dataSources.remove(Viewer.dataSources.getByName(res.type)[0]) + }, addzhaiHaiGeoJson(res) { - var url1 = layerData.config.Model_URL + res.urls[0]; - var url2 = layerData.config.Model_URL + res.urls[1]; - var url3 = layerData.config.Model_URL + res.urls[2]; + var url1 = layerData.config.Model_URL + res.urls; + var color = Cesium.Color.fromCssColorString("rgb(255,0,255)") var data1 = Cesium.GeoJsonDataSource.load(url1, //瑕佸姞杞界殑 url銆丟eoJSON 瀵硅薄鎴� TopoJSON 瀵硅薄銆� { @@ -46,38 +133,13 @@ } ) data1.then((dataSource) => { - dataSource.name = "zhaiHai1" + dataSource.name = res.type Viewer.dataSources.add( dataSource ); }) - var data2 = Cesium.GeoJsonDataSource.load(url2, //瑕佸姞杞界殑 url銆丟eoJSON 瀵硅薄鎴� TopoJSON 瀵硅薄銆� - { - stroke: color, //鎶樼嚎鍜屽杈瑰舰杞粨鐨勯粯璁ら鑹层�� - fill: Cesium.Color.WHITE.withAlpha(0.2), //澶氳竟褰㈠唴閮ㄧ殑榛樿棰滆壊銆� - strokeWidth: 3, //鎶樼嚎鍜屽杈瑰舰杞粨鐨勯粯璁ゅ搴︺�� - } - ) - data2.then((dataSource) => { - dataSource.name = "zhaiHai2" - Viewer.dataSources.add( - dataSource - ); - }) - var data3 = Cesium.GeoJsonDataSource.load(url3, //瑕佸姞杞界殑 url銆丟eoJSON 瀵硅薄鎴� TopoJSON 瀵硅薄銆� - { - stroke: color, //鎶樼嚎鍜屽杈瑰舰杞粨鐨勯粯璁ら鑹层�� - fill: Cesium.Color.WHITE.withAlpha(0.2), //澶氳竟褰㈠唴閮ㄧ殑榛樿棰滆壊銆� - strokeWidth: 3, //鎶樼嚎鍜屽杈瑰舰杞粨鐨勯粯璁ゅ搴︺�� - } - ) - data3.then((dataSource) => { - dataSource.name = "zhaiHai3" - Viewer.dataSources.add( - dataSource - ); - }) + }, addZhongQuXianGeoJson(res) { @@ -129,11 +191,11 @@ }) }, addZhuangHaoGeoJson(res) { - + var url = layerData.config.Model_URL + res.urls; var img = layerData.config.Model_URL + '/Data/img/img1.png'; - Cesium.GeoJsonDataSource.load(url).then((dataSource) => { - + Cesium.GeoJsonDataSource.load(url).then((dataSource) => { + dataSource.name = res.type Viewer.dataSources.add( dataSource -- Gitblit v1.9.3