suerprisePlus
2024-05-30 7452857e6eb0d23dbd71a29f25985ada5208f25d
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
import mapData from './mapData';
 
const mapLayer = {
  layerList: [],
  locationEntity: null,
  setLayerChange(res) {
    if (!res) return;
    if (res.checked) {
      this.setAddGeoJsonData(res);
    } else {
      this.setRemoveGeoJsonData(res);
    }
  },
  getlocationEntity(item) {
    if (!item) return;
    if (this.locationEntity) {
      this.setRemovelocationEntity();
    }
    const source = Viewer.dataSources._dataSources;
    var sources_data = source.filter(res => {
      if (res._name == item.attributes.XL) {
        return res;
      }
    });
    if (sources_data.length <= 0) return;
    const entities = sources_data[0].entities.values;
    for (var i in entities) {
      if (entities[i].properties.FID._value == item.attributes.FID) {
        if (item.attributes.MC) {
          entities[i].label.text._value = item.attributes.MC;
        } else if (item.attributes.SWLYMC) {
          entities[i].label.text._value = item.attributes.SWLYMC;
        } else if (item.attributes.XMMC) {
          entities[i].label.text._value = item.attributes.XMMC;
        } else if (item.attributes.TDQLR) {
          entities[i].label.text._value = item.attributes.TDQLR;
        }
        this.locationEntity = entities[i];
        if (this.locationEntity) {
          this.setTimeIconChange(this.locationEntity);
        }
      }
    }
  },
  setTimeIconChange(res) {
    const start = Cesium.JulianDate.fromDate(new Date());
    const stop = Cesium.JulianDate.addSeconds(start, 10, new Cesium.JulianDate());
    Viewer.clock.startTime = start.clone();
    Viewer.clock.stopTime = stop.clone();
    Viewer.clock.multiplier = 1;
    Viewer.clock.clockRange = Cesium.ClockRange.CLAMPED;
    const that = this;
    Viewer.clock.onTick.addEventListener(adjustRate);
    Viewer.clock.shouldAnimate = true;
    function adjustRate(clock) {
      //可以在这里做一些时间的监听
      if (that.locationEntity.billboard.scale) {
        if (that.locationEntity.billboard.scale < 1.5) {
          that.locationEntity.billboard.scale = that.locationEntity.billboard.scale + 0.02;
        } else {
          Viewer.clock.shouldAnimate = false;
          Viewer.clock.canAnimate = false;
          Viewer.clock.currentTime = Viewer.clock.startTime;
          Viewer.clock.onTick.removeEventListener(adjustRate);
        }
      } else {
        that.locationEntity.billboard.scale = 1;
      }
    }
  },
  setRemovelocationEntity() {
    if (this.locationEntity) {
      this.locationEntity.billboard.scale = 1;
      this.locationEntity.label.text._value = '';
      this.locationEntity = null;
    }
  },
  setAddGeoJsonData(res) {
    const obj = this.getFeatureEntity(res);
    var geoJson = this.getGeoJsonData(obj);
 
    if (geoJson.features.length <= 0) return;
    Cesium.GeoJsonDataSource.load(geoJson).then(dataSource => {
      dataSource.name = res.name;
      Viewer.dataSources.add(dataSource);
      const entities = dataSource.entities.values;
      for (var i = 0; i < entities.length; i++) {
        const entity = entities[i];
        entity.billboard = {
          image: res.icon,
          width: 32,
          height: 32,
          pixelOffset: new Cesium.Cartesian3(0, 0, -10),
          borderWidth: 20,
          borderColor: Cesium.Color.fromCssColorString(' rgba(22, 119, 255, 1)'),
          clampToGround: true,
          distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0.0, config.distance),
          disableDepthTestDistance: Number.POSITIVE_INFINITY
 
        };
        entity.label = {
          text: '',
          font: "15px 'Microsoft Yahei'",
          fillColor: Cesium.Color.fromCssColorString(' rgba(22, 119, 255, 1)'), // 文本填充颜色  rgba(22, 119, 255, 1)
          pixelOffset: new Cesium.Cartesian3(0, -45, 0),
          // fillColor: Cesium.Color.BLIUE,
          showBackground: true, //显示背景
          backgroundColor: Cesium.Color.fromCssColorString('rgba(255, 255, 255, 8)'), //背景色
          backgroundPadding: new Cesium.Cartesian2(5, 6), //padding值
          outlineColor: Cesium.Color.fromCssColorString('rgba(169, 169, 169, 1)'), // 文本轮廓颜色169, 169, 169
          distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0.0, config.distance)
        };
      }
    });
  },
  setRemoveGeoJsonData(res) {
    var source = Viewer.dataSources._dataSources;
    Viewer.dataSources.remove(Viewer.dataSources.getByName(res.name)[0]);
  },
  getGeoJsonData(res) {
    return {
      type: 'FeatureCollection',
      totalFeatures: 0,
      features: res
    };
  },
  getFeatureEntity(res) {
    var std = [];
    mapData.searchData.filter(item => {
      if (item.attributes.XL === res.name) {
        const coord = item.geometry.coordinates;
        std.push({
          properties: item.attributes,
          type: 'Feature',
          geometry: {
            type: 'Point',
            coordinates: [coord[0], coord[1]]
          }
        });
      }
 
      // if (item.pid == res.id) {
      //   return item;
      // }
    });
    return std;
  },
  setLayerRemoveAll() {
    Viewer.dataSources.removeAll();
  }
};
export default mapLayer;