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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<template>
  <mars-pannel :visible="true" right="10" top="10" bottom="40" width="255">
    <div style="width: 220px">
      <div class="f-mb infoView-content">
        <a-space>
          <span>模型列表: </span>
          <a-upload :multiple="false" name="file" accept="json,geojson" :showUploadList="false" @change="openGeoJSON" :beforeUpload="() => false">
            <i title="打开GeoJSON文件"><mars-icon icon="folder-upload" width="19" /></i>
          </a-upload>
          <i title="保存GeoJSON"><mars-icon icon="disk" width="17" color="#f2f2f2" @click="saveGeoJSON" /></i>
        </a-space>
      </div>
 
      <div class="f-mb">
        <a-checkbox @change="chkTestTerrain" v-model:checked="isTestTerrain" title="深度检测">深度</a-checkbox>
        <a-checkbox @change="onlyPickModelPosition" v-model:checked="isonlyModel">仅在Tiles上拾取</a-checkbox>
      </div>
 
      <div class="f-mb">
        <mars-select
          ref="select"
          v-model:value="value1"
          style="width: 200px; margin-left: 10px"
          :options="selectOptions"
          @change="handleChange"
        ></mars-select>
 
        <div class="f-mb gltfImg">
          <ul>
            <li v-for="imgs in dataList" :key="imgs.name">
              <img :src="imgs.image" alt="" @click="showModel(imgs.style)" />
            </li>
          </ul>
        </div>
      </div>
    </div>
  </mars-pannel>
</template>
 
<script lang="ts" setup>
import { ref, markRaw } from "vue"
import { useWidget } from "@mars/widgets/common/store/widget"
import * as mapWork from "./map.js"
 
const { activate, disable, isActivate, updateWidget } = useWidget()
 
interface FileItem {
  uid: string
  name?: string
  status?: string
  response?: string
  url?: string
}
 
interface FileInfo {
  file: FileItem
  fileList: FileItem[]
}
 
// 深度检测
const isTestTerrain = ref<boolean>(false)
const chkTestTerrain = () => {
  mapWork.chkTestTerrain(isTestTerrain.value)
}
 
// 仅在模型上绘制
const isonlyModel = ref<boolean>(false)
const onlyPickModelPosition = () => {
  mapWork.onlyPickModelPosition(isonlyModel.value)
}
 
// 绘制模型
const showModel = (style: any) => {
  mapWork.startDrawModel(style)
}
 
//* **********************下拉框******************* */
let modelData: any
const selectOptions = ref<any[]>([])
const value1 = ref<string>("车辆")
const dataList = ref<any[]>([])
 
mapWork.eventTarget.on("loadModelList", function (event: any) {
  modelData = event.data
  // 下拉框数据
  Object.keys(modelData).forEach((k) => {
    selectOptions.value.push({
      value: k,
      lable: k
    })
  })
  handleChange()
})
// 下拉框改变
const handleChange = () => {
  dataList.value = modelData[value1.value]
 
  for (let i = 0; i < dataList.value.length; i++) {
    const item = dataList.value[i]
 
    item.image = mapWork.changeItemImage(item)
    item.style.url = mapWork.changeItemUrl(item)
    dataList.value[i] = item
  }
}
 
// ************************JSON文件************************/
// 打开
const openGeoJSON = (info: FileInfo) => {
  const item = info.file
  const fileName = item.name
  const fileType = fileName?.substring(fileName.lastIndexOf(".") + 1, fileName.length).toLowerCase()
  if (fileType !== "json") {
    alert("文件类型不合法,请选择json格式标注文件!")
  }
  mapWork.openGeoJSON(item)
}
// 点击保存GeoJSON
const saveGeoJSON = () => {
  mapWork.saveGeoJSON()
}
 
// ************************属性面板************************/
 
const showEditor = (e: any) => {
  if (!isActivate("graphic-editor")) {
    activate({
      name: "graphic-editor",
      data: { graphic: markRaw(e.graphic) }
    })
  }
}
mapWork.eventTarget.on("graphicEditor-start", async (e: any) => {
  showEditor(e)
})
// 编辑修改了模型
mapWork.eventTarget.on("graphicEditor-update", async (e: any) => {
  updateWidget("graphic-editor", {
    data: { graphic: markRaw(e.graphic) }
  })
  showEditor(e)
})
 
// 停止编辑修改模型
mapWork.eventTarget.on("graphicEditor-stop", async (e: any) => {
  setTimeout(() => {
    if (!mapWork.graphicLayer.isEditing) {
      disable("graphic-editor")
    }
  }, 100)
})
</script>
<style scoped lang="less">
.infoView-content {
  height: 20px;
  width: 210px;
  line-height: 20px;
  background-color: rgba(32, 42, 68, 0.5);
  overflow: hidden;
}
 
.gltfImg {
  width: 100%;
  margin-top: 10px;
  margin-left: 10px;
  overflow-x: hidden;
  overflow-y: auto;
}
 
.gltfImg li {
  display: inline-block;
  margin-right: 5px;
  width: 100px;
  text-align: center;
  padding-bottom: 10px;
}
 
.gltfImg img {
  width: 100px;
  height: 90px;
  border: 1.5px solid white;
}
.ant-upload {
  line-height: 0 !important;
}
</style>