suerprisePlus
2024-08-14 d4a3ca549f8755c2f87442c27217c3be39cab5cc
src/assets/js/mapSdk/mapServe.js
@@ -1,6 +1,7 @@
import mapConfig from './mapConfig';
import { zhangzitou_selectAll } from '@/api/mapView/map.js';
import WKT from 'terraformer-wkt-parser';
import store from '@/store';
// 服务加载
const mapServer = {
    serveType: null,
@@ -39,7 +40,7 @@
                var geom = WKT.parse(item.geom).coordinates;
                const terrain = config.terrain;
                if (terrain.isShow && terrain.isUrl) {
                    this.addTerrainGLB(geom);
                    this.addTerrainGLB(item, geom, modelLayer);
                } else {
                    this.addGLB(item, geom, modelLayer);
                }
@@ -52,16 +53,33 @@
            });
        });
    },
    addTerrainGLB(geom) {
    addTerrainGLB(item, geom, modelLayer) {
        var positions = [Cesium.Cartographic.fromDegrees(geom[0], geom[1])];
        var promise = Cesium.sampleTerrainMostDetailed(Viewer.terrainProvider, positions);
        promise.then(updatedPositions => {
            console.log(updatedPositions);
        promise.then((updatedPositions) => {
            var terrainHeight = updatedPositions[0].height;
            var style = {
                longitude: geom[0],
                latitude: geom[1],
                altitude: terrainHeight,
                heading: 0,
                pitch: 0,
                roll: 0,
            };
            const modelMatrix = mapConfig.getModelMatrix(style);
            const url = '/glb/' + item.type + '.glb';
            modelLayer.add(
                Cesium.Model.fromGltf({
                    id: item.id,
                    url: url,
                    scale: 1,
                    minimumPixelSize: 20,
                    maximumScale: 20,
                    modelMatrix: modelMatrix,
                    primitive: item,
        })
        // SmartEarth.Cesium.when(promise, (updatedPositions) => {
        //     var terrainHeight = updatedPositions[0].height;
        //     console.log(terrainHeight);
        // });
            );
        });
    },
    addGLB(item, geom, modelLayer) {
        var style = {
@@ -154,7 +172,9 @@
        });
        const cnName = res.cnName + '_' + res.id;
        model.item.readyPromise.then((item) => {
            if (res.id != 'baseModel') {
            mapConfig.userSceneFlyTo(item);
            }
            this.layerList.push({
                id: res.id,
                name: cnName,
@@ -163,7 +183,6 @@
            });
        });
    },
    setTilesetArgs() {},
    removeLayer(res) {
        const cnName = res.cnName + '_' + res.id;
        this.layerList.map((item, index) => {
@@ -181,8 +200,46 @@
            }
        });
    },
    async getFeatureInfo(res) {
        console.log(res);
    async getFeatureInfo(html) {
        var start = html.indexOf('<caption class="featureInfo">') + '<caption class="featureInfo">'.length;
        var end = html.indexOf('</caption>');
        var tab = html.substr(start, end - start);
        var std = html
            .substr(html.indexOf('<th>'), html.lastIndexOf('</th>') - html.indexOf('<th>') + 5)
            .replaceAll(' ', '')
            .replaceAll('\n', '')
            .split('</th>');
        var str = html
            .substr(html.indexOf('<td>'), html.lastIndexOf('</td>') - html.indexOf('<td>') + 5)
            .replaceAll(' ', '')
            .replaceAll('\n', '')
            .split('</td>');
        var arr = [];
        for (var i in std) {
            var name, val;
            name = std[i];
            val = str[i];
            if (name == '') {
                continue;
            }
            if (name.indexOf('<th>') > -1) {
                name = name.replaceAll('<th>', '');
            }
            if (val.indexOf('<td>') > -1) {
                val = val.replaceAll('<td>', '');
            }
            if (name != '>') {
                arr.push({
                    name: name,
                    val: val,
                });
            }
        }
        store.dispatch('mapLayers/changeMapInfo', []);
        if (arr.length > 0) {
            // this.$store.geet.mapInfo = arr;
            store.dispatch('mapLayers/changeMapInfo', arr);
        }
    },
};
export default mapServer;