jihongshun
15 小时以前 307db148645230afc780a3d5d16ffb97aa32c189
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
<template>
  <div class="cesiumCard">
    <el-input v-show="false" id="AttributePoi" v-model="camPosition"></el-input>
    <CesiumMap></CesiumMap>
    <!-- <div v-if="showSearch && showCard" class="searchPointCard">
      <el-form label-width="auto" :model="form">
        <el-form-item label="经度:">
          <el-input v-model="form.lon" @blur="handleBlur('lon')" @focus="handleFocus('lon')"></el-input>
        </el-form-item>
        <el-form-item label="纬度:">
          <el-input v-model="form.lat" @blur="handleBlur('lat')" @focus="handleFocus('lat')"></el-input>
        </el-form-item>
        <el-form-item label="高度:">
          <el-input v-model="form.altitude"></el-input>
        </el-form-item>
        <el-form-item label="">
          <el-button type="primary" @click="search">搜索</el-button>
        </el-form-item>
      </el-form>
    </div> -->
  </div>
</template>
 
<script>
import CesiumMap from "../../utils/components/cesium-map";
import "../../js/CesiumDraw"
export default {
  name: '',
  components: {
    CesiumMap
  },
  props: {
    showSearch: {
      type: Boolean,
      defaule: false
    }
  },
  data() {
    return {
      // 地图拾点坐标
      camPosition: "",
      form: {
        longitude: '',
        latitude: '',
        altitude: '',
        lon: '',
        lat: '',
      },
      showCard: false
    }
  },
  mounted() {
    this.showCard = false
    this.handlePickMapPoint()
  },
  beforeDestroy() {
    CesiumDraw.clearDrawHandler();
  },
  methods: {
    clearMap () {
      this.showCard = false
      this.form.longitude = ''
      this.form.latitude = ''
      this.form.altitude = ''
      this.form.lon = ''
      this.form.lat = ''
      viewer.entities.removeById("drawPointEntity")
    },
    handlePickMapPoint() {
      let options = {
        viewer: viewer,
        pointcolor: Cesium.Color.BLUE,
        printId: 'AttributePoi',
        text: '新',
        size: 36,
      };
      //开启监听拾取地图点位
      viewer = window.viewer
      CesiumDraw.drawPoint(options, () => {
        this.camPosition = document.getElementById('AttributePoi').value;
        let pois = this.camPosition.split(",");
        let data = {
          longitude: pois[0],
          latitude: pois[1],
          altitude: pois[2],
        }
        this.form.longitude = pois[0]
        this.form.latitude = pois[1]
        this.form.altitude = pois[2]
        this.form.lon = new Array(String(pois[0]).length).fill('*').join('')
        this.form.lat = new Array(String(pois[1]).length).fill('*').join('')
        this.$emit('on-selectAddress', data)
        this.showCard = true
      });
    },
    showPickPoint(point) {
      this.showCard = false
      this.form.longitude = point.longitude
      this.form.latitude = point.latitude
      this.form.altitude = point.altitude
      this.form.lon = new Array(String(point.longitude).length).fill('*').join('')
      this.form.lat = new Array(String(point.latitude).length).fill('*').join('')
      this.drawPoint(Cesium.Cartesian3.fromDegrees(point.longitude,point.latitude,point.altitude))
    },
    drawPoint(point) {
      var drawPointEntity = viewer.entities.getById("drawPointEntity");
      if (drawPointEntity) {
        drawPointEntity.position = point.clone();
        return
      }
      const entity = viewer.entities.add({
        id: 'drawPointEntity',
        position: point.clone(),
        billboard: {
          image: new Cesium.PinBuilder().fromText('新', Cesium.Color.BLUE, 36).toDataURL(),
          verticalOrigin: Cesium.VerticalOrigin.BOTTOM
        },
        ellipsoid: {
          radii: new Cesium.Cartesian3(0.33, 0.65, 0.5),
          material: Cesium.Color.BLUE.withAlpha(0.7)
        }
      });
      viewer.flyTo(entity,{
        offset: new Cesium.HeadingPitchRange(0.0, -90.0, 200000)
      })
    },
    search() {
      this.drawPoint(Cesium.Cartesian3.fromDegrees(+this.form.longitude,+this.form.latitude,+this.form.altitude))
      this.$emit('on-selectAddress', this.form)
    },
    handleBlur(key) {
      if (key == 'lon') {
        this.form.longitude = this.form.lon
      } else {
        this.form.latitude = this.form.lat
      }
      let arr = new Array(this.form[key].length).fill('*')
      this.form[key] = arr.join('')
    },
    handleFocus(key) {
      this.form[key] = ''
      viewer.entities.removeById("drawPointEntity")
    }
  },
}
</script>
 
<style scoped>
.cesiumCard{
  position:relative;
}
.cesiumCard >>> .el-form-item__label {
  color:black;
}
.searchPointCard{
  position: absolute;
  left: 0;
  top:0;
  width: 300px;
  height: 260px;
  background-color: rgba(255,255,255,0.2);
  padding: 12px 24px;
}
</style>