Blame view

src/components/VMap.vue 5.07 KB
1e4db980   liuqimichale   轮廓
1
  <template>
f1105655   liuqimichale   map
2
      <div class="map-wrap" id="map"></div>
1e4db980   liuqimichale   轮廓
3
4
5
  </template>
  
  <script>
f1105655   liuqimichale   map
6
7
8
9
  import busyCar from '../images/content/busy-status.png'; //以import的方式导入图片文件
  import normalCar from '../images/content/normal-status.png'; //以import的方式导入图片文件
  import idleCar from '../images/content/idle-status.png'; //以import的方式导入图片文件
  
1e4db980   liuqimichale   轮廓
10
  export default {
f1105655   liuqimichale   map
11
    name: 'VMap',
633692cc   liuqimichale   axios
12
13
14
15
    props:['mapdata'],
    data(){
      return{
        map:'',
7d8d3bd4   liuqimichale   收入单位处理
16
        mapdataarr:[]
633692cc   liuqimichale   axios
17
18
      }
    },
f1105655   liuqimichale   map
19
    mounted(){
7d8d3bd4   liuqimichale   收入单位处理
20
      this.map = new BMap.Map('map', {enableMapClick: false})
83ffa354   liuqimichale   地图 数据
21
22
23
24
25
26
27
28
  
    },
    watch:{
      // mapdata:function (newVal) {
      //   console.log(newVal)
      // }
      mapdata: function () {
        this.$nextTick(()=>{
7d8d3bd4   liuqimichale   收入单位处理
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
          this.mapdataarr = this.mapdata
          let mapData = this.mapdataarr
          // let map = this.map
          console.log(this.mapdata)
          // let data =  [
          //     {Name:'万达停车场1',lonId:'111.742579',latId:'40.818675',status:0,freeBrethNum:0,plBerthNum:1000,plName:'万达广场停车场1',plAddress:'北京万达广场1'},
          //     {Name:'万达停车场2',lonId:'111.622579',latId:'40.878675',status:1,freeBrethNum:100,plBerthNum:800,plName:'万达广场停车场2',plAddress:'北京万达广场2'},
          //     {Name:'万达停车场333333',lonId:'111.782579',latId:'40.778675',status:2,freeBrethNum:300,plBerthNum:500,plName:'万达广场停车场3',plAddress:'北京万达广场3'}
          //   ];
          // let data = this.data
          console.log(mapData[0].lonId)
          console.log(mapData[0].latId)
          var point = new BMap.Point(mapData[0].lonId, mapData[0].latId)
          this.map.centerAndZoom(point, 22)
          var mapStyle={  style : "midnight" }
          this.map.enableScrollWheelZoom(false);
          this.map.setMapStyle(mapStyle);
          // var marker = new BMap.Marker(point)  // 创建标注
          // map.addOverlay(marker)              // 将标注添加到地图中
  
83ffa354   liuqimichale   地图 数据
49
50
          this.drawMap()
        })
7d8d3bd4   liuqimichale   收入单位处理
51
      },
f1105655   liuqimichale   map
52
53
    },
    methods:{
633692cc   liuqimichale   axios
54
55
56
      initMap(){
  
      },
f1105655   liuqimichale   map
57
      drawMap(){
f1105655   liuqimichale   map
58
  
7d8d3bd4   liuqimichale   收入单位处理
59
60
61
  
  
        this.map.clearOverlays();
f1105655   liuqimichale   map
62
63
        var i = 0;
        var points = [];
7d8d3bd4   liuqimichale   收入单位处理
64
65
        let mapData = this.mapdata
        var that = this
633692cc   liuqimichale   axios
66
        for (var item in mapData) {
f1105655   liuqimichale   map
67
68
69
          (function (x) {
            var itemthat = item;
            //创建标注
633692cc   liuqimichale   axios
70
            var pt = new BMap.Point(mapData[item].lonId, mapData[item].latId);
f1105655   liuqimichale   map
71
            points[i] = pt;
e73a397f   liuqimichale   进出场
72
            if(mapData[item].freeBrethNum/mapData[item].plBerthNum == 0|mapData[item].freeBrethNum==0){
5b095e2d   liuqimichale   地图
73
              var myIcon = new BMap.Icon(idleCar,
f1105655   liuqimichale   map
74
75
76
77
78
                new BMap.Size(29, 40), {
                  offset: new BMap.Size(10, 40),
                  textColor: '#fff'
                });
              var marker = new BMap.Marker(pt,{icon:myIcon});
633692cc   liuqimichale   axios
79
            } else if(mapData[item].freeBrethNum/mapData[item].plBerthNum <= 0.3){
f1105655   liuqimichale   map
80
81
82
83
84
85
86
              var myIcon = new BMap.Icon(normalCar,
                new BMap.Size(29, 40), {
                  offset: new BMap.Size(10, 40),
                  textColor: '#fff'
                });
              var marker = new BMap.Marker(pt,{icon:myIcon});
            } else {
5b095e2d   liuqimichale   地图
87
              var myIcon = new BMap.Icon(busyCar,
f1105655   liuqimichale   map
88
89
90
91
92
93
                new BMap.Size(29, 40), {
                  offset: new BMap.Size(10, 40),
                  textColor: '#fff'
                });
              var marker = new BMap.Marker(pt,{icon:myIcon});
            }
e73a397f   liuqimichale   进出场
94
95
96
97
98
            // var myIcon = new BMap.Icon(busyCar,
            //   new BMap.Size(29, 40), {
            //     offset: new BMap.Size(10, 40),
            //     textColor: '#fff'
            //   });
f1105655   liuqimichale   map
99
100
  
            marker.setTop(true,27000000);
7d8d3bd4   liuqimichale   收入单位处理
101
            that.map.addOverlay(marker);
f1105655   liuqimichale   map
102
            var myLabel;
7d8d3bd4   liuqimichale   收入单位处理
103
            that.map.removeOverlay(myLabel);
f1105655   liuqimichale   map
104
  
5b095e2d   liuqimichale   地图
105
106
107
            // map.removeOverlay(myLabel);
            myLabel = new BMap.Label(
              `<div class="dialog-wrap">
633692cc   liuqimichale   axios
108
109
                    <div class="dialog-header" title="${mapData[item].plAddress}">${mapData[item].plName}</div>
                    <div class="dialog-address" title="${mapData[item].plAddress}">${mapData[item].plAddress}</div>
5b095e2d   liuqimichale   地图
110
                    <ul class="dislog-body">
633692cc   liuqimichale   axios
111
                      <li><div>${mapData[item].freeBrethNum}</div><div>空闲</div></li>
5b095e2d   liuqimichale   地图
112
                      <li></li>
633692cc   liuqimichale   axios
113
                      <li><div>${mapData[item].plBerthNum}</div><div>总数</div></li>
5b095e2d   liuqimichale   地图
114
                    </ul>
83ffa354   liuqimichale   地图 数据
115
116
                    <div class="dislog-footer">停车场收入:${mapData[item].income}元</div>
                    <div class="dislog-footer">停车场欠费:${mapData[item].arreageincome}元</div>
5b095e2d   liuqimichale   地图
117
118
119
120
121
122
123
124
125
126
127
128
129
                  </div>`,
              {
                offset: new BMap.Size(-225, -55),   //label的偏移量,为了让label的中心显示在点上
                position: pt
              });
            myLabel.setStyle({
                // color: "#0f0",
                // fontSize: "12px",
                padding: "0",
                // whiteSpace: "normal",
                backgroundColor: "",
                border: "0px",
                zIndex: "1000"
f1105655   liuqimichale   map
130
              }
5b095e2d   liuqimichale   地图
131
132
133
            );
            marker.setLabel(myLabel)
            marker.setTop(true,27000000);
f1105655   liuqimichale   map
134
135
136
137
138
139
140
141
            i++;
          })(i);
        }
  
      }
  
    }
  
1e4db980   liuqimichale   轮廓
142
143
144
145
  }
  </script>
  
  <style scoped lang="scss">
f1105655   liuqimichale   map
146
147
148
149
      .map-wrap{
          width: 100%;
          height: 100%;
      }
5b095e2d   liuqimichale   地图
150
151
  
  
1e4db980   liuqimichale   轮廓
152
  </style>