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
<template>
  <mars-dialog title="属性编辑" width="260" top="60" bottom="40" left="10" :minWidth="200">
    <div class="top-handle-bar">
      <a-space>
        <mars-icon icon="send" width="20" @click="flyToGraphic" title="飞行定位"></mars-icon>
        <mars-icon icon="delete" width="20" @click="deleteEntity" title="删除"></mars-icon>
        <mars-icon icon="save" width="20" @click="getGeoJson" title="导出geojson"></mars-icon>
      </a-space>
    </div>
    <div class="attr-editor-main">
      <mars-styles :styleConfig="styleConfig" :style="style" @styleChange="styleChange" />
    </div>
  </mars-dialog>
</template>
 
<script setup lang="ts">
import { ref, provide, onMounted, toRaw } from "vue"
import useLifecycle from "@mars/widgets/common/uses/use-lifecycle"
import MarsStyles from "./mars-styles.vue"
import graphicAttr from "./attr.json"
import * as mapWork from "./map"
import _ from "lodash"
import { useWidget } from "@mars/widgets/common/store/widget"
 
const { currentWidget, updateWidget } = useWidget()
 
// 启用map.ts生命周期
useLifecycle(mapWork)
 
provide("getGraphicAttr", () => {
  return graphicAttr
})
 
let graphic = currentWidget.data.graphic
provide("getGraphic", () => {
  return graphic
})
 
const styleConfig = ref(null)
const style = ref(null)
 
onMounted(() => {
  updataLayer()
})
 
if (currentWidget) {
  currentWidget.onUpdate((e) => {
    graphic = e.data.graphic
    updataLayer()
  })
}
 
// 监听到矢量数据发生变化
function updataLayer() {
  style.value = _.cloneDeep(graphic.style)
  const config = (graphicAttr as any)[graphic.options?.edittype || graphic.type] || {}
  styleConfig.value = config
}
 
function flyToGraphic() {
  // 事件处理
  graphic.flyTo()
}
 
function deleteEntity() {
  // 删除
  graphic.remove()
}
 
function getGeoJson() {
  // 文件处理
  const geojson = graphic.toGeoJSON()
  geojson.properties._layer = graphic._layer.name
 
  mapWork.downloadFile("标绘item.json", JSON.stringify(geojson))
}
 
function styleChange(style: any) {
  console.log("修改了style样式", style)
  graphic.setStyle(toRaw(style))
}
</script>
<style lang="less" scoped>
.top-handle-bar {
  border-bottom: 1px solid #cde1de;
  padding: 5px 0 2px 0;
  :deep(.mars-icon) {
    cursor: pointer;
  }
}
.attr-editor-main {
  height: calc(100% - 40px);
  overflow-y: auto;
  :deep(*) {
    font-size: 12px;
  }
}
:deep(.ant-tabs-nav) {
  margin: 0;
}
:deep(.ant-select),
:deep(.ant-input-number) {
  width: 100%;
}
</style>