拖旺项目:聊城公交辅助决策系统
master
2022-04-27 493930a42a2ea3e13905ffd8772cdb945baa7bcf
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
import * as maptalks from 'maptalks';
import store from '../store';
import img_zhandian_m_url from '../assets/map/icon_zhandian_m.png';
import img_zhandian_mm_url from '../assets/map/icon_zhandian_mm.png';
import img_cheliang_m_url from '../assets/map/icon_cheliang_m.png';
import img_cheliang_mm_url from '../assets/map/icon_cheliang_mm.png';
import img_bg_s_url from '../assets/map/bg_s.png';
import img_bg_m_url from '../assets/map/bg_m.png';
import { message } from 'ant-design-vue';
export default class customTool extends maptalks.MapTool {
  onEnable() {
    let layer = window.map.getLayer("CustomTool_layer");
    if(!layer){
      this._markerLayer = new maptalks.VectorLayer('CustomTool_layer').addTo(this.getMap());
    }
 
  }
 
  onDisable() {
    if (this._markerLayer) {
      this._markerLayer.remove();
    }
  }
 
  getEvents() {
    return {
      'click': this._onClick,
      'contextmenu': this._onRightClick
    };
  }
 
  _onClick(param) {
    let layer = window.map.getLayer("CustomTool_layer");
    if(store.state.mapMenu === "站点") {
      window.map.on('click', function (e) {
        layer.forEach(function (g) {
          g.updateSymbol([{'markerFile': img_zhandian_m_url},{'markerFile': img_bg_s_url}]);
        });
        window.map.identify({
            'coordinate' : e.coordinate,
            'layers' : [layer]
          },
          function (geos) {
            if (geos.length === 0) {
              return;
            } else {
              store.commit("SET_SelAttr", {visa:true,type: "zhandian",value:geos[0].properties.name})
              geos[0].updateSymbol([{'markerFile': img_zhandian_mm_url},{'markerFile': img_bg_m_url}]);
              // loadtempLayer(geos[0].properties)
              // window.map.animateTo({
              //     zoom : 14,
              //     center : geos[0]._coordinates.add(0.015, 0.000)
              // }, {
              //     duration : 500,
              //     easing : 'out'
              // })
            }
          }
        );
      });
    } else if (store.state.mapMenu === "车辆") {
      window.map.on('click', function (e) {
        layer.forEach(function (g) {
          g.updateSymbol([{'markerFile': img_cheliang_m_url},{'markerFile': img_bg_s_url}]);
        });
        window.map.identify({
            'coordinate' : e.coordinate,
            'layers' : [layer]
          },
          function (geos) {
            if (geos.length === 0) {
              return;
            } else {
              store.commit("SET_SelAttr", {visa:true,type: "cheliang",value:geos[0].properties.name})
              geos[0].updateSymbol([{'markerFile': img_cheliang_mm_url},{'markerFile': img_bg_m_url}]);
              // loadtempLayer(geos[0].properties)
              // window.map.animateTo({
              //     zoom : 14,
              //     center : geos[0]._coordinates.add(0.015, 0.000)
              // }, {
              //     duration : 500,
              //     easing : 'out'
              // })
            }
          }
        );
      });
    }
 
  }
 
  _onRightClick(param) {
    map.identify({
      coordinate: param.coordinate,
      layers: [this._markerLayer]
    }, geos => {
        this._markerLayer.removeGeometry(geos)
        let array = this._markerLayer._geoList
        let pathDataArr =array.map(item=>item.properties.id)
        if(store.state.mapMenu === "车辆"){
          if(array.length > 50){
            message.warning('选择车辆不能大于50!')
          } else {
            store.commit("SET_SelAttr", {visa:true,type: "cheliangcircle",value:pathDataArr.toString()})
          }
        } else if (store.state.mapMenu === "站点") {
          if(array.length > 50){
            message.warning('选择站点不能大于50!')
          } else {
            store.commit("SET_SelAttr", {visa:true,type: "zhandiancircle",value:pathDataArr.toString()})
          }
        }
    });
  }
  setMarkersLayer(markers){
    this._markerLayer.addGeometry(markers);
  }
}