From a9437751269e33a0eaaccd83acd9a35aff20b04e Mon Sep 17 00:00:00 2001 From: zouyaoji <370681295@qq.com> Date: Tue, 28 May 2024 11:00:43 +0800 Subject: [PATCH] =?UTF-8?q?feat(dynamic-render):=20:sparkles:=20geojson?= =?UTF-8?q?=E4=B8=8D=E5=B1=95=E7=A4=BA=E5=AD=90=E8=8A=82=E7=82=B9=E4=BE=8B?= =?UTF-8?q?=E5=AD=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/modules/tree-data.ts | 35 ++++++++++++++++++++++++++++++++-- src/utils/render-data.ts | 37 +++++++++++++++++++++++++++--------- 2 files changed, 61 insertions(+), 11 deletions(-) diff --git a/src/api/modules/tree-data.ts b/src/api/modules/tree-data.ts index 299a38d..afe99d2 100644 --- a/src/api/modules/tree-data.ts +++ b/src/api/modules/tree-data.ts @@ -1,8 +1,8 @@ /* * @Author: zouyaoji@https://github.com/zouyaoji * @Date: 2022-07-21 17:27:55 - * @LastEditTime: 2022-09-12 23:49:12 - * @LastEditors: zouyaoji + * @LastEditTime: 2024-05-28 10:58:05 + * @LastEditors: zouyaoji 370681295@qq.com * @Description: * @FilePath: \vue-cesium-demo\src\api\modules\tree-data.ts */ @@ -279,6 +279,37 @@ export default [ } } ] + }, + { + id: uuidv4(), + name: 'GeoJSON', + icon: '', + checked: false, + expanded: false, + renderingType: 'geojson', + children: [ + { + type: 'Feature', + properties: { + id: uuidv4(), + checked: false, + name: '水系', + props: { + geojson: { + strokeWidth: 5, + stroke: '#ffc107', + fill: 'transparent', + show: false, + data: `${import.meta.env.BASE_URL}datas/work-bench/水系.json` + } + } + }, + geometry: { + coordinates: [108.965836, 34.225607], + type: 'Point' + } + } + ] } ] } diff --git a/src/utils/render-data.ts b/src/utils/render-data.ts index efbad4f..916f43d 100644 --- a/src/utils/render-data.ts +++ b/src/utils/render-data.ts @@ -1,8 +1,8 @@ /* * @Author: zouyaoji@https://github.com/zouyaoji * @Date: 2021-10-28 10:19:54 - * @LastEditTime: 2022-10-20 01:18:16 - * @LastEditors: zouyaoji + * @LastEditTime: 2024-05-28 10:56:31 + * @LastEditors: zouyaoji 370681295@qq.com * @Description: * @FilePath: \vue-cesium-demo\src\utils\render-data.ts */ @@ -137,8 +137,8 @@ export function highlightRenderData( selectedFeatureProps && isPlainObject(selectedFeatureProps) ? selectedFeatureProps : selectedFeatureProps - ? JSON.parse(selectedFeatureProps) - : {} + ? JSON.parse(selectedFeatureProps) + : {} const props = renderingApi === 'primitive' ? model : model[renderingType] const selectedRenderProps = selectedProps?.[renderingType] @@ -714,19 +714,38 @@ const addRenderDataset = (dataset: VcDataset, page: string, type: string, render dataset.props && isPlainObject(dataset?.props) ? dataset?.props : dataset.props - ? JSON.parse(dataset?.props) - : {} + ? JSON.parse(dataset?.props) + : {} const featureProps = feature.properties?.props && isPlainObject(feature.properties?.props) ? feature.properties?.props : feature.properties.props - ? JSON.parse(feature.properties?.props) - : {} + ? JSON.parse(feature.properties?.props) + : {} // 优先取 feature 上的 props 参数 const props = Object.assign({}, datasetProps, featureProps) - if (dataset.renderingType === 'tileset') { + if (dataset.renderingType === 'geojson') { + const vcProps = Object.assign( + {}, + props[dataset.renderingType], + feature.properties?.props?.[dataset.renderingType] + ) + + feature.properties.actualRenderingType = dataset.renderingType + renderData.datasets.push({ + cmpName: 'VcDatasourceGeojson', + props: { + ...vcProps, + show: toRef(feature.properties, 'checked'), + onReady: (e: VcReadyObject) => { + resolve(e) + } + } as VcDatasourceGeojsonProps, + feature + }) + } else if (dataset.renderingType === 'tileset') { const vcProps = Object.assign( {}, props[dataset.renderingType],