fuchengshen
2022-07-09 3a25c05b5ab837714f30469cdcb1e2a77d8d7f6c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<template>
  <mars-pannel :visible="true" right="10" top="10">
    <div class="f-mb">
      <span>3dtile模型移动(只适合小范围内的偏移 笛卡尔坐标方向,非贴球面)</span>
    </div>
 
    <div class="f-mb">
      <a-space>
        <span class="mars-pannel-item-label">模型URL:</span>
        <mars-input class="model-input" v-model:value="url"></mars-input>
        <mars-button class="model-button" @click="showModel">加载模型</mars-button>
      </a-space>
    </div>
 
    <div class="f-mb">
      <a-space>
        <span>设置移动步长:</span>
        <mars-button @click="getValue(0.1)" value="">0.1</mars-button>
        <mars-button @click="getValue(1)" value="1">1</mars-button>
        <mars-button @click="getValue(10)" value="10">10</mars-button>
        <mars-button @click="getValue(100)" value="100">100</mars-button>
      </a-space>
    </div>
 
    <div class="f-mb">
      <a-space>
        <span class="mars-pannel-item-label">按步长移动:</span>
        <mars-button @click="moveModel(0)">x+</mars-button>
        <mars-button @click="moveModel(1)">x-</mars-button>
 
        <mars-button @click="moveModel(2)">y+</mars-button>
        <mars-button @click="moveModel(3)">y-</mars-button>
 
        <mars-button @click="moveModel(4)">z+</mars-button>
        <mars-button @click="moveModel(5)">z-</mars-button>
      </a-space>
    </div>
 
    <div>
      <a-space> <span class="mars-pannel-item-label">当前偏移量: </span>{{ result }} </a-space>
    </div>
 
    <div>
      <a-space>
        <span class="mars-pannel-item-label"></span>
        <a-checkbox @change="chkHasTerrain" v-model:checked="enableHasTerrain">是否有地形</a-checkbox>
        <a-checkbox @change="chkTestTerrain" v-model:checked="enableTestTerrain">是否深度检测</a-checkbox>
      </a-space>
    </div>
  </mars-pannel>
</template>
 
<script setup lang="ts">
import { onMounted, ref } from "vue"
import * as mapWork from "./map.js"
 
const url = ref<any>()
 
const result = ref<string>("x:0.0" + " y:0.0" + " z:0.0")
 
const enableHasTerrain = ref<boolean>(false)
 
const enableTestTerrain = ref<boolean>(false)
 
onMounted(() => {
  // url传入模型地址
  const modelUrl = localStorage.getItem("3dtiles_move")
  if (modelUrl) {
    // 历史记录模型地址
    url.value = modelUrl
  } else {
    url.value = "//data.mars3d.cn/3dtiles/qx-dyt/tileset.json"
  }
 
  setTimeout(() => {
    mapWork.showModel(url.value)
  }, 1000)
})
 
// 加载模型
const showModel = () => {
  localStorage.setItem("3dtiles_move", url.value)
  mapWork.showModel(url.value)
}
 
let x = 0
let y = 0
let z = 0
let step = 1
 
const moveModel = (type: number) => {
  switch (type) {
    case 0:
      x += step
      break
    case 1:
      x -= step
      break
    case 2:
      y += step
      break
    case 3:
      y -= step
      break
    case 4:
      z += step
      break
    case 5:
      z -= step
      break
    default:
  }
 
  result.value = "x:" + x.toFixed(1) + " y:" + y.toFixed(1) + " z:" + z.toFixed(1)
  mapWork.setTranslation(x, y, z)
}
 
// 是否有地形
const chkHasTerrain = () => {
  mapWork.chkHasTerrain(enableHasTerrain.value)
}
 
// 深度检测
const chkTestTerrain = () => {
  mapWork.chkTestTerrain(enableTestTerrain.value)
}
 
//  设置步长
const getValue = (val: number) => {
  step = val
}
</script>
<style scoped lang="less">
.mars-pannel-item-label {
  width: 83px;
}
 
.model-input {
  width: 145%;
}
 
.model-button {
  margin-left: 75px;
}
</style>