管道基础大数据平台系统开发-【前端】-新系統界面
Surpriseplus
2023-02-14 965b4ade196fc23c3138320edb7c1e0653c9964c
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
<template>
  <!--总界面-->
  <div class="myDiv">
    <!--Cesium显示界面-->
    <div
      v-show="isSdkMapFlag"
      id="mapView"
      class="sdkMap"
      :class="[isShowCeMap ? 'sdkMapTwo' : 'sdkMapOne']"
    >
      <mapsdk></mapsdk>
    </div>
    <div
      id="ds"
      v-show="isShowDs"
    ></div>
    <!--openLayers显示界面-->
    <div
      v-show="isOlMapFlag"
      id="map"
      class="olMap"
      :class="[isShowOlMap ? 'olMapTwo' : 'olMapOne']"
    >
      <mapol></mapol>
    </div>
  </div>
</template>
 
<script>
import mapsdk from './mapsdk';
import mapol from './mapol';
import { transform } from 'ol/proj';
import ol from 'ol';
import $ from 'jquery';
export default {
  name: '',
  components: {
    mapsdk,
    mapol,
  },
  data() {
    return {
      isShowCeMap: false, //3维宽度
      isShowOlMap: false, //2维宽度
      isShowDs: false, //ds
      isOlMapFlag: false, //2维显隐
      isSdkMapFlag: true, //3维显隐
      isSplitFlag: 0,
      levelArray: [
        0, 40000000, 20000000, 10000000, 5000000, 2000000, 1000000, 500000,
        250000, 200000, 100000, 50000, 17000, 9000, 5000, 2000, 1000, 500, 200,
        100, 50, 25, 10, 0,
      ],
    };
  },
  methods: {
    changeMap(res) {
      this.isSplitFlag = res;
      switch (res) {
        case 1:
          this.isShowCeMap = true;
          this.isShowDs = true;
          this.isOlMapFlag = true;
          this.isShowOlMap = true;
          this.isSdkMapFlag = true;
          var that = this;
 
          setTimeout(function () {
            window.map.updateSize();
            that.showSplitMap();
          }, 500);
 
          break;
        case 2:
          this.isSdkMapFlag = false;
          this.isShowDs = false;
          this.isShowOlMap = false;
          this.isOlMapFlag = true;
          setTimeout(function () {
            window.map.updateSize();
          }, 300);
          break;
        case 3:
          this.isSdkMapFlag = true;
          this.isShowDs = false;
          this.isShowOlMap = false;
          this.isOlMapFlag = false;
          this.isShowCeMap = false;
          break;
      }
    },
    showSplitMap() {
      var that = this;
      $('#mapView')
        .off()
        .on('mousemove', function () {
          if (that.isSplitFlag == 1) {
            window.Viewer.camera.changed.addEventListener(that.sdktool());
          }
        })
        .on('mouseout', function () {
          if (that.isSplitFlag == 1) {
            window.Viewer.camera.changed.removeEventListener(that.sdktool());
          }
        });
      let mapZoomAndMove = function (event) {
        var position = window.map.getView().getCenter();
 
        // var pos = transform(position, 'EPSG:3857', 'EPSG:4326');
        var pos = position;
        var level = that.getHeight(parseInt(window.map.getView().getZoom()));
        window.Viewer.camera.setView({
          destination: Cesium.Cartesian3.fromDegrees(pos[0], pos[1], level),
        });
      };
      $('#map')
        .off()
        .on('mousemove', function () {
          if (that.isSplitFlag == 1) {
            that.olzoomAndMove(mapZoomAndMove);
          }
        })
        .on('mouseout', function () {
          if (that.isSplitFlag == 1) {
            that.clearolzoomAndMove();
          }
        });
    },
    clearolzoomAndMove() {
      let registerOnZoomArr = window.map.get('registerOnZoom');
      if (registerOnZoomArr && registerOnZoomArr.length > 0) {
        for (let i = 0; i < registerOnZoomArr.length; i++) {
          window.map.un('moveend', registerOnZoomArr[i]);
        }
      }
    },
    olzoomAndMove(eventListen, notListenMove) {
      // 记录地图缩放,用于判断拖动
      window.map.lastZoom =
        window.map.lastZoom || window.map.getView().getZoom();
      // 地图缩放事件
      let registerOnZoom = function (e) {
        // 不监听地图拖动事件
        if (notListenMove) {
          if (window.map.lastZoom != window.map.getView().getZoom()) {
            eventListen && eventListen(e);
          }
        } else {
          eventListen && eventListen(e);
        }
        window.map.lastZoom = window.map.getView().getZoom();
      };
      // 保存缩放和拖动事件对象,用于后期移除
      let registerOnZoomArr = map.get('registerOnZoom') || [];
 
      registerOnZoomArr.push(registerOnZoom);
 
      // 使用地图 set 方法保存事件对象
      window.map.set('registerOnZoom', registerOnZoomArr);
 
      // 监听地图移动结束事件
      window.map.on('moveend', registerOnZoom);
 
      return eventListen;
    },
    sdktool() {
      if (this.isSplitFlag != 1) return;
      var position = window.Viewer.camera.position;
      var ellipsoid = window.Viewer.scene.globe.ellipsoid;
      var cartographic = ellipsoid.cartesianToCartographic(position);
      var lat = Cesium.Math.toDegrees(cartographic.latitude);
      var lng = Cesium.Math.toDegrees(cartographic.longitude);
      var level = this.getLevel(cartographic.height);
      var value
      // window.map
      //   .getView()
      //   .setCenter(transform([lng, lat], 'EPSG:4326', 'EPSG:3857'));
      window.map
        .getView()
        .setCenter([lng, lat]);
      window.map.getView().setZoom(level);
    },
    getLevel(height) {
      for (var i = 1, len = this.levelArray.length; i < len - 1; i++) {
        if (height >= (this.levelArray[i] + this.levelArray[i + 1]) / 2) {
          return i;
        }
      }
      return this.levelArray.length - 1;
    },
    getHeight(level) {
      if (level > 0 && level < 23) {
        return this.levelArray[level];
      }
      return this.levelArray[this.levelArray.length - 1];
    },
  },
  mounted() {
    this.$bus.$on('changemap', (e) => {
      this.changeMap(e);
    });
  },
};
</script>
 
<style scoped>
.myDiv {
  width: 100%;
  height: 100%;
  padding: 0;
  margin: 0;
  position: absolute;
  float: left;
}
.sdkMap {
  height: 100%;
  padding: 0;
  margin: 0;
  float: left;
}
.sdkMapOne {
  width: 100%;
}
.sdkMapTwo {
  width: calc(50% - 1px);
}
.olMap {
  height: 100%;
  padding: 0;
  margin: 0;
  float: right;
}
.olMapOne {
  width: 100%;
}
.olMapTwo {
  width: calc(50% - 1px);
}
#ds {
  height: 100%;
  width: 2px;
  background: #d6d6d6;
  float: left;
}
</style>