| | |
| | | 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, |
| | |
| | | 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); |
| | | } |
| | |
| | | }); |
| | | }); |
| | | }, |
| | | 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); |
| | | }) |
| | | // SmartEarth.Cesium.when(promise, (updatedPositions) => { |
| | | // var terrainHeight = updatedPositions[0].height; |
| | | // console.log(terrainHeight); |
| | | // }); |
| | | 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, |
| | | url: url, |
| | | scale: 1, |
| | | minimumPixelSize: 20, |
| | | maximumScale: 20, |
| | | modelMatrix: modelMatrix, |
| | | primitive: item, |
| | | }) |
| | | ); |
| | | }); |
| | | }, |
| | | addGLB(item, geom, modelLayer) { |
| | | var style = { |
| | |
| | | const url = '/glb/' + item.type + '.glb'; |
| | | modelLayer.add( |
| | | Cesium.Model.fromGltf({ |
| | | id: item.id, |
| | | id: item, |
| | | url: url, |
| | | scale: 1, |
| | | minimumPixelSize: 20, |
| | |
| | | }); |
| | | const cnName = res.cnName + '_' + res.id; |
| | | model.item.readyPromise.then((item) => { |
| | | mapConfig.userSceneFlyTo(item); |
| | | if (res.id != 'baseModel') { |
| | | mapConfig.userSceneFlyTo(item); |
| | | } |
| | | this.layerList.push({ |
| | | id: res.id, |
| | | name: cnName, |
| | |
| | | }); |
| | | }); |
| | | }, |
| | | setTilesetArgs() {}, |
| | | removeLayer(res) { |
| | | const cnName = res.cnName + '_' + res.id; |
| | | this.layerList.map((item, index) => { |
| | |
| | | } |
| | | }); |
| | | }, |
| | | 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; |